Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Weird Asembly.LoadFrom() and custom attributes bug

The CLR runs into an error if all of the following conditions apply:

* There is a managed application app.exe together with a DLL fw.dll somewhere on the file system
* There are two managed DLLs a.dll and b.dll somewhere else
* In fw.dll there is a attribute class: MyAttribute
* MyAttribute has a property of type Type: ItfType
* a.dll contains an interface: IMyItf
* b.dll contains a class that implements IMyItf: CMyClass
* CMyClass has an attribute: [My(ItfType=typeof(IMyItf))]
* app.exe loads b.dll via Assembly.LoadFrom"<path>\\b.dll")
* app.exe retrieves custom attributes from type CMyClass via reflection: type.GetCustomAttributes()

The call to GetCustomAttributes() crashes, because the containing assembly of IMyItf cannot be found. However, if  I create a static property CMyClass.MyItfType that returns typeof(IMyItf), everything is fine.

A CLR fusion bug (can't resolve dependencies in the LoadFrom context correctly)?

Alex
Friday, January 30, 2004

*  Recent Topics

*  Fog Creek Home