[Mono-list] Security exception using 2.10 Evaluator with .Net

Bruce McKenzie bjmckenzie at gmail.com
Tue Mar 8 22:07:43 EST 2011

I recently saw the announcement of mono 2.10 which included the Mono C#
Compiler Service which seemed very relevant to a project under development.
We are using Visual Studio and .Net 4.0 (and eventually will want to use
this with Silverlight)

I downloaded and installed mono 2.10 (a great experience - thank you) and
then created a simple Windows console app in Visual Studio 2010. I added
Mono.CSharp to the references and the main program contains just a single

using Mono.CSharp;

namespace TestMono
    class Program
        static void Main(string[] args)
            var result = Evaluator.Evaluate("34 + 56;");

This compiled without a problem but when executed it raises an exception
when the line is executed. 

The exception is a TypeInitializationException and appears to occur when the
Mono.CSharp.dll assembly is loaded The inner exception complains about the
security of the type Location in the dll

{"Method 'Mono.CSharp.Location.ToString()' is security transparent, but is a
member of a 
 security critical type.":"Mono.CSharp.Location.ToString()"}

The full details of the exception are:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'Mono.CSharp.Evaluator' threw an
       at Mono.CSharp.Evaluator.Evaluate(String input)
       at TestMono.Program.Main(String[] args) in
c:\users\cnwbm1\documents\visual studio
2010\Projects\TestMono\TestMono\Program.cs:line 9
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.TypeLoadException
       Message=Method 'Mono.CSharp.Location.ToString()' is security
transparent, but is a member of a security critical type.
            at Mono.CSharp.Evaluator..cctor()

Can anyone shed any light on why this exception occurs?
Is it valid to mix mono and .Net 4.0 dlls in the manner I am attempting?

Thanks in advance

View this message in context: http://mono.1490590.n4.nabble.com/Security-exception-using-2-10-Evaluator-with-Net-tp3342676p3342676.html
Sent from the Mono - General mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20110308/b1bb3f0e/attachment.html 

More information about the Mono-list mailing list