1

Based on my answer in Unable to create RegisteredServer in Microsoft.SqlServer.Management.RegisteredServers, I installed

Microsoft.SqlServer.SqlManagementObjects
Microsoft.SqlServer.Smo
System.Security.Cryptography.ProtectedData

It worked on Consol Application based on .Net Core 2.0 and ClassLibrary based on .Net Standard 2.0:

enter image description here enter image description here

Now I use them in my main C# Solution with Web Application based on .Net Framework 4.7.1 and Class Library based on .Net Standard 2.0:

enter image description here enter image description here

I got this error:

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)

This is the detail:

=== 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.

I tried different solution like The located assembly's manifest definition does not match the assembly reference but they did not work

1 Answer 1

1

Finally, a combination of solutions worked:

1) Delete the obj and bin folders

2) Update the references from web.config file, and then run this command from the NuGet Package Manager console in order to add new bindings:

Get-Project -All | Add-BindingRedirect

3) Deleting C:\WINDOWS\Microsoft.NET\Framework\~\Temporary ASP.NET Files\ directory

4) Adding dependentAssembly to 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>

It should be the same as 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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.