C# dynamic compilation and “Microsoft.CSharp.dll” error

前端 未结 3 490
栀梦
栀梦 2021-01-18 13:18

I\'m doing the example that can be found here. So I\'m trying to run IronPython in a C# script:

Python:

def hello(name):
    print \"Hello \" + name          


        
相关标签:
3条回答
  • 2021-01-18 13:59

    Microsoft.CSharp.dll contains the dynamic portion of the C# compiler. Any time you use dynamic in your code, you need a reference to it. I'm not familiar with MonoDevelop, but you'll probably have to set the target framework to 4.0, and add a reference to Microsoft.CSharp.dll to the project (probably right-click on the project, 'Add Reference', find Microsoft.CSharp).

    My guess is that the project you're using was created with a pre-release version of VS, and is missing the proper references.

    0 讨论(0)
  • 2021-01-18 14:01

    Ok. Basically, my mistake was linked to the fact that I added my IronPython assemblies from the wrong platform. Verify that:

    • Target Framework: 4.0

    • Add all the assemblies provided by IronPython in [IronPython-2.7.3]->[Platforms]->[Net40].

    Thx to everyone who gave me advices.

    Ps:Now, of course, there is another problem… But it's not about that topic anymore.

    0 讨论(0)
  • 2021-01-18 14:05

    This is what helped me. I am using Xamarian Studio v5.8.1 (build 8) to write a C# program. I just had to right click "References" -> "Edit References" -> started typing "Microsoft" in the search bar -> Checked the box next to "Microsoft.CSharp" -> and clicked "OK".

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

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