2017-06-05 64 views
1

我開發了一個.NET Core應用程序。 該解決方案由庫和控制檯應用程序netcoreapp1.1中的netstandard1.6組成。 這兩個項目都使用SqlClient。 如果我在Windows上發佈並運行,那麼一切都會運行良好。 如果我在Linux上運行,那麼應用程序崩潰並出現錯誤:在.NET Core中使用SqlClient時,爲什麼System.Runtime.InteropServices程序集中會出現System.IO.FileLoadException異常?

Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.AggregateException: One or more errors occurred. (The type initializer for 'System.Runtime.Versioning.BinaryCompatibility' threw an exception.) ---> System.TypeInitializationException: The type initializer for 'System.Runtime.Versioning.BinaryCompatibility' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.InteropServices, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

PS:其實,服務器可用,您可以從您剛剛在Linux上創建的應用程序連接到它。

dotnet --info 
Product Information: 
Version:   1.0.4 
Commit SHA-1 hash: af1e6684fd 

Runtime Environment: 
OS Name:  ubuntu 
OS Version: 16.04 
OS Platform: Linux 
RID:   ubuntu.16.04-x64 
Base Path: /usr/share/dotnet/sdk/1.0.4 
+0

是否包含在該項目中的金塊或你正在閱讀它的形式global-packages? –

+1

請檢查https://stackoverflow.com/questions/43363713/entity-framework-core-exception-system-runtime-versioning-binarycompatibility是否已幫助解決此問題。 –

+0

@HansPassant 1.0.4工具是當前工具版本,支持.net核心1.1 –

回答

1

最有可能你缺少dependcies

這裏的一個是我的片斷:

apt-get update \ 
&& apt-get install -y --no-install-recommends \ 
    libc6 \ 
    libcurl3 \ 
    libgcc1 \ 
    libgssapi-krb5-2 \ 
    libicu52 \ 
    liblttng-ust0 \ 
    libgdiplus \ 
    libssl1.0.0 \ 
    libstdc++6 \ 
    libunwind8 \ 
    libuuid1 \ 
    zlib1g \ 

如果不是指this

+0

謝謝!鏈接+1 –

+0

@MartinUllrich如何從Visual Studio 2017中排除此設置而不編輯csproj文件? –

相關問題