Why can't I import my C# type into IronPython?

你。 提交于 2019-12-04 09:33:03

Could you be picking up the DLL from a different location then you're expecting? AddReferenceToFile will search sys.path and load the first file it finds which matches that filename. Depending on where you expect to find the DLL and where it may exist earlier on the path you could be getting a version which you've compiled earlier. You can also do:

dir(clr.LoadAssemblyFromFile('SprocGenerator.dll'))

to see what types exist in the DLL which you are actually getting back or:

clr.LoadAssemblyFromFile('test.dll').CodeBase

to see where the file is actually being loaded from.

Check your namespaces. The fact that it complains:

ImportError: No module named Generators

instead of:

ImportError: No module named SprocGenerator.Generators

tells us that it found the SprocGenerator namespace. Is there a misspelling either in C# or Python in the inner namespace, Generators?

Place the assembly in one of the locations specified in sys.path. On my machine:

['C:\Windows\system32', 'C:\Program Files (x86)\IronPython 2.6\Lib', 'C:\Program Files (x86)\IronPython 2.6\DLLs', 'C:\Program Files (x86)\IronPython 2.6', 'C:\Program Files (x86)\IronPython 2.6\lib\site-packages']

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!