This is an offshoot question that\'s related to another I asked here. I\'m splitting it off because it\'s really a sub-question:
I\'m having difficulties casting an obje
I bet that IronPython loads your entity.dll
into a different assembly load context, so that you have two copies of it loaded and the types in them are of course different. You might be able to work around this issue by hooking AppDomain.AssemblyReslove
/AppDomain.AssemblyLoad
and returning your local assembly (typeof (Entity.TestPy).Assembly
) when IronPython tries to load it, but I don't guarantee that this will work.
You don't experience this with System.Uri
because mscorlib.dll
(and maybe some other system assemblies) is treated specially by the runtime.
Update: IronPython FAQ states that if the assembly isn't already loaded clr.AddReferenceToFile
uses Assembly.LoadFile
, which loads into the 'Neither' context. Try accessing a method from Entity.TestPy
before calling IronPython to load the assembly into the default Load
context.
Here's an answer from the IronPython team which covers the same problem:
C# / IronPython Interop with shared C# Class Library
(Lifted from http://lists.ironpython.com/pipermail/users-ironpython.com/2010-September/013717.html )