6

I'm using Visual Studio 2012 and the .Net Framework 4.5 I have 2 Solutions: 1) WPF Application 2) Class library (dll)

The Class Library contains 3 buttons and a control that has to be inside a WindosFormsHost control since it was made for WinForms.

The only referenced assemblies outside of the .NET Framework ones are for the aforementioned winforms control and iTextSharp.

The winforms control seems to be kinda old and when I put the reference in my dll I got the same error as the title but following other SO questions/answers, my I put this in my config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

The 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

As I mentioned, I've seen questions posting this issue, and they did solve the issue in my DLL project, but in the project using that DLL I've tried them all to no avail. For reference:

  1. What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?
  2. Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime
  3. What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config?
  4. Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime
  5. Mixed mode assembly is built against version X and cannot be loaded in version Y of the runtime without additional configuration information

In that project my config file has the exact same tags with the same values.

Also to note, in my WPF Application, at the beginning I was getting an error about it not being able to find the specified dll (for the winforms control), in the end I put that control's dll in the GAC.

I've tried changing my target framework for all of the possibilities (4.5, 4.0 full and client, 3.5 full and client, 3.0 and 2.0), building my DLL in debug and release and setting the "Generate serialization assembly" to OFF, also, changed the platform target from Any CPU to x86 and x64. I only tried changing the value of one setting at a time.

Is this a problem in VS2012 or what do I need to do to solve this?

EDIT:

The above error is shown at design time in the errors list, the designer shows an error saying "Cannot create an instance of 'my_class'"

The inner exception of that one says: "Set connectionId threw an exception" and the inner exception of this is the title message.

This still allows the solution to be built, and upon running the application, I get basically the same, except that the innermost exception says:

"Could not load file or assembly 'SigPlusNET, Version=1.1.3358.14336, Culture=neutral, PublicKeyToken=6aef07010bb0624f' or one of its dependencies. An attempt was made to load a program with an incorrect format."

That one is the winForms control's assembly, upon inspection through dotPeek, the only dependencies it has are .NET Framework ones

Community
  • 1
  • 1
Emmanuel Medina
  • 163
  • 1
  • 1
  • 15
  • Right-click your EXE project, Properties, Debug tab, untick the "Enable the Visual Studio hosting process" option and try again. – Hans Passant Jan 24 '13 at 20:10
  • I didn't mention this in my question, but I'm getting this at design time when I drag and drop my control from the toolbox (the program crashes when ran too), I will edit my question and add the Exception i get in run time – Emmanuel Medina Jan 24 '13 at 21:04
  • 2
    The second error you just posted in an edit is because SigPlusNET (or something it uses) is the wrong target platform. Either your app is 32-bit and SigPlusNET (or a dependency) is 64-bit, or the other way around. – Kevin Crowell Jan 25 '13 at 16:11

3 Answers3

4

Working with Bling for DirectX 10.0, (Bling UI Toolkit at CodePlex). I got the error that ended me up here on this page looking for the solution, the app.config file in the D3D10.example included the supported runtime, version=4 line. But it does NOT include a later line for the version=2 .net line, using the app.config as:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
  <supportedRuntime version="v2.0.50727" />
 </startup>
</configuration>

solved the problem, and all examples run in VS2012 once the config file is modified to the code shown.

I don't know if this post is to late for an answer, I'm just starting in windows 7 and VS2012 this month on a graphics project and the config change solved my problem.

Wayne C.
  • 56
  • 1
2

This might be caused because you have 4.0 in 1 location and 4.5 in another on this line:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

Try:

<supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5" />

or

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
Kevin Crowell
  • 10,082
  • 4
  • 35
  • 51
  • The error does say 4.0 runtime, does vs2012 uses another version? both my wpf and dll are using .net 4.5, so that's the reason of those values, in any case, I just tried what you said, and the problem persists. – Emmanuel Medina Jan 24 '13 at 19:09
  • I haven't been using 4.5, so I'm not sure. I hoped that it would work out for you. I guess it might be possible that you have both a 4.0 and 4.5 project and you need to have 2 "supportedRuntime" tags, 1 for 4.0 and another for 4.5. Can you try that? – Kevin Crowell Jan 24 '13 at 19:13
  • I did try that, doesn't work, looking around if vs2012 uses another runtime I found this: http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx See the xml below the third image in the "Developing Safely for both .NET 4 and .NET 4.5" section, it's the same as mine – Emmanuel Medina Jan 24 '13 at 20:15
2

My approach was a little different. The error clearly identifies some .NET 2.0.50727 component was included in .NET 4.0 In App.config file instead of use this:

<startup useLegacyV2RuntimeActivationPolicy="true"> 

It solved my problem

Bibaswann Bandyopadhyay
  • 3,389
  • 2
  • 31
  • 30
  • after all of the bang head here, i got it to work with this. It was an upgrade from 3.5 to 4.5.2 and the DTSX was failing on execute. – DirtyHowi Oct 24 '17 at 14:02