Tuesday, June 17, 2008

Assembly.GetEntryAssembly()

I have to use a library designed for use with Winforms.
I have to use it in Asp.net though, so at one point I got to a method using unguarded Assembly.GetEntryAssembly() call that failed.

After a little research and found this in the MSDN:



The GetEntryAssembly method can return null reference (Nothing in Visual Basic) when a managed assembly has been loaded from an unmanaged application



and became evident that the reason for the problem was that the library was call from the unmanaged IIS process.

I searched for a generic solution, but finally only managed to find a hint here:http://www.developersdex.com/asp/message.asp?p=2912&r=5817390

so now I'll add this code to solve the problem

if (null != Assembly.GetEntryAssembly())

{

// proceed with Assembly.GetEntryAssembly()

}

Else

{

// read a setting from the config file and set the entry assembly to this value if not empty

System.Configuration.ConfigurationManager.AppSettings["EntryAssembly"]

}


and thats all for now ...

No comments :