Search code examples
c#.netentity-frameworkmixed-mode

Library .NET version exception


Im trying do my first steps in Winforms development with C# and .NET framework. I want to make a little users CRUD application. I have the SQLite db populated with test data.

So, i create a blank project solution, and added a "Class library" project called "DataBundle".

In the DataBundle, have the entity class for the database, mapped with Entity Framework.

Also, i created a console application for test my DataBundle. The app build correctlly, but when try run querys the application throw an exception.

This is my code:

Console.WriteLine("Testeando el DataBudnle ...");
mainContext _dao = new mainContext();

Zone city = new Zone
{
  name = "Ensenada"
};

Console.WriteLine("Existen {0} ciudades registradas ...", _dao.Zones.Count());
Console.ReadLine();

And the exception message is:

The mixed-mode assembly is compiled with 'v2.0.50727' version of the runtime and can not be loaded in the 4.0 runtime without additional configuration information.

Im using Visual Studio 2010 Ultimate, Windows 7 Professional with .NET 4 Framework installed.

Any ideas ?


Solution

  • As Steve suggested there, add this in the console application App.config file

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