Careers: Interviews
Expert in Interop Adam Nathan

This week, Stephen Ibaraki, ISP, has an exclusive interview with Adam Nathan. Adam is unquestionably the world’s foremost expert in .NET/COM Interop and the Common Language Runtime.

Q: Adam, you are at the top of the world’s elite in .NET and COM applications and interoperability issues. This is a rare opportunity for us. Thank you for agreeing to this interview and sharing your experiences, wisdom, and vast skills with our audience.
A: Thank you, but you’re too flattering! Soon there will probably be many Interop gurus around. Hopefully they’ll gain their knowledge from reading my book!

Q: What led you to take your honours B.S. in Computer Science at Cornell? Can you detail your history that eventually took you into computing?
A: Ever since fourth grade I would program in BASIC just for fun, but I never considered going into computer science until my freshman year of college. I enrolled in Cornell University’s College of Engineering because I always liked math and science, but didn’t have any specific plans for what field I wanted to go into. In the second half of my freshman year, I took an introductory computer science class that was mandatory for all engineers, and that class made me realize that computer science was the right field for me. It was just as fun as when I programmed as a hobby!

Q: You are a software design engineer on Microsoft’s .NET Common Language Runtime QA team and made numerous contributions to the design of Interop. You also filed more bugs than anyone else and due to the quality of your work, had the bulk of them resolved; equivalent to batting a 1000. What were the reasons and outcomes for taking on the role of an external software developer?
A: I came to Microsoft to experience what it’s like to be a part of first-rate software development, and the experience has been phenomenal. I had no idea about the magnitude of the project I was working on until shortly before the PDC [Professional Developers Conference] in 2000. Since then, it’s become clear that .NET is changing the face of software development, both inside and outside of Microsoft. As for the role of finding bugs in the product, I think it’s a lot of fun (and not that different from doing something like proofreading a book).

Q: You were a contributing author for the best-selling ASP.NET: Tips, Tutorial, and Code by SAMS. How did you get into writing and what lessons did you learn from that experience? Can you share some tips from the book?
A: Due to the tremendous interest in the .NET platform, there was (and still is) a tremendous demand for books. The opportunity to contribute to this ASP.NET book presented itself while I was in the midst of writing my Interop book. It was my first exposure to the complete editing cycle involved when publishing a book (since my Interop book was published about 6 months later), so that was an interesting learning experience.

One important tip from the book is to use the aspcompat=true page directive when invoking Visual Basic 6 COM components from an ASP.NET page. Among other things, this directive makes the page run on an STA thread rather than an MTA thread. Since VB6 COM components are apartment-threaded, using aspcompat=true can result in a huge performance improvement by avoiding cross-apartment COM marshaling.

Q: Your current book, “.NET and COM, The Complete Interoperability Guide” by SAMS is the finest book in this area available today and has received rave reviews for its completeness. I would second this assessment and highly recommend the book as the best available for .NET and COM developers. What made your write this book, especially during your first year of marriage, and while providing your invaluable and unique services to Microsoft? Who should read this book? What are the objectives of the book? Can you share some tips from the book?
A: Thanks. I saw a huge need for a complete resource for COM Interoperability and Platform Invocation Services (PInvoke). These can be complex technologies, and are especially important to understand as software developers evaluate what to do with large bodies of existing software. Interoperating with existing software is one of the first .NET topics a developer should master.

I had seen other .NET books dedicate a chapter or two to COM Interoperability and/or PInvoke. These chapters sometimes provide a nice introduction to the technologies, but real-world applications almost never behave as nicely as canonical examples. Instead, they often require techniques that just can't be covered in one or two chapters. So I felt compelled to share what I had learned. It was a grueling process, but I’m extremely lucky to have a supportive wife who suffered through the long nights and weekends when I did nothing but write.

Who should read the book? Anyone wanting to mix existing pre-.NET software (a primary example being Windows itself) with .NET applications or components. It demonstrates how to:
  • Leverage existing software (COM-based or not) in new .NET applications.
  • Plug new .NET components into an existing COM architecture, taking advantage of .NET's many features rather than continuing to program the COM way.
  • Design your software to work well in both .NET and COM-based surroundings.
  • Call any unmanaged APIs (such as Win32 functions) in any .NET language.
  • Interoperate with COM+ and DCOM objects, as well as ActiveX controls.
I don't expect the reader to know anything about .NET in advance, but the more background in .NET you have (and experience with one .NET language), the better off you'll be. Most of the book assumes familiarity with either "raw COM" or COM through Visual Basic 6, but its concepts are explained in enough detail that developers should still get a lot out of the book without in-depth prior knowledge. Even if you don't care about COM, you should still find its coverage of PInvoke valuable.

I could go on forever with tips from the book (since it has well over 150 tips embedded as sidebars), so to limit the scope, here are 10 quick tips for designing .NET class libraries that are easy to use by COM clients:

  • Avoid creating members with names that conflict with method names of IUnknown or IDispatch, such as Release or Invoke. Such members are exposed to COM with mangled names to avoid collision.
  • Provide alternatives to parameterized constructors, because they are not directly exposed to COM.
  • Don't create APIs that rely on static members, because they are not easily accessible from COM.
  • Don't create APIs that rely on methods or properties of value types, because they are not directly exposed to COM.
  • Don't create APIs that rely on nested arrays, because the Interop marshaler does not support them.
  • Think twice before using overloaded methods, because they are exposed to COM with unintuitive and version-brittle names (suffixed with _2, _3, and so on).
  • Don't forget the benefits of interface-based programming. When defining public classes, it often makes sense to define a corresponding interface for the class to implement, and to always use the interface type rather than the class type in any public method, property, field, or event definitions. Also mark the class with ClassInterfaceAttribute and its ClassInterfaceType.None value to make the implemented interface the default.
  • Throw exception types defined in the mscorlib assembly whenever appropriate, because user-defined exceptions don't get the same special treatment by the Interop marshaler.
  • If you define a method that returns null (Nothing in VB .NET) to indicate failure, provide the option for it to throw an exception on failure instead. Because COM clients see S_OK returned whenever an exception isn't thrown, not throwing an exception may mistakenly lead them to believe the call succeeded when it really did not.
  • Use ComSourceInterfacesAttribute on classes that expose events, so they expose connection points to COM event sinks.

Q: You have regularly provided technical assistance on .NET e-mail lists, served on the panel of .NET experts, provided technical assistance during hands-on labs, prepared demonstrations for the 2000 and 2001 Microsoft Professional Developers Conferences and no doubt will be heavily involved for 2002. Can you provide us with tips from this unbounded experience that you have and from other projects that you have worked on?
A: My only advice is to make use of online newsgroups. These groups, provided not just by Microsoft but many other companies as well, are great resources for getting just about any kind of question answered.

Q: Describe future book titles and articles can we expect from you?
A: I have no plans for writing any more books or articles, but I’m not ruling out the possibility of doing so in the future.

Q: What are the ten top traps or pitfalls that developers should be wary of and avoid?
A: Just one – Don’t believe everything you read in the press when it comes to technology! I can’t count the number of times I’ve read an article that was misleading or just flat out wrong about something .NET related, and I’m sure it happens all the time for other technologies, too. Do your homework and let facts guide your decisions about making technological decisions.

Q: Can you share your 10 leading career tips for those thinking of getting into the computing field?
A: I don’t have ten tips; just two:
1. Make sure that enjoying computing is your motivation for entering the field, as opposed to something like monetary gain.
2. Take the time to learn something new every once in awhile. Technology is constantly evolving, so you need to evolve with it.

Q: You have a reputation for being plugged into the stream of computing consciousness. What are the hottest topics that all IT professionals must know to be successful in the short term and long term?
A: Besides the .NET Framework and associated technologies, the only topic that comes to mind is security. I think most people see how crucial properly-secured systems are these days, and being knowledgeable enough to prevent security breaches is vital.

Q: What would be your recommended top five references for the serious developer?
A: I would recommend:
  • .NET and COM: The Complete Interoperability Guide (Sams)
  • .NET Framework Security (Addison Wesley)
  • Applied Microsoft .NET Framework Programming (Microsoft Press)
  • Hacking Exposed: Network Security Secrets & Solutions, Third Edition (McGraw-Hill)
  • Design Patterns (Addison Wesley)

Q: You have so many accomplishments. What do you do to relax?
A: Not enough! But watching TV with my wife and our cat (Shadow, who appears in the book in the example of using COM Interop with Windows Media Player) is probably my favorite way to relax.

Q: If you were doing this interview, what two questions would you ask of someone in your position and what would be your answers?
A: I think you’ve covered it all! I’d ask about the book and the motivation for writing it, just as you did.

Q: It’s a blank slate, what added comments would you like to give to enterprise corporations and organizations?
A: Only to take a serious look at .NET if you haven’t already. It’s beginning to revolutionize the way software is created, and things will only get better in future versions!

Q: Adam, thank you for sharing your valuable insights with us today and we look forward to reading your books, and articles.
A: My pleasure.


Suggestions for this page?
Email NPA Web Services: click here

NPA      facebook      LinkedIN logo
© Copyright Network Professional Association® 1994-2024 All Rights Reserved.
NPA Privacy Statement