3

My situation: I have a .Net 4.7.2 WinForms application. It references a project that is a .Net Standard class library The .Net Standard library references the Microsoft.SqlServer.SqlManagementObjects NuGet package using a PackageReference

When I build the winforms application, it is pulling in the Microsoft.SqlServer.SqlManagementObjects package from the net462 lib folder instead of the netstandard2.0 folder. This is a problem because the .Net Standard version of the library has different classes (e.g. it uses Microsoft.Data.SqlConnection instead of System.Data.SqlConnection). So when the application is run you get an error saying System.MissingMethodException: Method not found: 'Void Microsoft.SqlServer.Management.Common.ServerConnection..ctor(Microsoft.Data.SqlClient.SqlConnection)'

Is there any way around this? I feel like the SMO libraries should have been separated into different packages for .Net Standard and .Net Framework if they have differences like this.

MadSkeletor
  • 161
  • 1
  • 14

1 Answers1

0

I believe the official position is that this is library authoring issue, so there isn't a good way to do what you want.

There is a heinous hack detailed here though, which is something like:

<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" ExcludeAssets="Compile" GeneratePathProperty="true">
    <Version>1.2.3</Version> 
</PackageReference>
<Reference Include="Microsoft.SqlServer.SqlManagementObjects">
    <HintPath>$(PkgMicrosoft_SqlServer_SqlManagementObjects)lib\netstandard2.0\Microsoft.SqlServer.SqlManagementObjects.dll</HintPath> 
</Reference>
rbennett485
  • 1,907
  • 15
  • 24
  • I'll flag your answer as correct, it looks similar to what they replied to in the issue I submitted to the github project: https://github.com/microsoft/sqlmanagementobjects/issues/10. I ended up just splitting out my SMO calls into a separate .Net Framework library since I wasn't using it for much and refactoring my code a little bit since I thought in my case that was simpler. – MadSkeletor May 14 '20 at 21:18