Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法加载文件或程序集';Microsoft.SqlServer.Management.RegisteredServers,版本=15.2.0.0,区域性=neutral,PublicKeyToken=89845dcd8080cc91';_C#_Asp.net_.net Assembly - Fatal编程技术网

C# 无法加载文件或程序集';Microsoft.SqlServer.Management.RegisteredServers,版本=15.2.0.0,区域性=neutral,PublicKeyToken=89845dcd8080cc91';

C# 无法加载文件或程序集';Microsoft.SqlServer.Management.RegisteredServers,版本=15.2.0.0,区域性=neutral,PublicKeyToken=89845dcd8080cc91';,c#,asp.net,.net-assembly,C#,Asp.net,.net Assembly,根据我在中的回答,我安装了 Microsoft.SqlServer.SqlManagementObjects Microsoft.SqlServer.Smo System.Security.Cryptography.ProtectedData 它在基于.Net Core 2.0的Console应用程序和基于.Net标准2.0的类库上工作: 现在,我在基于.Net Framework 4.7.1的Web应用程序和基于.Net Standard 2.0的类库的主要C#解决方案中使用了它们:

根据我在中的回答,我安装了

Microsoft.SqlServer.SqlManagementObjects
Microsoft.SqlServer.Smo
System.Security.Cryptography.ProtectedData
它在基于.Net Core 2.0的Console应用程序和基于.Net标准2.0的类库上工作:

现在,我在基于.Net Framework 4.7.1的Web应用程序和基于.Net Standard 2.0的类库的主要C#解决方案中使用了它们:

我得到了这个错误:

Could not load file or assembly 'Microsoft.SqlServer.Management.RegisteredServers, Version=15.2.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
详情如下:

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.SqlServer.Management.RegisteredServers, Version=15.2.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
 (Fully-specified)
LOG: Appbase = file:///C:/Code/Platform/Platform.Web/
LOG: Initial PrivatePath = C:\Code\Platform\Platform.Web\bin
Calling assembly : Application.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\Platform\Platform.Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.SqlServer.Management.RegisteredServers, Version=15.2.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/cd41b801/927eac2d/Microsoft.SqlServer.Management.RegisteredServers.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/cd41b801/927eac2d/Microsoft.SqlServer.Management.RegisteredServers/Microsoft.SqlServer.Management.RegisteredServers.DLL.
LOG: Attempting download of new URL file:///C:/Code/Platform/Platform.Web/bin/Microsoft.SqlServer.Management.RegisteredServers.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
我尝试了不同的解决方案,比如
但它们不起作用

最后,一组解决方案奏效了:

1) 删除
obj
bin
文件夹

2) 更新web.config文件中的引用,然后从NuGet Package Manager控制台运行此命令以添加新绑定:

Get-Project -All | Add-BindingRedirect
3) 正在删除
C:\WINDOWS\Microsoft.NET\Framework\~\ASP.NET临时文件\目录

4) 将
dependentAssembly
添加到web.config:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.SqlServer.Management.RegisteredServers" publicKeyToken="89845dcd8080cc91" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-15.100.0.0" newVersion="15.100.0.0" />
  </dependentAssembly>

它应该与project.cspj相同:

 <Reference Include="Microsoft.SqlServer.Management.RegisteredServers, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.SqlServer.SqlManagementObjects.150.18208.0\lib\net45\Microsoft.SqlServer.Management.RegisteredServers.dll</HintPath>
</Reference>

..\packages\Microsoft.SqlServer.SqlManagementObjects.150.18208.0\lib\net45\Microsoft.SqlServer.Management.registeredserver.dll