TypeLoadException when building and using Microsoft.Dynamic and Microsoft.Scripting under VS2010 beta2


I have a project that uses DLR in .NET4 (beta 2). I want to use DefaultBinder, so I drag in Microsoft.Dynamic (which requires Microsoft.Scripting, so I drag that into my VS2010b2 solution, too). I configure MS.Dynamic and MS.Scripting to build against v4 framework (in project properties).
When I call into DefaultBinder.CallMethod, I get a TypeLoadException whenever MS.Scripting is first loaded into the AppDomain:
"Inheritance security rules violated while overriding member: 'Microsoft.Scripting.SymbolId.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."
Any thoughts on where I might be going wrong here?
Closed Apr 21, 2010 at 6:44 PM by rdawson


jplane wrote Nov 19, 2009 at 7:47 PM

Incidentally, I'm using the v0.92 DLR source...

BurtHarris wrote Dec 7, 2009 at 6:41 PM

I suspect this has something to do with the new security model in .NET 4

Doing a Bing search for "Inheritance security rules violated while overriding member" suggests this problem isn't limited to the DLR.

Seems very high impact to me.

rdawson wrote Jan 18, 2010 at 4:57 PM

Burt is likely correct on the source, but the fix is easy. Make sure you're using the "Microsoft.Dynamic.Build.csproj" and "Microsoft.Scripting.Build.csproj" (note the .Build.) Those are the .NET 4 projects. Specifically, this attribute needs to be on each assembly: [assembly: SecurityRules(SecurityRuleSet.Level1)]. It should already be defined in the .Build. projects.

leppie wrote Apr 16, 2010 at 1:08 PM

Why cant the default ruleset work?

jmesserly wrote Apr 21, 2010 at 6:42 PM

We could use Level2 rules, but it would mean Microsoft.Scripting and Microsoft.Dynamic would need to have Security*Attributes everywhere. Lots of code changes for minimal benefit.