Olivarsham
Olivarsham

Reputation: 1731

C# smo project assembly not referenced error

I am doing a C# project which is using smo objects(Server,Database).
I included

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Server;  

I have added Microsoft.SqlServer.Management.Smo,Microsoft.SqlServer.Management.SmoExtended,Microsoft.SqlServer.SqlEnum,Microsoft.SqlServer.ConnectionInfo.

But still i am getting the errors like this(10 errors similar to this):

The type 'Microsoft.SqlServer.Management.Sdk.Sfc.ISfcHasConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'.  

how to resolve this??

Upvotes: 1

Views: 4002

Answers (2)

Julio Trindade
Julio Trindade

Reputation: 1

I don't know if your problem still happen, but in my case, the problem was an Assembly binding redirect in App.Config:

<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Management.Sdk.Sfc" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-15.100.0.0" newVersion="15.100.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.ConnectionInfo" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-15.100.0.0" newVersion="15.100.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Diagnostics.STrace" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-15.100.0.0" newVersion="15.100.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Smo" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-15.100.0.0" newVersion="15.100.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

I don't know exactly when Visual Studio put it here, but, when I remove, it works.

=)

Upvotes: 0

Justin Pihony
Justin Pihony

Reputation: 67075

Well, I think the error is fairly explanatory, include a reference to Microsoft.SqlServer.Management.Sdk.Sfc. You have not listed that you added that reference. Sometimes when you add references that use other dll reference's that were not included, then you have to include those other references...even if you are not using them.

Upvotes: 7

Related Questions