[IronPython] assembly context binding in appDomain and .NET interop
tristan1132 at gmail.com
Thu Sep 16 01:09:28 CEST 2010
New to the list & hoping an IronPython expert might be able to shed some
light on an vexing IronPython runtime problem I'm having.
I've actually posted this question in StackOverflow to no avail here:
is a lot more details about this problem there.
essentially what I'm having problems with I think boils down to an assembly
binding context mismatch. However, I have totally run out of ideas on how to
resolve the problem.
I have a C# assembly I reference in IronPython. I new up an object defined
in that assembly in IronPython:
return Entity.TestPy(); // the C# class
So now over in C#, I call this and assign it to a dynamic var:
// C# code calling IronPython and getting back an object
dynamic test = scriptEngine.GetTest();
Entity.TestPy t = test as Entity.TestPy; // t==null!!!
the cast fails. However, if I do this with a BCL type (say System.Uri as an
example), this cast succeeds. It only fails for types in my own assembly.
It has been suggested to me that the reason for this type mismatch is that
the runtime takes in the totality of the runtime environment when
considering if types match. It appears that the IronPython runtime AppDomain
gets a different Assembly Load Context than the C# (
http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx) and thus even
though the Entity.TestPy type in C# and IP are the same, because the context
is different, the types do not line up and therefore the cast fails.
I don't want a dynamic type--I want the static type, but I can't figure out
how to get the CLR to be happy about this.
While I'm strongly suspicious that the Assembly Load Context is what is the
problem--I don't know that for sure. I'm guessing an IronPython guru can
help sort this out.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users