C# IronPython抛出动态操作只能在同质AppDomain中执行

C# IronPython抛出动态操作只能在同质AppDomain中执行,c#,.net,ironpython,C#,.net,Ironpython,我正在测试从我的C#DLL对IronPython的调用,但是我得到以下异常动态操作只能在同质AppDomain中执行。来自var pythonResult=engine.Execute(脚本,范围)。在我的testFunc中添加了一个汇总元素的循环之后,出现了这个问题。当我删除循环元素时,这个方法可以很好地工作 我搜索了AppDomain的内容,但只找到了与ASP.NET开发相关的内容,与我的案例完全无关 var theScript = @"import sys def

我正在测试从我的C#DLL对IronPython的调用,但是我得到以下异常
动态操作只能在同质AppDomain中执行。
来自
var pythonResult=engine.Execute(脚本,范围)。在我的
testFunc
中添加了一个汇总元素的循环之后,出现了这个问题。当我删除循环元素时,这个方法可以很好地工作

我搜索了AppDomain的内容,但只找到了与ASP.NET开发相关的内容,与我的案例完全无关

            var theScript =
@"import sys
def testFunc():
    print list

    sum = 0;
    for i in list:
        sum += i

    return 3

testFunc()";

            var engine = Python.CreateEngine();
            var scope = engine.CreateScope();

            List<int> list = new List<int>();
            list.Add(2);
            list.Add(3);
            list.Add(7);
            scope.SetVariable("list", list);

            var pythonResult = engine.Execute(theScript, scope);
var脚本=
@“导入系统
def testFunc():
打印列表
总和=0;
对于列表中的i:
总和+=i
返回3
testFunc()”;
var engine=Python.CreateEngine();
var scope=engine.CreateScope();
列表=新列表();
增加(2);
增加(3);
增加(7);
scope.SetVariable(“列表”,列表);
var pythonResult=engine.Execute(脚本,范围);
这个问题阻碍了我的进一步发展。有什么想法吗?