无法确定类型的供应商工厂的供应商名称“Npgsql.NpgsqlFactory” [英] Unable to determine the provider name for provider factory of type 'Npgsql.NpgsqlFactory'

查看:341
本文介绍了无法确定类型的供应商工厂的供应商名称“Npgsql.NpgsqlFactory”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个测试项目,但我没有成功,因为有一个失败,npgsql连接。我重新安装了Npgsql,Npgsql.EntityFramework,EntityFramwork ......但问题仍然存在。
结果消息:

I trying running a test project but I not have a success because have a fail with npgsql connection. I reinstalled Npgsql, Npgsql.EntityFramework, EntityFramwork... but the problem persist. Result Message:

方法方法去睾丸TestUserControl.ControleBaseTest.TesteGetPermissoesUsuarioFixo鸽肉exceção:

Método de teste TestUserControl.ControleBaseTest.TesteGetPermissoesUsuarioFixo gerou exceção:

System.NotSupportedException:无法确定类型的供应商工厂Npgsql.NpgsqlFactory'提供者的名称。确保ADO.NET提供程序已安装或应用程序配置注册。
结果堆栈跟踪:

System.NotSupportedException: Unable to determine the provider name for provider factory of type 'Npgsql.NpgsqlFactory'. Make sure that the ADO.NET provider is installed or registered in the application config. Result StackTrace:

我有这个app.config文件:

I have this app.config file:

<?xml version="1.0" encoding="utf-8"?>
<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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient"     type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework">    </provider>
    </providers>
    <!--<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />-->
    <defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" />
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
    </DbProviderFactories>
  </system.data>
</configuration>

和一个DBCONFIG是...

And a DbConfig is...

public class CtxUser : DbContext
{
    public CtxUser(string conexao) : base(conexao) { }
    public CtxUser(DbConnection conexao) : base(conexao, true) { }
}

我的模型......

My Model...

[Serializable]
[Table("mytable", Schema = "public")]
public class Users
{
    [Key, Column("userid")]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    [Column("login")]
    public string Login { get; set; }

    [Column("password")] 
    public string Password { get; set; }
}



我的逻辑类...

My logical class...

private DbConnection Conexao { get; set; }
public ControleBase(DbConnection connector)
{
    if(conexao == null)
        throw new ArgumentException("blah blah", "connector");
    Conexao = conexao;
}

public Usuarios GetUser(int id)
{
    if(id <= 0)
        throw new ArgumentException("blah blah");
    Users user;
    using (var ctx  = new CtxUser(Connection))
    {
        user = ctx.DbUser.Find(id);
    }
    return user;
}



我的测试方法...

My test method...

[TestClass]
public class ControleBaseTest
{
    private DbConnection Conexao
    {
        get
        {
            var cnxBuilder = new NpgsqlConnectionStringBuilder
            {
                Database = "mydatabase",
                Host = "localhost",
                Port = 5432,
                UserName = "postgres",
                Password = "postgres",
                Enlist = true,
                CommandTimeout = 30,
                Timeout = 30,
                Pooling = true,
                MinPoolSize = 1,
                MaxPoolSize = 20,
                Compatible = new Version(2, 1),
                PreloadReader = true
            };
            return new NpgsqlConnection(cnxBuilder);
        }
    }

    [TestMethod]
    public void TestGetUser()
    {
        IUserControl userControl = new ControleBase(Conexao);            
        var usuario = userControl.GetUsuario(9);
        Assert.IsNotNull(usuario);
    }
}



明显,本次测试只针对Npgsql测试连接和LINQ等等......对于测试的问题的解决方案。有人有想法?

Obvious, this test is only for test connection with Npgsql and linq, etc... for test a solution for the problem. Someone have a idea?

推荐答案

我有同样的问题,并通过设置固定Npgsql.dll它是在本地复制
的参考属性。出于某种原因,VS 2013(也许其他versios以及)将这种
为假在一次看似随机点。这导致生成在它不
上的.dll复制到导致上述错误的汇编目录。

I had the same problem and fixed it by setting the Npgsql.dll to be copied locally in the reference properties. For some reason VS 2013 (maybe other versios as well) turns this to "false" at seemingly random points in time. This results in a build where it doesn't copy the .dll to your compilation directory resulting in the error described above.

我希望它可以帮助你,但它可能是你不同的东西。

I hope it helps you, but it may be something different for you.

这篇关于无法确定类型的供应商工厂的供应商名称“Npgsql.NpgsqlFactory”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆