最近我开始使用 SSMS 2017 (v17.5)。在我的 MVC 应用程序中,Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.出现错误。我的应用程序中唯一改变的Microsoft.SqlServer.Types是14.0.0.0现在的版本。以前,它是12.0.0.0.
以下是我迄今为止根据我的研究尝试过的不同选项(这包括另stackoverflow一篇文章 + 谷歌),但我遇到了同样的错误。
添加<dependentAssembly>在app.config
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
Global.asax.cs在Application_Start方法中添加以下行。
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
安装Microsoft.SqlServer.Types使用NuGet.
PM> Install-Package Microsoft.SqlServer.Types
10.0.0.0在整个项目中搜索参考,但没有找到任何参考。
我确实Microsoft System CLR Types for SQL Server安装了2012, 2014, 2016和2017。
我在这里缺少什么?
花了将近一天后,我能够解决这个问题。从我上面的问题来看,选项 1 对我有用。唯一的调整是将其添加到web.config而不是app.config. 希望这对其他人有帮助。
代码:web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)