NUnit console runner fails to load assemblies

Bug #595683 reported by Christian Horsdal
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
Fix Released
Medium
Charlie Poole
NUnit V2
Fix Released
Medium
Charlie Poole

Bug Description

I am using NUnit 2.9.4 which I have downloaded as source and compiled with VS2010 RC.
I had trouble loading my test assemblies running the test-runner.exe gives the following output:

----------------------------------------------------------------------------------------------------------------------

PS C:\projects\Specs\Specs.Test\bin\Debug> ..\..\..\..\NUnit\NUnit-2.9.4\solutions\vs2010\bin\Debug\test-runner.exe .\Specs.Test.dll
TestRunner version 1.0.0
Copyright c 2009 Charlie Poole

Runtime Environment -
    OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3
  .NET Version: 4.0.30128.1

Options -
    Use Same AppDomain

Could not load file or assembly 'Specs.Test' or one of its dependencies. The system cannot find the file specified.
PS C:\projects\Specs\Specs.Test\bin\Debug>

----------------------------------------------------------------------------------------------------------------------------

If I change the method Load on the class DefaultTestAssemblyBuilder in the file NUnit-2.9.4\src\framework\Internal\DefaultTestAssemblyBuilder.cs from

        private Assembly Load(string path)
        {
            Assembly assembly = null;

            // Throws if this isn't a managed assembly or if it was built
            // with a later version of the same assembly.
            AssemblyName assemblyName = AssemblyName.GetAssemblyName(Path.GetFileName(path));

            // TODO: Figure out why we can't load using the assembly name
            // in all cases. Might be a problem with the tests themselves.
            assembly = Assembly.Load(Path.GetFileNameWithoutExtension(path));

            if (assembly != null)
                CoreExtensions.Host.InstallAdhocExtensions(assembly);

            InternalTrace.Info("Loaded assembly " + assembly.FullName);

            return assembly;
        }

to

        private Assembly Load(string path)
        {
            Assembly assembly = null;

            // Throws if this isn't a managed assembly or if it was built
            // with a later version of the same assembly.
            AssemblyName assemblyName = AssemblyName.GetAssemblyName(Path.GetFileName(path));

            // TODO: Figure out why we can't load using the assembly name
            // in all cases. Might be a problem with the tests themselves.
            assembly = Assembly.Load(assemblyName);

            if (assembly != null)
                CoreExtensions.Host.InstallAdhocExtensions(assembly);

            InternalTrace.Info("Loaded assembly " + assembly.FullName);

            return assembly;
        }

I can load my assemblies. -The difference in the code is that the Assembly.Load call takes the AssemblyName instead of the path.
With the code change the test-runner output is:

PS C:\projects\Specs\Specs.Test\bin\Debug> ..\..\..\..\NUnit\NUnit-2.9.4\solutions\vs2010\bin\Debug\test-runner.exe .\Specs.Test.dll
TestRunner version 1.0.0
Copyright c 2009 Charlie Poole

Runtime Environment -
    OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3
  .NET Version: 4.0.30128.1

Options -
    Use Same AppDomain

   Tests run: 6, Errors: 0, Failures: 0, Inconclusive: 0
     Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
        Time: 0,031 seconds

PS C:\projects\Specs\Specs.Test\bin\Debug>

Related branches

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 595683] [NEW] NUnit console runner fails to load assemblies
Download full text (4.0 KiB)

This is a valid bug - thanks for reporting it. Just one note for your
information, however...
test-runner.exe is _not_ the new nunit-console runner. It's merely a program
used to test
the framework itself. There will be a new nunit-console runner for NUnit
3.0... it's just
not out there yet.

Charlie

On Thu, Jun 17, 2010 at 2:00 PM, Christian Horsdal <email address hidden>wrote:

> Public bug reported:
>
> I am using NUnit 2.9.4 which I have downloaded as source and compiled with
> VS2010 RC.
> I had trouble loading my test assemblies running the test-runner.exe gives
> the following output:
>
>
> ----------------------------------------------------------------------------------------------------------------------
>
> PS C:\projects\Specs\Specs.Test\bin\Debug>
> ..\..\..\..\NUnit\NUnit-2.9.4\solutions\vs2010\bin\Debug\test-runner.exe
> .\Specs.Test.dll
> TestRunner version 1.0.0
> Copyright c 2009 Charlie Poole
>
> Runtime Environment -
> OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3
> .NET Version: 4.0.30128.1
>
> Options -
> Use Same AppDomain
>
> Could not load file or assembly 'Specs.Test' or one of its dependencies.
> The system cannot find the file specified.
> PS C:\projects\Specs\Specs.Test\bin\Debug>
>
>
> ----------------------------------------------------------------------------------------------------------------------------
>
> If I change the method Load on the class DefaultTestAssemblyBuilder in
> the file
> NUnit-2.9.4\src\framework\Internal\DefaultTestAssemblyBuilder.cs from
>
>
> private Assembly Load(string path)
> {
> Assembly assembly = null;
>
> // Throws if this isn't a managed assembly or if it was built
> // with a later version of the same assembly.
> AssemblyName assemblyName =
> AssemblyName.GetAssemblyName(Path.GetFileName(path));
>
> // TODO: Figure out why we can't load using the assembly name
> // in all cases. Might be a problem with the tests themselves.
> assembly =
> Assembly.Load(Path.GetFileNameWithoutExtension(path));
>
> if (assembly != null)
> CoreExtensions.Host.InstallAdhocExtensions(assembly);
>
> InternalTrace.Info("Loaded assembly " + assembly.FullName);
>
> return assembly;
> }
>
>
> to
>
>
> private Assembly Load(string path)
> {
> Assembly assembly = null;
>
> // Throws if this isn't a managed assembly or if it was built
> // with a later version of the same assembly.
> AssemblyName assemblyName =
> AssemblyName.GetAssemblyName(Path.GetFileName(path));
>
> // TODO: Figure out why we can't load using the assembly name
> // in all cases. Might be a problem with the tests themselves.
> assembly = Assembly.Load(assemblyName);
>
> if (assembly != null)
> CoreExtensions.Host.InstallAdhocExtensions(assembly);
>
> InternalTrace.Info("Loaded assembly " + assembly.FullName);
>
> return assembly;
> }
>
>
> I can load my assemblies. -The difference in the code is that the
> Assembly.Load call takes t...

Read more...

Revision history for this message
Charlie Poole (charlie.poole) wrote :

The change you have made is actually what the TODO comment is talking about. At some past time, loading by AssemblyName rather than by the string name of the file caused failures. Whatever the cause was, it seems to be gone now. I'm able to change this code in both 2.5 and 3.0 and everything works OK.

So I understand this better, what's different about your assembly name - i.e. is there a key, a non-default culture, etc?

Changed in nunitv2:
status: New → Triaged
Changed in nunit-3.0:
status: New → Triaged
Changed in nunitv2:
importance: Undecided → Medium
Changed in nunit-3.0:
importance: Undecided → Medium
assignee: nobody → Charlie Poole (charlie.poole)
Changed in nunitv2:
assignee: nobody → Charlie Poole (charlie.poole)
Changed in nunit-3.0:
milestone: none → 2.9.5
Changed in nunit-3.0:
status: Triaged → Fix Committed
Changed in nunitv2:
status: Triaged → Fix Committed
milestone: none → 2.5.7
Changed in nunit-3.0:
status: Fix Committed → Fix Released
Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.