Question

I hate to ask a question that's been asked here countless times, as well as been blogged about all over the place, but I still can't get my upgraded project to work.

My application was originally written in VS2008, targeting .NET 3.5 SP1. I just upgraded to VS2010, and figured that I'd try to take advantage of the new language features and integrated MEF, so I changed all of my projects to target .NET 4.0. After getting everything (like post build events, MEF references, and stuff like that) set up properly and compiling properly, I ran my application and got the ever-famous error:

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

I then added the following attribute to my <startup> element in app.config:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup>

But when I run my application, I still get the same error. Is there anything I can do to debug this problem further? I literally have no idea what else to try. I'm trying to find as much information as I can on mixed mode assemblies and the way they interact with the CLR, but my background knowledge in this area is limited at best.

I've also tried to get around the problem by recompiling log4net's source to target .NET 4.0, but that didn't work out the way I had hoped. After compiling, I got this error:

Inheritance security rules violated while overriding member: 'log4net.Util.ReadOnlyPropertiesDictionary.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.

So I found a post that recommended trying to add the following line to AssemblyInfo.cs:

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

And when I did that, I ended right back where I began! (with the mixed mode assembly error).

Ugh.

Was it helpful?

Solution

I ended up getting everything to work after recompiling the source, targeting .NET 4.0. I still don't like this because everyone says it should work. The one thing I also had to do to get the application to finally run was to use MEF2 from CodePlex, and not the one built into .NET 4.0. I don't see why those two things would be related, but I'll go back and try to make it work with log4net as-is. I'll post the details here once I'm done, and hopefully it will help out someone else that has run into the same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top