C# 4.0: casting dynamic to static

前端 未结 2 2007
长发绾君心
长发绾君心 2021-02-05 20:23

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

相关标签:
2条回答
  • 2021-02-05 21:03

    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.

    0 讨论(0)
  • 2021-02-05 21:20

    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 )

    0 讨论(0)
提交回复
热议问题