Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded #603

Closed
Salwaa opened this issue May 12, 2015 · 40 comments

Comments

@Salwaa
Copy link

Salwaa commented May 12, 2015

I installed EF 6.1.3, Npgsql 2.2.5, and Npgsql.EntityFramework using Nuget in my ASP.NET MVC 3 Project (VS 2010). I also registered Npgsql to GAC + added Npgsql provider to machine.config, etc. All this, by following Kenjiuno's tutorial (Many thanks to him btw!).
Now when trying to add a controller and after choosing : "Controller with read/write actions and views, using Entity Framework" template, I get the following error :

Unable to retrieve metadata for 'MvcApplication.Models.centredevote'.
The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded.
Make sure that the assembly-quallified name is used and that the assembly is available to the running application.
See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

I searched the error and came across a post stating the same issue.. The solution mentioned was to add Npgsql.EntityFramework using Nuget, but I have already Npgsql.EntityFramework installed.. The dll files are present in the references section in visual studio too.. So I really don't know what's wrong..
In my web.config file I have this line in the provider's tag, under the "entityFramework" tag :

provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"

@franciscojunior
Copy link
Member

Did you add mono.security.dll to gac as well? Npgsql 2.2.5 needs it.

I hope it helps.
Em 12/05/2015 09:30, "Salwaa" notifications@github.com escreveu:

I installed EF 6.1.3, Npgsql 2.2.5, and Npgsql.EntityFramework using Nuget
in my ASP.NET MVC 3 Project (VS 2010). I also registered Npgsql to GAC +
added Npgsql provider to machine.config, etc. All this, by following
Kenjiuno's tutorial (Many thanks to him btw!).
Now when trying to add a controller and after choosing : "Controller with
read/write actions and views, using Entity Framework" template, I get the
following error :

Unable to retrieve metadata for 'MvcApplication.Models.centredevote'.
The Entity Framework provider type 'Npgsql.NpgsqlServices,
Npgsql.EntityFramework' registered in the application config file for the
ADO.NET provider with invariant name 'Npgsql' could not be loaded.
Make sure that the assembly-quallified name is used and that the assembly
is available to the running application.
See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

I searched the error and came across a post stating the same issue.. The
solution mentioned was to add Npgsql.EntityFramework using Nuget, but I
have already Npgsql.EntityFramework installed.. The dll files are present
in the references section in visual studio too.. So I really don't know
what's wrong..
In my web.config file I have this line in the provider's tag, under the
"entityFramework" tag :

provider invariantName="Npgsql" type="Npgsql.NpgsqlServices,
Npgsql.EntityFramework"


Reply to this email directly or view it on GitHub
#603.

@Salwaa
Copy link
Author

Salwaa commented May 12, 2015

I have added Mono.Security.dll as well to GAC.. Still getting the same error!
Here's a screenshot of the command line :
screenshot

@franciscojunior
Copy link
Member

Hmmmm, as you added the configuration to the machine.conf ( you changed
both 32 and 64 bits version, right? ) , try to remove the provider factory
configuration from your web.config. it should use the existing from
machine.config.

I hope it helps.

I have added Mono.Security.dll as well to GAC.. Still getting the same
error!
Here's a screenshot of the command line :
[image: screenshot]
https://cloud.githubusercontent.com/assets/6245314/7590469/98c405e4-f8c0-11e4-9606-cf3e3f5c2ba6.PNG


Reply to this email directly or view it on GitHub
#603 (comment).

@kmschaefer
Copy link

I would suggest that you uninstall Npgsql and Mono.Security from your GAC with the /u option and remove the entries you added to the machine.config files.

Next, go and get the .exe and .zip files for your .NET version here: https://github.com/npgsql/npgsql/releases/tag/v2.2.5.

Run the setup file, then replace the Npgsql.dll and Npgsql.EntityFramework.dll in your project with the ones from the .zip file.

The version of Npgsql.dll in the GAC needs to match the version in your project.

You will probably still need to add the DbProviderFactory entry to your web.config. I'll post mine tomorrow when I get to work.

I hope this helps.

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

@franciscojunior Yes I've changed both 32 and 64 bits machine.config files. Also tried what u suggested (removing the provider factory configuration from my web.config), but it throws me another error now :
error1

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

@kmschaefer I really appreciate ur detailed answer. Thank u :)
I just started doing what u suggested me to do but I couldn't uninstall Npgsql and Mono.Security from GAC with the /u option.. I don't know what I might be doing wrong but I get this :
capture

@kenjiuno
Copy link
Contributor

Hi @Salwaa

Please try them for uninstall:

gacutil /u "Npgsql, Version=2.2.5.0"

gacutil /u "Mono.Security, Version=4.0.0.0"

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

Thanks a LOT @kenjiuno ! I will proceed now with @kmschaefer 's suggestion..
Do u have any other thoughts too on this issue ?

@kenjiuno
Copy link
Contributor

Hi.

I'll test this soon!
I have successfully installed ASP.NET MVC 3 with this workaround just now.

@kmschaefer
Copy link

Sorry about not typing the whole command for uninstall. I usually just do 'gacutil /u Npgql' and not worry about the version. That way you remove all versions that might be causing you problems, if it is even possible to have multiple ones installed.

I had originally typed the commands, but my browser session locked up :)

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

@kmschaefer It's okay ^^ I managed to unistall them thanks to @kenjiuno :) !
I was wondering though, what's the difference between these two .exe files : Setup_Npgsql-2.2.5.0-r2-net40.exe and Setup_Npgsql-2.2.5.0-net40.exe ?
I don't know which one of them I should be installing..

@kenjiuno
Copy link
Contributor

Hi.

Please use 2.2.5.0-r2. It contains official Npgsql.dll.

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

So I followed all the instructions mentioned by @kmschaefer (I executed the 2.2.5.0-r2 .exe file btw as u said @kenjiuno ).
Now when trying to add a controller to my project I get this error :
capture2

@kenjiuno
Copy link
Contributor

Hi.

Could you post Web.config in your project?

For example, this is from my sample project:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="Add2files_dbEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=Npgsql;provider connection string=&quot;PORT=9400;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.2.5.0;HOST=127.0.0.1;USER ID=Add2files_db;PASSWORD=Add2files_db;DATABASE=Add2files_db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

I'm using EntityFramework 4.1.0.0 that is installed at project initialization.

@kenjiuno
Copy link
Contributor

Hi.

Npgsql and Npgsql.EntityFrameworkLegacy (.NET 4.0 version) can be used with ASP.NET MVC 3 Web Application using VS 2010.

This is my sample web output:

mvc3sample

It uses VS 2010 features:

  • Model: built by EntityDataModel Wizard
  • View: razor?
  • Controller: Controller with read/write action and views, using Entity Framework

It displays my file location database stored on my computer.

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

Here's my web.config file :

<?xml version="1.0" encoding="utf-8"?>
<!--  For more information on how to configure your ASP.NET application, please visit  http://go.microsoft.com/fwlink/?LinkId=152368  -->
<configuration>
 <configSections>
 <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 </configSections>
 <!-- 
 <connectionStrings>
 <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
 </connectionStrings> 
-->
 <connectionStrings>
 <add name="electionscasaEntitiesModel" connectionString="metadata=res://*/Models.electionsModel.csdl|res://*/Models.electionsModel.ssdl|res://*/Models.electionsModel.msl;provider=Npgsql;provider connection string=&quot;PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.2.5.0;DATABASE=electionscasa;HOST=localhost;USER ID=sde;" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
 <add key="webpages:Version" value="1.0.0.0" />
 <add key="ClientValidationEnabled" value="true" />
 <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
 <compilation debug="true" targetFramework="4.0">
   <assemblies>
     <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
     <!--<add assembly="Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />-->
    </assemblies>
  </compilation>
 <authentication mode="Forms">
   <forms loginUrl="~/Account/LogOn" timeout="2880" />
 </authentication>
 <membership>
   <providers>
     <clear />
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
   </providers>
 </membership>
 <profile>
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
  </providers>
 </profile>
  <roleManager enabled="false">
   <providers>
     <clear />
     <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
     <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
   </providers>
  </roleManager>
  <pages>
    <namespaces>
     <add namespace="System.Web.Helpers" />
     <add namespace="System.Web.Mvc" />
     <add namespace="System.Web.Mvc.Ajax" />
     <add namespace="System.Web.Mvc.Html" />
     <add namespace="System.Web.Routing" />
     <add namespace="System.Web.WebPages" />
    </namespaces>
  </pages>
</system.web>
<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
   <dependentAssembly>
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
   <dependentAssembly>
     <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-2.2.5.0" newVersion="2.2.5.0" />
    </dependentAssembly>
   <dependentAssembly>
     <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
    </dependentAssembly>
    <loadFromRemoteSources enabled="true" />
    <dependentAssembly>
    <assemblyIdentity name="System.Data.Entity" publicKeyToken="b77a5c561934e089" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
   </dependentAssembly>
   <dependentAssembly>
     <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
   </assemblyBinding>
</runtime>
 <entityFramework>
 <!--
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
   <parameters>
     <parameter value="mssqllocaldb" />
   </parameters>
   </defaultConnectionFactory> -->
   <defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql.EntityFramework">
     <parameters>
      <parameter value="electionscasaEntitiesModel" />
     </parameters>
   </defaultConnectionFactory>
   <providers>
     <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
    <!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
    </providers>
  </entityFramework>
 <system.data>
 <DbProviderFactories>
   <remove invariant="Npgsql" />
   <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
   </DbProviderFactories>
  </system.data>
</configuration>

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

Right after I click on Add, I get the error mentioned above
entityframework

@kenjiuno
Copy link
Contributor

Hi.

Please remove these lines. defaultConnectionFactory is not mandatory.

       <defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql.EntityFramework">
         <parameters>
          <parameter value="electionscasaEntitiesModel" />
         </parameters>
       </defaultConnectionFactory>

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

Done that. Re-built the project, yet still getting that error :( !
capture2

@kenjiuno
Copy link
Contributor

Hi.

    <add name="electionscasaEntitiesModel" connectionString="...;USER ID=sde;&quot;" providerName="System.Data.EntityClient" />

Please add the missing &quot; after USER ID=sde;.

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

I actually have the password too.. And it has the quot; after it..
I noticed one thing though.. I installed EntityFramework using Nuget, and it has downloaded the 6.1.3 version.. Normally the web.config file should be updated but I see here :

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

That the version is 6.0.0.0 ?? I tried editing it manually to 6.1.3.0... Still having the same problem though... I don't even understand the error ? Would u like to enlighten me please @kenjiuno ..
And thank u soo much for ur time.. Reaally appreciate ur efforts :)!

@kenjiuno
Copy link
Contributor

I actually have the password too.. And it has the quot; after it..

Ok, so there is no problem...

That the version is 6.0.0.0 ??

EntityFramework, Version=6.0.0.0 is Ok.

6.0.0.0 is assembly version. This is important to specify assembly.
6.1.3.0 is file version. It will be updated if newer version is released.

I'll continue to check possible things.

@kenjiuno
Copy link
Contributor

Also, try to delete them from Web.config...

     <system.data>
     <DbProviderFactories>
       <remove invariant="Npgsql" />
       <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
       </DbProviderFactories>
      </system.data>

I got the following message you have posted at first, when I have DbProviderFactories in Web.config:

Unable to retrieve metadata for 'MvcApplication.Models.centredevote'.
The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded.
Make sure that the assembly-quallified name is used and that the assembly is available to the running application.

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

Back to square 1.. I'm getting that initial error too.. And this happened after I unistalled both "EntityFramework" and "Npgsql.EntityFramework" packages from Nuget.. And re-installed them once again.. I also removed those line u just mentioned and now I'm getting this :
error3

@kenjiuno
Copy link
Contributor

Hmm...

I cannot know what's happened...

Could you try to capture the log of devenv.exe?
https://msdn.microsoft.com/en-us/library/ms241272(v=vs.100).aspx

I hope it may contain the exception log to check this issue...

The default output will be:
%APPDATA%\Microsoft\VisualStudio\10.0\ActivityLog.xml

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

I couldn't find that "ActivityLog.xml" file :(.. Is there anyway to restore it or something?
(It might have been deleted 'cause I run CCleaner more often.. :()

@kmschaefer
Copy link

I would suggest that you do not install Npgsql or Npgsql.EntityFramework via nuget. Uninstall them, then manually add references to the two .dll files from the .zip file that you downloaded with the .exe file. This could at least help rule out any mismatches.

@kmschaefer
Copy link

That happens to me when I forget to add the provider to the web.config:

<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />

@Salwaa
Copy link
Author

Salwaa commented May 13, 2015

I mistakenly deleted my previous reply.. Sorry..
I actually found that NpgsqlDdex Provider was disabled from Nuget.. Now that part is solved..
Back to getting this error now when I try to add the controller with read/write actions, views using entity framework..
This is taking me a lot of time already :(
capture2

@kmschaefer
Copy link

Can you provide your model for centredevote?

@Salwaa
Copy link
Author

Salwaa commented May 14, 2015

Hi @kmschaefer, sorry for my late reply.. I've generated the code from the model.. Here's my model for centredevote (and by the way, I get the error by trying to add controllers for each one of my entities, not only this one :()

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace MvcApplication.Models
{
 using System;
 using System.Collections.Generic;

 public partial class centredevote
 { 
    public centredevote()
    {
        this.bureaudevote = new HashSet<bureaudevote>();
    }

    public int objectid { get; set; }
    public string arabicname { get; set; }
    public string frenchname { get; set; }
    public Nullable<int> fk_prefecture { get; set; }

    public virtual prefecture prefecture { get; set; }
    public virtual ICollection<bureaudevote> bureaudevote { get; set; }
 }
}

@Salwaa
Copy link
Author

Salwaa commented May 14, 2015

In the connection string I've noticed something.. (It was added automatically after I've generated the model from my database)..
Here in my web.config :

  <connectionStrings>
      <add name="electionscasaEntitiesModel" 
       connectionString="metadata=res://*/Models.electionsModel.csdl|res://*/Models.electionsModel.ssdl|res://*/Models.electionsModel.msl;provider=Npgsql;provider connection string=&quot;PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.2.5.0;DATABASE=electionscasa;HOST=localhost;USER ID=sde&quot;" 
       providerName="System.Data.EntityClient"/>
  </connectionStrings>

Shouldn't the providerName be "Npgsql.NpgsqlConnection" instead of "System.Data.EntityClient"? Normally the last one is for SQL Server, no?

EDIT : I've tried Npgsql.NpgsqlConnection but no luck either... Help?

@Salwaa
Copy link
Author

Salwaa commented May 14, 2015

I've uninstalled EntityFramework 6.1.3.. As well as the related packages such as Npgsql.EntityFramework..
I uninstalled them from GAC too.. Then ran : Install-Package EntityFramework -Version 5.0.0
After that I've deleted the reference to Npgsql.EntityFramework and left only Npgsql.EntityFrameworkLegacy.dll..
Followed all the necessary steps, yet still getting the saame error..
Any guidance please? I'm litterally stuck :(.. Is there any workaround at least so I can generate my controllers using scaffolding??

@Salwaa
Copy link
Author

Salwaa commented May 14, 2015

After I have generated my model from database using ADO.NET... Normally I should get the .csdl , .ssdl, .msl files hidden in the Models folder, right? (I saw that on some posts).. Maybe that's why I get this error related to metadata ?? But why aren't they generated automatically? And is there any way to add them and what should they contain?
solutionexplorer

@kmschaefer
Copy link

If you right-click your electionsModel.edmx file and select Open With..., then select XML (Text) Editor, you should be able to see the SSDL content, CSDL content, and C-S mapping content. Mine are not separate files in the project.

As for the model that you are trying to build the controller, I would try and use one that has only primitive types like int and string. If you have access to create a table in the database, I would just create a really simple test one. That is what I did for testing the cidr, inet, macaddr, date, timestamp, and timestamptz Postgresql types. I had an issue where Npgsql.dll was converting timestamptz types to DateTime, but Npgsql.EntityFramework.dll was expecting them to be DateTimeOffset. When I tried to create a scaffolded controller of any models for tables that had timestamptz columns it would throw an exception. I had to modify the source code for the Npgsql.EntityFramework project to get it to work. That is why I suggest trying a really simple example and working your way up from there.

Here is my connection string that was created. I don't have the compatible entry, but my providerName is the same as yours:
<add name="ltaccEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=Npgsql;provider connection string=&quot;Database=database;Server=server;Password=password;Port=5432;Username=username&quot;" providerName="System.Data.EntityClient" />

I wish I could be of more help, but I'm pretty new to Entity Framework and Npgsql.

@kenjiuno
Copy link
Contributor

Hi @Salwaa .

Please try to debug Visual Studio by Visual Studio.

We need to know the detail about Exception thrown:

Unable to retrieve metadata for 'MvcApplication.Models.centredevote'.
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.

Steps:

Launch 1st Vs 2010. It is Vs2010 No1.
Launch 2nd Vs 2010. It is Vs2010 No2.

[Vs2010 No1] Open your MvcApplication

[Vs2010 No2] Menu [DEBUG]→[Attach to process], attach to devenv.exe (Vs2010 No1) with attach target Auto: managed (v4.0) code.

[Vs2010 No1] Try to add MVC controller. Exception will be thrown.

[Vs2010 No2] Show [VIEW]→[Output]. You will see the thrown exception names like:

...
'System.Configuration.ConfigurationErrorsException' の初回例外が System.Data.dll で発生しました。
'System.Reflection.TargetInvocationException' の初回例外が mscorlib.dll で発生しました。
'System.Configuration.ConfigurationErrorsException' の初回例外が Microsoft.VisualStudio.Web.Mvc.3.01.dll で発生しました。
...

In my case, System.Configuration.ConfigurationErrorsException is important.

[Vs2010 No2] Menu [DEBUG]→[Exceptions]. [Find], System.Configuration.ConfigurationErrorsException. If there is no match, click [Add].

  • Type = Common Language Runtime Exceptions,
  • ExceptionName = System.Configuration.ConfigurationErrorsException

Turn on Thrown, [Ok].

[Vs2010 No1] Try to add MVC controller again.

[Vs2010 No2] The IDE will be activated. The Vs2010 No1 now freezes.

[Vs2010 No2] In exception assistant, [Copy exception detail to the clipboard]

[Vs2010 No2] Menu [DEBUG]→[Run] to continue.

[Vs2010 No1] The error message box will be displayed.

Paste the "exception detail" to notepad or such.

The catched exception looks like this format.

System.Configuration.ConfigurationErrorsException が発生しました。
  HResult=-2146232062
  Message=登録されている .Net Framework データ プロバイダーが見つからないか、読み込めませんでした。
  Source=System.Data
  BareMessage=登録されている .Net Framework データ プロバイダーが見つからないか、読み込めませんでした。
  Line=0
  StackTrace:
       場所 System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
  InnerException: 

I think we will be able to extract useful information from Exception output.

I have fixed this issue by tweaking Web.config's DbProviderFactories.
Edit from
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0" />
to
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />

@Salwaa
Copy link
Author

Salwaa commented May 14, 2015

@kmschaefer I really appreciate your answers. Thank u soo much. You've been of a great help too :)!
I tried what u suggested yet it didn't work :/
@kenjiuno Many thanks for your detailed reply. Now here's what I got so far.. When I go to [Vs2010 No2] Show [VIEW]→[Output], I don't get the same thrown exceptions as u do.. Here's what I have :
output1

What should I be looking for in [Vs2010 No2] Menu [DEBUG]→[Exceptions]. [Find] ?

@Salwaa
Copy link
Author

Salwaa commented May 15, 2015

I'm thinking of switching the ORM and using NHibernate instead of EntityFramework.. And give it a try maybe? Time is running out of me and I can't seem to figure out the problem so far.. :s
Is there a support for Npgsql with NHibernate?
Is there a workaround at least? So I can generate Scaffolding code based on my model?

@kenjiuno
Copy link
Contributor

Hi.

I'm sorry that I can't help on this problem.

I'm thinking of switching the ORM and using NHibernate instead of EntityFramework.. And give it a try maybe? Time is running out of me and I can't seem to figure out the problem so far.. :s

I don't have good idea whether ASP.NET MVC 3 runs on NHibernate model.

I have a question. Could you build your project successfully, and browse it now?

If you can build and run, there is a selection to implement controllers by yourself.

The following files are generated ones by my model:

mvcapp6

I have uploaded my test project: MvcApplication6.7z
https://drive.google.com/file/d/0BzIsP2o582nbMWpHOTFHdUEzXzg/view?usp=sharing

You can check it if it is good idea to write the controllers by yourself...

@roji roji added the ef6 label May 8, 2016
@roji
Copy link
Member

roji commented May 8, 2016

Am going to close this for inactivity, Npgsql 2.x is quite old by now. If you still have an issue please try 3.0.x and open a new issue.

@roji roji closed this as completed May 8, 2016
@roji roji added the invalid label May 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants