This looks like a bug in System.Reflection to me.  The program below
raises a ReflectionTypeLoadException on a call to Assembly.GetTypes().
All of the assemblies involved are standard framework ones.  The
assembly causing the problem is System.ServiceProcess.

The tricky part is the dependencies between the assemblies.
System.ServiceProcess makes use of some stuff in
System.Configuration.Install.  If I load the latter assembly
first (see the commented out code below) everything works fine.
However I would expect the referenced assemblies to get loaded
automatically when needed (they are all in the GAC).

Can anyone tell me if this is a bug or feature?

Chris Daly
Rational Software


// test case follows...
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Collections;
using System.Runtime.InteropServices;

namespace ReflectionBug
{

 public class Driver
 {
  static void Main(string[] args)
  {
   string GACPath = @"C:\WINNT\Microsoft.NET\Framework\v1.0.3705\";

   Assembly temp;
   Assembly serviceProcess;
   Assembly sysConfigInstall;

   temp = Assembly.LoadFrom(GACPath + "System.dll");
   temp = Assembly.LoadFrom(GACPath + "System.Data.dll");

   // Note: Uncommenting the line below - which causes
System.Configuration.Install to
   //       load before System.ServiceProcess - makes the problem go away.
   //sysConfigInstall = Assembly.LoadFrom(GACPath
+ "System.Configuration.Install.dll");

   serviceProcess = Assembly.LoadFrom(GACPath +
"System.ServiceProcess.dll");
   temp = Assembly.LoadFrom(GACPath + "System.Xml.dll");

   try
   {
    serviceProcess.GetTypes();
   }
   catch (ReflectionTypeLoadException ex)
   {
    Console.WriteLine(ex + "\n");

    foreach (Exception ex2 in ex.LoaderExceptions)
    {
     Console.WriteLine(ex2 + "\n");
    }
   }
  }
 }
}

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to