C # dynamic compilation and error "Microsoft.CSharp.dll"

I am doing an example that can be found here . So I am trying to run IronPython in a C # script:

Python:

def hello(name): print "Hello " + name + "! Welcome to IronPython!" return def add(x, y): print "%i + %i = %i" % (x, y, (x + y)) return def multiply(x, y): print "%i * %i = %i" % (x, y, (x * y)) return 

FROM#:

 using IronPython.Hosting; using IronPython.Runtime; using Microsoft.Scripting.Hosting; using System; namespace IntroIronPython { class IronPythonMain { static void Main(string[] args) { // Create a new ScriptRuntime for IronPython Console.WriteLine("Loading IronPython Runtime..."); ScriptRuntime python = Python.CreateRuntime(); try { // Attempt to load the python file Console.WriteLine("Loading Python File..."); // Create a Dynamic Type for our Python File dynamic pyfile = python.UseFile("PythonFunctions.py"); Console.WriteLine("Python File Loaded!"); Console.WriteLine("Running Python Commands...\n"); // Call the hello(name) function pyfile.hello("Urda"); … 

And from here I have this error: "Dynamic operation cannot be compiled without reference to the assembly" Microsoft.CSharp.dll "." And I seriously don’t understand what it is about, what did I forget to add?

In my recommendations, I have: References of my project

Thanks for your help.

Ps: I'm on MonoDevelop.

+6
c # .net-assembly dynamic ironpython
Jul 10 '12 at 15:45
source share
3 answers

Ok Basically, my mistake was due to the fact that I added my IronPython builds from the wrong platform. Make sure that:

  • Target structure: 4.0

  • Add all the assemblies provided by IronPython to [IronPython-2.7.3] → [Platforms] → [Net40].

Thanks to everyone who gave me advice.

Ps: Now, of course, there is another problem ... But this is not about this topic.

+4
Jul 10 2018-12-12T00:
source share
— -

It helped me. I am using Xamarian Studio v5.8.1 (build 8) to write a program in C #. I just needed to right-click “Links” → “Change Links” → started typing “Microsoft” in the search bar → I checked the box next to “Microsoft.CSharp” → and clicked “OK”.

I just saved and started the program after that - everything works as expected!

+11
Mar 30 '15 at 1:08
source share

Microsoft.CSharp.dll contains the dynamic part of the C # compiler. Every time you use dynamic in your code, you need a link to it. I am not familiar with MonoDevelop, but you probably have to set the target structure to 4.0 and add a link to Microsoft.CSharp.dll in the project (maybe right-click on the project, "Add Link"), find Microsoft. CSharp).

I assume that the project you are using was created with a preliminary version of VS and does not contain the correct links.

+2
Jul 10 2018-12-12T00:
source share



All Articles