C#动态编译和“Microsoft.CSharp.dll”错误 [英] C# dynamic compilation and "Microsoft.CSharp.dll" error

查看:1057
本文介绍了C#动态编译和“Microsoft.CSharp.dll”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个例子,可以找到这里
所以我试图在C#脚本中运行IronPython:



Python:

  def hello(name):
printHello+ name +!欢迎来到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))
返回

C#:

 使用IronPython.Hosting; 
使用IronPython.Runtime;
使用Microsoft.Scripting.Hosting;
使用系统;

命名空间IntroIronPython
{
class IronPythonMain
{
static void Main(string [] args)
{
//为IronPython创建一个新的ScriptRuntime
Console.WriteLine(Loading IronPython Runtime ...);
ScriptRuntime python = Python.CreateRuntime();

尝试
{
//尝试加载python文件
Console.WriteLine(加载Python文件...);
//为我们的Python文件创建动态类型
dynamic pyfile = python.UseFile(PythonFunctions.py);
Console.WriteLine(Python File Loaded!);

Console.WriteLine(运行Python命令... \\\
);

//调用hello(name)函数
pyfile.hello(Urda);
...

从这里我有这个错误:
动态操作不能编译时没有Microsoft.CSharp.dll程序集引用。
我真的不明白这是什么,我忘了添加什么?



在我的引用中我有:



Thx为您的帮助。 p>

Ps:我在MonoDevelop。

解决方案

基本上我的错误与我从错误的平台添加了IronPython程序集的事实有关。
验证:




  • 目标框架:4.0


  • 添加IronPython在[IronPython-2.7.3] - > [Platforms] - > [Net40]中提供的所有程序集。



向所有给予我意见的人提供了这个。



Ps:现在,当然还有另外一个问题...但是不再是这个话题了。


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 + "! 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

C#:

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 "Microsoft.CSharp.dll" assembly reference." And I seriously don't understand what that is about, what did I forget to add?

In my references I have:

Thx for your help.

Ps: I'm on MonoDevelop.

解决方案

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.

这篇关于C#动态编译和“Microsoft.CSharp.dll”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆