Build/Test Issues

System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll'

Started by pgpacc on 279 views

I very often get this error when running NCrunch:


Exception occurred while testing (unknown migration)
System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.Data.SqlClient.SNINativeManagedWrapperX86.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
at Microsoft.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)


The easiest fix is to add

    <CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace>


However, now I get a bunch of warnings

The 'Copy Referenced Assemblies To Workspace' configuration setting for this component has been switched on.


Is there a way to either make it copy the dll without enabling CopyReferencedAssembliesToWorkspace,
or to suppress the "Copy Referenced Assemblies To Workspace" globally, so I don't have to do it for each project.
Hi, thanks for sharing this issue.

The answer to this depends heavily on the nature of your dependency on this binary. It may be enough to simply reference it directly from your test project, as this way NCrunch will have the dependency details for it and the assembly resolution should work better.

How are you referencing this binary? Is it an unmanaged dependency of a different DLL you are using?
I have a reference to FuentMigrator.Runner


    <PackageReference Include="FluentMigrator.Runner" Version="7.0.0" />


And from what I can see, that has a reference to FluentMigrator.Runner.SqlServer -> Microsoft.Data.SqlClient -> Microsoft.Data.SqlClient.SNI

I'm not a big fan of having to include it directly in my test project, as I have 70+, and if FluentMigrator then decides to update, then I'll have to keep all my test projects in sync.
One way or another, this assembly needs to be accessible at runtime.

Turning on 'Copy referenced assemblies to workspace' sets NCrunch in a compatibility mode so that runtime references get copied to the output directory, so that assembly referencing can work using the runtime's natural system.

It's usually possible to work without this setting, but that means either:
1. Ensuring that NCrunch has the correct information about the dependency by referencing it in your project
or
2. Copying the file into the runtime directory yourself using your own code inside your test run, or a custom build step

If the above options aren't suitable, then 'Copy referenced assemblies to workspace' is probably the right option for you. If you enable the advanced configuration mode in the NCrunch configuration window, you can enable this setting globally or for the entire solution, and the projects will just inherit it. The system will still warn you about it, but you can multi-select the warnings and choose to ignore them.

Post a reply

Log in to reply.