My ASP.NET application utilises a "Modules" system by using Type.GetType()
on a fully-qualified string reference, and instantiating an object of that type, as you do.
However, recently it has been throwing exceptions at not being able to find the types - but only occasionally. I haven't been able to replicate at will, but it usually happens after a simple change to something non-bin-related like a Master Page or ASCX markup. It doesn't sort itself until I rebuild the site or restart IIS. Making a change to the web.config does not fix it.
Adding an explicit reference to the assembly in the web.config rather than making hoping it gets found sitting in the bin directory reduces the occurrence of the issue, but does not prevent it from happening entirely. Somehow, something somewhere is thinking it's a good idea to remove my assembly.
I've debugged into where it fails to find the type and right enough, despite being there on the previous page load, the assembly seems to disappear out of the Thread.GetDomain().GetAssemblies()
. Clearly, I can't risk this happening when the application is live so I manually called Assembly.LoadAssembly()
on the DLL I knew it needed just to see if it would be worth creating a method that would try to locate the assembly. This didn't work either, as it then threw the following error when I tried to use the class:
[A]xxx.Modules.CustomCaseStudy cannot be cast to [B]xxx.Modules.CustomCaseStudy. Type A originates from 'xxx.Modules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Development\xxx\xxx.Web\bin\xxx.Modules.dll'. Type B originates from 'xxx.Modules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\fff474e0\8c6aec7e\assembly\dl3\325b4335\009dbd67_b2fbc901\xxx.Modules.DLL'.
All the while, the required DLL is sitting in the bin folder, waiting - nay, begging to be used, not to mention the explicit reference in the web.config.
Any information in tracking down the culprit, or even as a last resort how to load that assembly into the "Default" context would be greatly appreciated!