I have been facing a silly bug related to AppDomain, so stupid that it is worth mentionned in a blog.
The symptoms
Load an assembly in a separate AppDomain, create an instance of a type. Things work correctly. Then unload the domain, and recreate the type. Somehow, strange bugs (Custom Attributes not detected, the debugger messed up) arise.
How-to recreate it:
Assume that we have the Assembly MbUnit.Core.dll, MbUnit.Framework.dll (that references Core) and Test.dll that references both. Core defines an abstract Custom Attribute TestPatternFixtureAttribute,
MbUnit.Core.dll
MbUnit.Framework.dll
Test.dll
public abstract TestFixturePatternAttribute :Attribute{...}
TestFixtureAttribute
public class TestFixtureAttribute : TestFixturePatternAttribute{...}
[TestFixture] public class MyTest{...}
RemoteTestTree
TestPatternFixtureAttribute
The fix
In point 2,5, I have been using AppDomain.CreateInstanceFromAndUnWrap, this is the error. I should have been using AppDomain.CreateInstanceAndUnWrap. The difference is subtle, 4 letters.
The explanation
I'm still unsure of the explanation.... so I'm waiting for someone to come up with a relevant explanation :)
Page rendered at Sunday, September 07, 2008 10:01:15 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.