none
MS VS 2013 EF6.1.1 An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll RRS feed

  • Question

  • I hav e a simple .NET Application (MS Visual Studio 2013, .NET 4.5.1 EF 6.1.1).

    When I want to access the database, I get following error:

    An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

    Additional information: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

    THe error occurs at (AdresModel.Context.cs)

    namespace adressen
    {
        using System;
        using System.Data.Entity;
        using System.Data.Entity.Infrastructure;
        using System.Data.SqlClient;
        
        public partial class AdressenEntities: DbContext
        {
            public AdressenEntities()
                : base("name=AdressenEntities") <------error
            {
            }
        
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                throw new UnintentionalCodeFirstException();
            }
        
            public virtual DbSet<Adres> Adres { get; set; }
        }
    }

    My App.Config is as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
      <connectionStrings>
      <add name="AdressenEntities" connectionString="metadata=res://*/AdresModel.csdl|res://*/AdresModel.ssdl|res://*/AdresModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\sqlexpress;initial catalog=Adressen;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
      </startup>
    </configuration>

    I found on the internet that also other people had a problem with this, but so far no solution.

    Thank you for any help.

    Willem


    Sunday, September 7, 2014 8:55 AM

All replies

  • THis is an indication that you machine.config file is broken, try totemporarily replace with one from a machine that Works, and the observe the differences.

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Sunday, September 7, 2014 9:31 AM
  • I have a package.config, but no machine.config.

    To my understanding, the package.config is OK.

    Do I need a machine.config?

    Kind Regards,

    Willem

    Sunday, September 7, 2014 9:48 AM
  • Everyone has a machine.config, it is part of the .NET Framework,on my PC it is in: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config

    or

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config if your app runs under x64


    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Sunday, September 7, 2014 9:50 AM
  • Can you on one laptop, use Sql Server and MySql in different applications?

    Willem

    Sunday, September 7, 2014 4:36 PM
  • Sure...

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Sunday, September 7, 2014 5:03 PM
  • public static void Toevoegen(AdresBO adres)
            {
                using (AdressenEntities2 entities = new AdressenEntities2())
                {
                    Adres nieuwAdres = new Adres {naam = adres.Naam,adres1 = adres.Adres,postcode = adres.Postcode,
                        gemeente = adres.Gemeente,land = adres.Land,telefoon = adres.Telefoon,gsm = adres.Gsm,email = adres.Email };
    
                    entities.Adres.Add(nieuwAdres); <-------
                    entities.SaveChanges();
                }
            }  


    I can compile the above code; I had expected that I could compile the following:

    public static void Toevoegen(AdresBO adres)
            {
                using (AdressenEntities2 entities = new AdressenEntities2())
                {
                    Adres nieuwAdres = new Adres {naam = adres.Naam,adres1 = adres.Adres,postcode = adres.Postcode,
                        gemeente = adres.Gemeente,land = adres.Land,telefoon = adres.Telefoon,gsm = adres.Gsm,email = adres.Email };
    
                    entities.AddObject(nieuwAdres); <-------
                    entities.SaveChanges();
                }
            }  

    Is this part of the problem?

    Sunday, September 7, 2014 7:08 PM
  • Hello Willem,

    >>I can compile the above code; I had expected that I could compile the following:

    Since your context class is derived from DbContext, it provides the way to add a new entity like “entities.Adres.Add(nieuwAdres);” , while the second way AddObject() is used with ObjectContext.

    If you want to use the AddObject() way, since you are working with EF6, you need to install this extension:

    http://visualstudiogallery.msdn.microsoft.com/66612113-549c-4a9e-a14a-f629ceb3f89a

    After installing it, the model could generate entities derive from ObjectContext and then you could use the AddObject method.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 9, 2014 8:15 AM
    Moderator

  • EntityFramework.SqlServer.dll

    should be present in bin folder while you run application. Please verify whether EntityFramework.SqlServer.dll is present in bin folder.

    • Proposed as answer by Anand Panse Thursday, January 8, 2015 10:09 PM
    Thursday, January 8, 2015 10:08 PM