System.IO.FileLoadException ONLY in unit test

851 views
Skip to first unread message

Oskar Berggren

unread,
Jun 26, 2015, 12:31:41 PM6/26/15
to nunit-...@googlegroups.com
Hi,

I have a small program that instantiates a class from a third-party assembly. This program runs to completion with no exceptions thrown.

I also have a unit test assembly that references the above exe-fil, and calls the exact same method that instantiates the class from the third-party assembly. This unfortunately throws:
System.IO.FileLoadException : Could not load file or assembly 'OmnisAPI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cac0dfcb036eae0f' 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. (Exception from HRESULT: 0x80131045)

If the test case directly instantiates the class from the third-party, the same exception is thrown.

To make it clear: The exception loads fine when the program is run, but not when the same code is run under the test runnet.

NUnit 2.6.4, Windows 7 32-bit (and Windows 2012R2 64-bit), net-4.0

Any ideas?

I've created a minimalized test scenario that shows the problem. Because of the third-party DLL I don't want to post it publically, but it can be provided privately to anyone interested.


/Oskar

Greg Young

unread,
Jun 26, 2015, 12:42:12 PM6/26/15
to nunit-...@googlegroups.com
It means it can't find the assembly run fusion it will show you where
its looking. Are you including the 3rd party library?
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunit-discus...@googlegroups.com.
> To post to this group, send email to nunit-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nunit-discuss.
> For more options, visit https://groups.google.com/d/optout.



--
Studying for the Turing test

Oskar Berggren

unread,
Jun 26, 2015, 1:01:51 PM6/26/15
to nunit-...@googlegroups.com
Fusion log indicates that the file is found in the expected location:


*** Assembly Binder Log Entry  (2015-06-26 @ 18:55:06) ***

The operation failed.
Bind result: hr = 0x80131045. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files\NUnit 2.6.4\bin\nunit-agent.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = OmnisAPI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cac0dfcb036eae0f
 (Fully-specified)
LOG: Appbase = file:///C:/Users/oskar.berggren/Documents/Projects/OmnisAPITest/OmnisAPITest/OmnisAPITestCases/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\oskar.berggren\AppData\Local\Temp\nunit20\ShadowCopyCache\4524_635709417000365244
LOG: AppName = Tests_31802718
Calling assembly : OmnisAPITest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: OmnisAPI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cac0dfcb036eae0f
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/oskar.berggren/Documents/Projects/OmnisAPITest/OmnisAPITest/OmnisAPITestCases/bin/Debug/OmnisAPI.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\oskar.berggren\Documents\Projects\OmnisAPITest\OmnisAPITest\OmnisAPITestCases\bin\Debug\OmnisAPI.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: OmnisAPI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cac0dfcb036eae0f
ERR: Setup failed with hr = 0x80131045.
ERR: Failed to complete setup of assembly (hr = 0x80131045). Probing terminated.



Directory tree (obj omitted for brevity):

Folder PATH listing
Volume serial number is 680B-0A20
C:.
|   nunit.framework.dll
|   nunit.framework.xml
|   OmnisAPI.DLL
|
\---OmnisAPITest
    |   OmnisAPITest.sln
    |   OmnisAPITest.sln.DotSettings.user
    |
    +---OmnisAPITest
    |   |   app.config
    |   |   OmnisAPITest.csproj
    |   |   Program.cs
    |   |
    |   +---bin
    |   |   \---Debug
    |   |           OmnisAPI.DLL
    |   |           OmnisAPITest.exe
    |   |           OmnisAPITest.exe.config
    |   |           OmnisAPITest.pdb
    |   |           OmnisAPITest.vshost.exe
    |   |           OmnisAPITest.vshost.exe.config
    |   |           OmnisAPITest.vshost.exe.manifest
    |   |
    |   |
    |   \---Properties
    |           AssemblyInfo.cs
    |
    \---OmnisAPITestCases
        |   LoadOmnisApiTests.cs
        |   OmnisAPITestCases.csproj
        |
        +---bin
        |   \---Debug
        |           nunit.framework.dll
        |           nunit.framework.xml
        |           OmnisAPI.DLL
        |           OmnisAPITest.exe
        |           OmnisAPITest.pdb
        |           OmnisAPITestCases.dll
        |           OmnisAPITestCases.dll.VisualState.xml
        |           OmnisAPITestCases.pdb
        |           TestResult.xml
        |
        \---Properties
                AssemblyInfo.cs


/Oskar

Greg Young

unread,
Jun 26, 2015, 1:05:11 PM6/26/15
to nunit-...@googlegroups.com
LOG: Entering download cache setup phase.
LOG: Assembly Name is: OmnisAPI, Version=2.1.0.0, Culture=neutral,
PublicKeyToken=cac0dfcb036eae0f
ERR: Setup failed with hr = 0x80131045.
ERR: Failed to complete setup of assembly (hr = 0x80131045). Probing terminated

Is the failure. But this is standard .net stuff nothing to do with
nunit. A quick pop of the error into google brought up about 5
possible issues it could be.

On Fri, Jun 26, 2015 at 7:01 PM, Oskar Berggren

Oskar Berggren

unread,
Jun 26, 2015, 1:14:38 PM6/26/15
to nunit-...@googlegroups.com
Yeah, I've googled it too, but all I got were people having weird issues that was solved by reinstalling, or installting in GAC, or removing from GAC, or mucking about with file permissions deep under %windir%. In particular, no one seemed to claim that the same file worked in one program, but not in another.

However, sn -vf on my own test assembly says (as expected):
"...OmnisAPITest.exe does not represent a strongly named assembly"

While on OmnisAPI.dll it says:
Failed to verify assembly -- Strong name validation failed for assembly '...\OmnisAPI.DLL'.

So I suppose there really is something strange going on with the assembly that the provider needs to fix. I still don't understand why this problem only shows when running under nunit, not when the program is executed on its own. Do you know why this difference?

/Oskar


Marius Goppelt

unread,
Jun 30, 2015, 6:50:55 AM6/30/15
to nunit-...@googlegroups.com
 
The application may have a configuration (*.config) embedded, that allows her to rebind assemblies to specific versions.
 
But you should avoid such evil witchcraft. Bindings like that may actually break the application as soon as you update its dependency.

Greg Young

unread,
Jun 30, 2015, 8:59:57 AM6/30/15
to nunit-...@googlegroups.com
It can also be different versions for other reasons that get bound in
the app vs in tests (try fusion on both)
Reply all
Reply to author
Forward
0 new messages