2

I've just upgraded my C# winforms app from dotnet 2.0 (VS2010) to dotnet 4.5 (VS2015). I'm now getting this error when trying to run it:

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

After doing a whole bunch of research, I understand its because my dotnet 4.5 app references code that was built using dotnet 2.0 (or 3.0 or 3.5 I think). The solution (according to what I have read), is to add some text to the app.config file. But no matter what I add (with closing down the app after each time), it doesnt work.

So far I have tried (in no particular order):

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

And

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5"/>
    <requiredRuntime version="v4.5.50709" />
</startup>

And

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <requiredRuntime version="v4.0.20506" />
</startup>

And

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>

and

<startup useLegacyV2RuntimeActivationPolicy="true" /> 

I'm running out of things to try.

I'm not sure if this is related, but my App.config file is giving me warnings when I mouse over certain areas, giving me a message like:

Imported schema for namespace 'urn:schemas-microsoft-com:asm.v1' was not resolved.

I raised this in another posting, but someone said this should not be an issue. A quick screenshot of this below: Mouseover message

Any assistance would be greatly appreciated.

My current App.config is shown below:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true" />

  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <section name="netTiersService" type="MyApp.Data.Bases.NetTiersServiceSection, MyApp.Data"/>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
    </sectionGroup>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Formatted EventLog TraceListener"/>
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}


EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: 

{appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread 

Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, 

Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter"/>
    </formatters>
    <categorySources>
      <add switchValue="All" name="Exceptions">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
        </listeners>
      </add>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events"/>
      <notProcessed switchValue="All" name="Unprocessed Category"/>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener"/>
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="NoneExceptionPolicy">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="Exceptions" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.XmlExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Logging Handler"/>
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  <connectionStrings>
    <add name="MyApp" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <netTiersService defaultProvider="SqlNetTiersProvider">
    <providers>
      <add name="SqlNetTiersProvider" type="MyApp.Data.SqlClient.SqlNetTiersProvider, MyApp.Data.SqlClient" useStoredProcedure="false" connectionStringName="MyApp" applicationName="MyAppWeb" providerInvariantName="System.Data.SqlClient" enableEntityTracking="false" useEntityFactory="false"/>
    </providers>
  </netTiersService>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="4.0.0.0" newVersion="5.0.414.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="4.0.0.0" newVersion="5.0.414.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Data" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="4.0.0.0" newVersion="5.0.414.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="4.0.0.0" newVersion="5.0.414.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <userSettings>
    <MyApp.Properties.Settings>
      <setting name="LastConnection" serializeAs="String">
        <value>LocalSqlServer</value>
      </setting>
    </MyApp.Properties.Settings>
  </userSettings>
  <applicationSettings>
    <MyApp.Properties.Settings>
      <setting name="MyApp_NAVService_MyAppInt" serializeAs="String">
        <value>http://localhost:7047/DynamicsNAV/WS/MyApp_Integration/Codeunit/MyAppInt</value>
      </setting>
    </MyApp.Properties.Settings>
  </applicationSettings>

</configuration>
Shaggs
  • 111
  • 3
  • 11
  • Sure. I've updated my post to include the App.config. – Shaggs Oct 22 '16 at 11:10
  • Thats one of the posts I have read on this, and I their suggested additions to the app.config are amongst those I tried. – Shaggs Oct 22 '16 at 11:36
  • As a further experiment, I deleted my App.config and started afresh. Now all I have in it is the startup node. So it looks like it isnt something else in the App.config causing a conflict. This is now the enirety of my app.config: ` ` – Shaggs Oct 22 '16 at 11:54
  • MyApp.Data is also dotnet 4.5. I have upgraded every project in this solution to dotnet 4.5, and everything else compiles fine, except the winforms project. The other projects also refer to dotnet 2.0 dll's, but they have not had this same issue. – Shaggs Oct 22 '16 at 19:29
  • Sorry - maybe my previous comment wasnt clear. I mean I stripped everything out except the startup bit, and I still get the error. – Shaggs Oct 22 '16 at 20:01
  • In desperation, I started deleting the references that use dotnet v2.0. After removing the first one (and fixing all the errors), it compiles!! The dll in question is one that I compiled myself, so I may be able to re-compile it as 4.5 and bring it in again. This may take a while - I'll update this if it worked or not. – Shaggs Oct 22 '16 at 20:16
  • Well, the dll in question is c++. I'm not sure if that changes anything. – Shaggs Oct 22 '16 at 20:30
  • Sorry - it isnt C++ - it has a component (one project) which is C++. Anyway, its a starting point. – Shaggs Oct 22 '16 at 20:37

1 Answers1

-1

The problem ended up being one specific dll (dotnet v2.0) that I was using. It was a C++ one, which somehow made it different to the many other dotnet ones (I dont knowhow - I dont know C++ that well at all).

Once I upgraded that solution to 4.5, and rebuilt it, everything worked fine.

Shaggs
  • 111
  • 3
  • 11