1

Closed

NUnit fails to load obfuscated dll

description

Hi

I've been experimenting with Obfuscar and to be safe I want to run my unit tests first, then obfuscate and rerun the tests to ensure nothing has broken. However after obfuscation of the library being tested I cannot get the dll containing the test code to load in NUnit - it throws a FileNotFound exception for the test code dll, even though I've just selected it, and it can be loaded by ILSpy.

I've created and attached an example which replicates the problem. There are two dlls, the first contains the code I want obfuscating, in this case MyClass with a single static property Value that returns a string. The second dll contains the NUnit test which simply checks the string is what it is expecting.

My Obfuscar configuration is set to obfuscate the first dll, and to ignore the namespace used in the test dll. The configuration file is at packages/Obfuscar.2.0.0.0/tools/test.xml and the obfuscated output written to the Output folder at that location.

If I load the test dll in ILSpy I can see that it has adjusted the call to the obfuscated class as A.A() instead of MyClass.Value, but otherwise appears untouched.

This is using the version of NUint (2.6.3) and Obfuscar (2.0.0) from nuget. You'll need the NUnit binaries from http://nunit.org/index.php?p=download

Thanks
Darren

file attachments

Closed Jun 1 at 3:45 AM by lextm

comments

lextm wrote Jun 1 at 3:45 AM

I cannot reproduce your case.

Note that in the package you attached, we can see that in Mapping.txt that only ObfuscarTest.MyClass was touched.
Renamed Types:

[ObfuscarTest]ObfuscarTest.MyClass -> [ObfuscarTest]A.A
{
    [ObfuscarTest]ObfuscarTest.MyClass::get_Value[0]( ) -> A

    [ObfuscarTest]ObfuscarTest.MyClass::.ctor[0]( ) skipped:  special name

    System.String [ObfuscarTest]System.String ObfuscarTest.MyClass::Value -> dropped
}

Skipped Types:

Renamed Resources:


Skipped Resources:
However, on my machine I got
Renamed Types:

[ObfuscarTest]ObfuscarTest.MyClass -> [ObfuscarTest]A.A
{
    [ObfuscarTest]ObfuscarTest.MyClass::get_Value[0]( ) -> A

    [ObfuscarTest]ObfuscarTest.MyClass::.ctor[0]( ) skipped:  special name

    System.String [ObfuscarTest]System.String ObfuscarTest.MyClass::Value -> dropped
}

Skipped Types:

[ObfuscarTest.Tests]ObfuscarTest.Tests.TestClass skipped:  namespace rule in configuration
{

    [ObfuscarTest.Tests]ObfuscarTest.Tests.TestClass::GetStaticPropertyValue[0]( ) skipped:  type rule in configuration
    [ObfuscarTest.Tests]ObfuscarTest.Tests.TestClass::.ctor[0]( ) skipped:  special name
}

Renamed Resources:


Skipped Resources:
I can only guess that on your machine for some other reason ObfuscarTest.Tests.dll was never processed, and that's why it still refers to the unobfuscated method name.

robertsdj wrote Jun 1 at 3:40 PM

It was processed, like I said if you opened ObfuscarTest.Tests.dll after it has been processed by Obfuscar in ILSpy you can see the call to MyClass.Value has been changed to A.A(), so I'm not sure about that mapping.txt file.

Rebuilding and testing the project now I get exactly the same output in mapping.txt that you've listed, but the dll is still unable to be loaded in NUnit.

Were you able to open your compiled ObfuscarTest.Tests.dll in NUnit 2.6.3 as part of your testing?