'Npgsql.TypeMapping.GlobalTypeMapper'的类型初始值设定项引发了异常 [英] The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception

查看:268
本文介绍了'Npgsql.TypeMapping.GlobalTypeMapper'的类型初始值设定项引发了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2017尝试使用服务器资源管理器将连接添加到Postgres数据库.单击测试连接.问题出现错误,并显示:'Npgsql.TypeMapping.GlobalTypeMapper'的类型初始值设定项引发了异常.

Using Visual Studio 2017 try using the Server Explorer to add a connection to a Postgres database. Click Test connection. The issue An error is shown with: The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception.

在此之前,我安装了System.Runtime.CompilerServices.Unsafe v4.5.2和System.Numerics.Vectors v4.4.0,以修复错误消息无法加载文件或程序集'System.Runtime.CompilerServices.Unsafe,版本= 4.0.4.1",并且无法加载文件或程序集'System.Numerics.Vectors,版本= 4.1.3.0.

Before that I installed System.Runtime.CompilerServices.Unsafe v4.5.2 and System.Numerics.Vectors v4.4.0 to fix the error message "Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1" and Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0.

我不知道要解决此问题'Npgsql.TypeMapping.GlobalTypeMapper'的类型初始值设定项引发了异常."

I have no idea to fix this "The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception."

我只想将PostgreSQL数据库的连接添加到Visual Studio2017.我已经在postgres中建立了一个数据库...我不知道要先安装什么才能添加该连接.

I just want to add the connection of PostgreSQL database to Visual Studio 2017. I already have a database in postgres... I don't know what I'm going to install first to add that connection.

在Visual Studio中安装Npgsql PostgresSQL Integration => Tools =>扩展和更新后,我创建了新项目并直接转到Manage Nuget Packages并安装了System.Runtime.CompilerServices.Unsafe v4.5.2和System.Numerics.Vectorsv4.4.0.我直接尝试在服务器资源管理器中添加连接.我对此一无所知.我只想在Visual Studio中添加postgres的数据连接,以便可以添加ADO.NET实体数据模型.

After I installed Npgsql PostgresSQL Integration in Visual Studio=>Tools=> Extension and update, I created new project and go directly to Manage Nuget Packages and installed System.Runtime.CompilerServices.Unsafe v4.5.2 and System.Numerics.Vectors v4.4.0. And I directly tried to add the connection in Server Explorer. I have no idea into this. I just want to add the data connection of postgres in visual studio so that I can add ADO.NET Entity Data model.

更多技术细节.NET Framework 4.6.1Npgsql版本4.1.1.2

Further technical details .NET framework 4.6.1 Npgsql version 4.1.1.2

推荐答案

这是我发现的一种潜在修复方法.很难确切了解它的作用,但是它可以工作!您可以将其添加到root中的csproj文件中.通过此处找到了.这似乎是一种hack.不确定是否有解决问题根源的方法.

Here is one potential fix that I found. It is hard to understand exactly what this does, but it works! You can add this to your csproj file within the root . Found this via here. This seems to be kind of a hack. Not sure if there is a solution to the root of the problem.

<Target Name="ReplaceRefWithLib" BeforeTargets="ResolveAssemblyReferences">
    <ItemGroup>
      <_noCopyRefs Include="@(Reference)" Condition="'%(Reference.Private)' == 'false'" />
      <_noCopyRefsByFileName Include="@(_noCopyRefs->'%(FileName)')">
        <OriginalItem>%(Identity)</OriginalItem>
      </_noCopyRefsByFileName>

      <_libByFileName Include="@(ReferenceCopyLocalPaths->'%(FileName)')">
        <OriginalItem>%(Identity)</OriginalItem>
      </_libByFileName>

      <_overlappingRefByFileName Include="@(_noCopyRefsByFileName)" Condition="'@(_noCopyRefsByFileName)' == '@(_libByFileName)' AND '%(Identity)' != ''" />
      <_overlappingLibByFileName Include="@(_libByFileName)" Condition="'@(_noCopyRefsByFileName)' == '@(_libByFileName)' AND '%(Identity)' != ''" />

      <_overlappingRef Include="@(_overlappingRefByFileName->'%(OriginalItem)')" />
      <_overlappingLib Include="@(_overlappingLibByFileName->'%(OriginalItem)')" />
    </ItemGroup>

    <ItemGroup Condition="'@(_overlappingRef)' != ''">
      <Reference Remove="@(_overlappingRef)" />
      <Reference Include="@(_overlappingLib)">
        <Private>false</Private>
      </Reference>
    </ItemGroup>
  </Target>

  <Target Name="RemoveNetFxForceConflicts" AfterTargets="ResolveAssemblyReferences">
    <ItemGroup>
      <ReferencePath Remove="@(ReferencePath)" Condition="'%(FileName)' == 'netfx.force.conflicts'" />
    </ItemGroup>
  </Target>

这篇关于'Npgsql.TypeMapping.GlobalTypeMapper'的类型初始值设定项引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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