IronPython Attachment - Unable to Add System Link

I am embedding IronPython in my C # application. For some reason, I'm having trouble loading assemblies. In particular, I want System.dll to have access to .NET classes such as DateTime.

If I try the line:

_runtime.LoadAssembly(_runtime.Host.PlatformAdaptationLayer.LoadAssembly("System")); 

I get:

 could not load file or assembly 'System' 

If I explicitly type the path to C: /WINDOWS/Microsoft.NET /.../ System.dll, I get:

 The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) 

So, I tried to import using clr inside a Python script:

 import clr clr.AddReference('System') from System import DateTime 

And now I get:

 Cannot import name DateTime 

Where am I mistaken? Why is DateTime not in System, and why LoadAssembly cannot find System.dll? Do I need to explain some search paths for IronPython? Does he find an invalid "System"?

All this works great when I test in the IronPython interpreter.

+3
source share
1 answer

I am using engine.Runtime.LoadAssembly(typeof(string).Assembly); to load the system assembly; I believe this is what the IronPython console does.

PS Do not forget that the source is available for IronPython ; it is a gold mine for such things.

+4
source

Source: https://habr.com/ru/post/1436826/


All Articles