Assembly.Load fails within a test case (strong naming validation also fails)... why?

187 views Asked by At

I've been setting up some test cases, and part of that was wanting to make sure I could run some EntityFramework tests.

I'm having trouble loading the driver (Npgsql in this case). I can load it in the app, but not the test case.

I've put together a trivial project showing the problem. https://github.com/scornflake/StrongNameNightmare

a) Loading the assembly works from the app b) The same Assembly.Load, in a test case, fails with (Could not load file or assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=2.0.2.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key.)

The SHA1 of the two files (the one in packages\ and the one that is copied to the assembly output folder) are identical:

  • SHA1 hash of packages\Npgsql.EntityFrameworkCore.PostgreSQL.2.0.2\lib\netstandard2.0\Npgsql.EntityFrameworkCore.PostgreSQL.dll: 29261f08a466e3b5c24ff8d1aa1810b29c3ff8a5
  • SHA1 hash of Tests\bin\Debug\Npgsql.EntityFrameworkCore.PostgreSQL.dll: 29261f08a466e3b5c24ff8d1aa1810b29c3ff8a5

A 'sn -v' of packages\Npgsql.EntityFrameworkCore.PostgreSQL.2.0.2\lib\netstandard2.0\Npgsql.EntityFrameworkCore.PostgreSQL.dll works.

a 'sn -v' of Tests\bin\Debug\Npgsql.EntityFrameworkCore.PostgreSQL.dll fails

Failed to verify assembly -- Strong name validation failed.

I'm presuming that the failure to verify the strong name of the 'tests' version of the Npgsql driver is the root cause of the failure to load the assembly in the test.

I've tried disabling strong name validation (sn -Vr *,*), with no effect.

I'm at a bit of a loss here. I'm no expert in VS/Assemblies, perhaps someone can shed light on why an assembly would not pass strong name verification in a different folder? Seems very odd to me.

1

There are 1 answers

0
scornflake On BEST ANSWER

I never did find the root cause, but switching from xUnit to NUnit solves the .Load failure. So, I guess I'll just go with NUnit!