的Mono.CSharp解释我的印象是Mono的编译器是usable in Microsoft.NET如何使用Microsoft.NET
编辑:updated blog posting here,我原来错过了一些解释它(是符合Justin的答案)
我创建了一个简单的类来尝试使用它
[TestFixture]
class Class1
{
[Test]
public void EXPR()
{
Evaluator.Run("using System;");
int sum = (int)Evaluator.Evaluate("1+2");
}
}
,并在Visual Studio 2010中的一个项目,它引用C:\ Program Files文件(x86)的\单-2.10.1 \ LIB \单声道\ 4.0 \单.CSharp.dll。
然而,当我尝试运行这个任务,我得到下面的异常,在Evaluator.Run调用抛出:
System.TypeInitializationException was unhandled by user code
Message=The type initializer for 'Mono.CSharp.Evaluator' threw an exception.
Source=Mono.CSharp
TypeName=Mono.CSharp.Evaluator
StackTrace:
at Mono.CSharp.Evaluator.Run(String statement)
at Experiments.Class1.EXPR() in W:\Experiments\Class1.cs:line 16
InnerException: System.TypeLoadException
Message=Method 'Mono.CSharp.Location.ToString()' is security transparent, but is a member of a security critical type.
Source=Mono.CSharp
TypeName=Mono.CSharp.Location.ToString()
StackTrace:
at Mono.CSharp.Evaluator..cctor()
InnerException:
阿谷歌证实了另外一个人问这个问题,但没有答案。我试图开始阅读the microsoft article on security transparent code,但很快就感到困惑。有人能够建议一个快速的解决方法,让我使用这个?并且可能总结出安全含义(如果有的话)给我(在我的情况下 - 未来我希望将它打包为一个厚客户端应用程序,以供内部和最终用户使用)
感谢您的非常全面的答案! – fostandy 2011-04-28 01:14:46