Open Anthony-GitHub opened 3 years ago
To get .NET Core 1.x and 2.x as well as .NET Standard <= 2.0 working properly, you need to add the dependency explicitly as external module. This way it will resolve the file properly.
So you add
<module path="\Libs\CoreCLR\SDK\2.0.0\shared\Microsoft.NETCore.App\2.0.0-preview2-25407-01\netstandard.dll" external="true" />
to the project. This will force ConfuserEx 1.5 to use the file (1.4.1 will not work).
Thanks. I tried to add the dependency explicitly as an external module but it makes no difference. It still crashes with NullReferenceException. I also tried to add all the .NET Standard dlls as an external module, still not work.
The NullReferenceException
is hiding the real error. Any chance you could attach the debugger to the Confuser while running and tell me, what exactly triggers this exception in this function?
I'm guessing it's triggered here because there is some assembly without managed module.
Yes, the NullReferenceException is triggered here. The variable asm
is null.
The first Exception is triggered in VTable.cs:
dnlib.DotNet.TypeResolveException
HResult=0x80131500
Message=Could not resolve type: System.ICloneable (netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
Source=dnlib
StackTrace:
at dnlib.DotNet.TypeRef.ResolveThrow(ModuleDef sourceModule)
at Confuser.Renamer.VTableStorage.GetVTable(ITypeDefOrRef type) in C:\test\ConfuserEx-master\Confuser.Renamer\VTable.cs:line 372
Okay, so I can't reproduce the issue in my system, because it always falls back to the .NET Framework version of the system. And that is the same thing that should happen in your case, unless you don't have the .NET Framework installed.
What exactly is the setup on your system?
I just install a Windows 7 SP1 in VM, and then install .NET Framework 4.6.1, then it can reproduce this issue.
Let me know if you still cannot reproduce this issue. I can share the credential by Email so you can remote login. Or I can upload this VM that may take some time.
There was actually still an error in ConfuserEx, that caused my suggested fix from before to fail. The fix suggested here should not work with the ConfuserEx 1.5 Release.
Please let me know if that resolves the problem.
The NullReferenceException is still there with the ConfuserEx 1.5 Release.. The error message is the same as before.
Try uninstalling .NET 4.6.1. For whatever reason .NET 4.6.1 breaks serval obfuscators that have been build with .NET 4.0. Install .NET 4.8 instead. Maybe that helps.
This issue only occurred on a machine that does not install the .NET Standard runtime. My build machine is Windows 7 and the .NET Standard runtime cannot be installed for some reasons. So I use the
/probe
parameter to provide the dll search path for .NET Standard.The NullReferenceException will occur when there is a class with the
ICloneable
interface.confuserex.crproj:
command:
The output:
Here is the demo project to reproduce: ConfuserExNullReferenceException.zip
This project does not include the dll for .NETCore due to the upload size limitation. For the full project, please download from: https://drive.google.com/file/d/1zIFdeA2T17597i5BQhWdkKO0JZ8bldPD/view?usp=sharing
I finally make it work by disabling the GAC: https://github.com/Anthony-GitHub/ConfuserEx/commit/7b6cc07bc537d489b861668cc9c0d188d97c3323
Is that possible to add a parameter to disable/enable the GAC? Or do you have any other ideas?
Thanks