I'm seeing a strange problem using System.Reflection calls where I get ReflectionTypeLoadException. I haven't been able to narrow this down to a simple test case, but I think I am seeing the same behavior from Lutz Roeder's .Net Reflector program. Below is the email I sent to Lutz. I'm posting it here in the hope that maybe someone out there has encountered this before and can explain what's going on.... Thanks in advance!
[email to Lutz Roeder:] Hello! I have been using the .Net Reflector a lot and it is a great tool! I have also been doing System.Reflection programming and I've run into a strange problem which I think I have reproduced in the Reflector. I'm wondering if you will have any insight into what's going on here behind the scenes. When I launch the Reflector I see nine assemblies open (mscorlib, System, System.Data, System.Design, System.Drawing, System.Web, System.Web.Services, System.Windows.Forms, System.Xml). I believe this is the standard set that shows up the first time the Reflector is run. Now I want to inspect System.ServiceProcess so I do File | Open... and navigate to C:\WINNT\Microsoft.NET\Framework\v1.0.3705 (where the .Net framework was installed). I select System.ServiceProcess and it shows up in the Reflector. Then I open that node and open the child node "system.serviceprocess.dll" to look at the namespaces and types. But what I see instead is an error indicator "One or more of the types in the assembly unable to load.". Here is the other interesting twist: System.ServiceProcess references a number of assemblies, all but one of which are among the nine I list above. The other one is System.Configuration.Install. If I open System.Configuration.Install first, System.ServiceProcess will sucessfully show it's types. I believe this scenario corresponds to something I am trying to do in my code and I'm probably running into the same problem. I'm getting a System.Reflection.ReflectionTypeLoadException with the same error message and a stack something like this: One or more of the types in the assembly unable to load.(in System.Type[] System.Reflection.Module.GetTypesInternal(System.Threading.StackCrawlMark& stackMark)) Exception Stack: Server stack trace: at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark) at System.Reflection.Assembly.GetTypes() at ... (my code) So my code is calling myAssembly.GetTypes() when the exception is thrown. The ReflectionTypeLoadException class has a property called LoaderExceptions which exposes an array of exceptions for the types that failed to load. Here's what I see when I dump that array: LOADER_EXCEPTIONS 0 : System.TypeLoadException: Method CopyFromComponent in type System.ServiceProcess.ServiceInstaller from assembly CopyFromComponent does not have an implementation. 1 : System.TypeLoadException: Method CopyFromComponent in type System.ServiceProcess.ServiceProcessInstaller from assembly CopyFromComponent does not have an implementation. Note that ServiceInstaller and ServiceProcessInstaller are concrete classes that derive from the abstract class System.Configuration.Install.ComponentInstaller (which appears to derive from a concrete class (can this be???) System.Configuration.Install.Installer) I'm very surprised that this doesn't work because System.Configuration.Install and System.ServiceProcess (and all the others) are in the GAC, so I would expect them to get resolved and loaded as needed without any special action on my part. But there could be a bug in the System.Reflection code or possibly the fact that System.Configuration.Install.ComponentInstaller is abstract is a bug. Do you have any clues about what's going on here? Thanks, Chris Daly Rational Software You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
