1

IronPython.net documentation says the MSIL in the assembly isn't CLS-compliant, but is there a workaround?

2 Answers 2

1

This was partly a motivation for adding the dynamic type to C# 4.0. The biggest problem is that IronPython declarations doesn't include type information, which makes it difficult to use it from C#. The dynamic keyword adds support for such dynamically typed objects to C# 4.0. See for example:

Calling functions/objects from C# 3.0 is a bit more annoying, but it is still possible. You'll just have to write something like foo.Invoke("Bar", 42) instead of just writing foo.Bar(42).

Sign up to request clarification or add additional context in comments.

Comments

0

I'm typing this on my phone so please forgive any silly mistakes. To use the compiled assembly, make sure you compile with clr.CompileModules, NOT pyc.py. Then in your C# call the LoadAssembly method on your Python ScriptEngine object. The module can then be imported by calling the ImportModule method on your ScriptEngine. From there if you can take advantage of the dynamic keyword, do so. Otherwise you'll be stuck with some magic string heavy calls to GetVariable. Also note that you'll have to provide the standard library to your compiled Python Assembly in one form or another.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.