COM Interop from ASP Automatically Using Latest .NET Version

If you have an application that calls a .NET DLL registered for COM interop using "RegAsm", that DLL will get executed using the NEWEST version of .NET on your computer. That's the information I got straight from the guys at Microsoft.

At work we have an ASP application that uses a .NET DLL registered for COM interop to talk to webservices in an ASP.NET application.  Everything was working fine until our customers started installing .NET 2.0. Or in some cases, they would install SQL Server 2005 which would install .NET 2.0. Our ASP application started to break, because the DLL was not designed to work on .NET 2.0. How would it have been?  It wasn't written when 2.0 was available.

Figuring out the problem ended up being the easy part (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconruntimeinitializationfromcomapplication.asp). The hard part was forcing it to use .NET 1.1.  Microsoft has no information about it, and Google searches proved to be futile. I ended up using one of my MSDN support incidents. They basically allow me to get straight to an expert on the subject, and Microsoft holds my hand until we get it figured out.

Once I got a hold of someone who knew what I was talking about, he told me that you COULD NOT tell it what version of .NET to use, because it was ultimately running under IIS. He did offer some workarounds:

  1. Live with it.  This was obviously unacceptable because it wasn't technically a solution.
  2. Write some kind of bizarre non-managed wrapper that could make a .NET 1.1 call and then use our DLL. He didn't really understand this one, but he had heard it from someone else.  I really don't even know how I would have done that, or what it even means really.
  3. Write a dummy ASPX page in the ASP directory that would get called on startup by the ASP application. In addition, the virtual directory for the ASP page would need to be set to use .NET 1.1. That basically forces the application to start .NET for the virtual directory, and any future .NET calls will use .NET 1.1. This was the method that we ended up choosing.

Once we added some logic to the startup of the ASP application to call the blank ASPX page, any future calls to COM registered .NET DLL's would be made with the .NET version of our choosing. It's strange, but it works.

No Comment

No comments yet

Leave a reply