This project has moved and is read-only. For the latest updates, please go here.

Compiling for .NET 4.0?

May 14, 2012 at 8:21 PM

Hi All,

Has anyone had success compiling the Jurassic.dll for 4.0 instead of 3.5? I can get it to compile but the unit tests won't run, the following exception is thrown:

System.TypeLoadException was unhandled
  Message=Inheritance security rules violated while overriding member: 'Jurassic.ScriptEngine.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
  Source=Test Suite Runner
  TypeName=Jurassic.ScriptEngine.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
       at Jurassic.TestSuite.Program.Main(String[] args)
       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 ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

May 15, 2012 at 7:56 AM
Edited May 15, 2012 at 7:56 AM

I compile & run Jurassic in .NET 4.0 as my primary platform, with no issues, so I'm not sure why you are getting an error.  It looks like a security error - are you running in low trust (i.e. in Silverlight, WP7 or from a network share)?  Might there by any other reason why .NET is running in low privilege mode that you can think of (maybe you have low privilege mode set in your project settings)?

May 15, 2012 at 6:35 PM

Hi Paul,

Thanks for the reply. Here's what I tried:

1. Download the latest source.

2. Open the solution in VS2010.

3. Change target for Jurassic.dll to .Net Framework 4

4. Build Jurassic.dll

5. Reference Jurassic.dll from a simple console app, which does this:

 class Program
    static void Main(string[] args)
        ScriptEngine engine = new ScriptEngine();
        object r = engine.Evaluate("x = 100;");


The first thing that happens, when the console application is executed, is that the system complains about GetObjectData not being marked with [SecurityCritical] and so I went through and marked all of the GetObjectData implementations with that attribute.

If I go ahead and then mark all the GetObjectData implementations with the [SecurityCritical] attribute, that takes care of the first exception, but then the system complains about line 127 in DynamicIlGenerator.cs and throws the following exception:

System.Security.VerificationException occurred
  Message=Operation could destabilize the runtime.
       at Jurassic.Compiler.DynamicILGenerator.Complete() in C:\tmp\jurassic\jurassic_2359aadc27fe\Jurassic\Compiler\Emit\ILGenerator\DynamicILGenerator.cs:line 127

I'm running this as Administrator on my local desktop, from the local drive, so not sure about any permission issues this relates to.

I'm sure I can go ahead with the 3.5 binaries (this doesn't happen when I target 3.5, just when I change Jurassic.dll to 4.0), I was just hoping there was an easy way to target 4.0 as part of my Azure project.

Thanks for any suggestions, and I hope you keep up the great work - this is a great project!



May 15, 2012 at 6:54 PM

Okay, so I got a little further with that. It turns out that adding:

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

To the AssemblyInfo.cs module for Jurassic.dll fixes the problem with the final exception I was getting. I don't know what the issue is with Jurassic and the .NET 4.0 security model, but reverting to the 2.0 rules seems to make everything run fine!