I am running into a weird issue with my managed C++ assembly. Even though I have the C# project and the managed C++ (DLL) project set to target .NET 3.5, when I compile the managed assembly its “Runtime Version” is 2.0.
I am trying to use the same assembly across a .NET 3.5 project and a .NET 4.0 version of a CSScript and the CSScript refuses to run with a .NET 2.0 assembly (“Runtime Exception: 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 managed to localize the problem to the following (all work done in VS 2008):
- I create a C# project targeting .NET 3.5.
- I create an empty C++ project in the same solution.
- Add an empty .cpp file to the C++ project.
- Change the C++ project properties: Configuration Type = Dynamic Library (.dll), Common Language Runtime support = Common Language Runtime Support (/clr), and make sure that Common Properties’ “Targeted Framework” is set to 3.5
- Compile the C++ project and add it as a reference to the C# project.
When you look at the properties of the reference in the C# project you will see the “Runtime Version” is v2.0.50727. My question is, what the hell?
Why is the runtime version 2.0? I set everything to 3.5 … How can I force the managed C++ project to compile against .NET 3.5?
Thanks,
Marek
Your “fix” won’t actually fix the problem.
You need to use the 4.0 runtime to avoid this, no point in even trying for some mythical “3.5” version. For that, you need to compile using the VC++ 2010 compiler. Since you need to use it in a .NET 3.5 application, that’s a non-starter.
Try looking into that “additional configuration information”. See this question and also this one.