Got an error when trying to Protect .NETStandard 2.0 library.
[ERROR] Failed to resolve dependency of 'My.dll'.
Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
at dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, IAssembly assembly, ModuleDef sourceModule) in C:\projects\modphuserex\dnlib\src\DotNet\IAssemblyResolver.cs:line 113
at Confuser.Core.ConfuserEngine.Inspection(ConfuserContext context) in C:\projects\modphuserex\Confuser.Core\ConfuserEngine.cs:line 264
I'm caught in a dilemma:
To use Obfuscation attribute we need .NET Standard 2.0. It is not supported in .NET Stardard 1.6 or earlier. But when my project upgraded to .NET Standard 2.0, we will not be able to protect my dlls with ModPhuserEx.
I'm trying to build ModPhuserEx on .NET Standard 2.0 and hope it can be done.
.NET Portability Analyzer analysis result:
System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName,System.Reflection.Emit.AssemblyBuilderAccess)
Not supported on .NET Core,Version=v2.0; .NET Standard,Version=v2.0
Suggestion: Remove usage. dnlib W:\VS2017\_Experiment\ModPhuserEx\dnlib\src\DotNet\Emit\MethodTableToTypeConverter.cs 33
System.Reflection.Emit.TypeBuilder.CreateType
Not supported on .NET Standard,Version=v2.0 dnlib W:\VS2017\_Experiment\ModPhuserEx\dnlib\src\DotNet\Emit\MethodTableToTypeConverter.cs 85
System.Reflection.Emit.TypeBuilder.CreateType
Not supported on .NET Standard,Version=v2.0 dnlib W:\VS2017\_Experiment\ModPhuserEx\dnlib\src\DotNet\Emit\MethodTableToTypeConverter.cs 104
System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Module)
Not supported on .NET Standard,Version=v2.0 dnlib W:\VS2017\_Experiment\ModPhuserEx\dnlib\src\DotNet\ModuleDefMD.cs 264
Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive,System.String)
Not supported on .NET Standard,Version=v2.0 Confuser.Core W:\VS2017\_Experiment\ModPhuserEx\Confuser.Core\ConfuserEngine.cs 465
Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive,System.String)
Not supported on .NET Standard,Version=v2.0 Confuser.Core W:\VS2017\_Experiment\ModPhuserEx\Confuser.Core\ConfuserEngine.cs 497
System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Module)
Not supported on .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\AntiDump.cs 13
System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Module)
Not supported on .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\AntiTamper.JIT.cs 22
System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Module)
Not supported on .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\AntiTamper.Normal.cs 14
System.Reflection.Emit.DynamicMethod.GetDynamicILInfo
Not supported on .NET Core,Version=v2.0; .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\RefProxy.Strong.cs 55
System.Reflection.Emit.DynamicILInfo.SetLocalSignature(System.Byte[])
Not supported on .NET Core,Version=v2.0; .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\RefProxy.Strong.cs 56
System.Reflection.Emit.DynamicILInfo.GetTokenFor(System.RuntimeTypeHandle)
Not supported on .NET Core,Version=v2.0; .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\RefProxy.Strong.cs 67
System.Reflection.Emit.DynamicILInfo.GetTokenFor(System.RuntimeMethodHandle)
Not supported on .NET Core,Version=v2.0; .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\RefProxy.Strong.cs 79
System.Reflection.Emit.DynamicILInfo.SetCode(System.Byte[],System.Int32)
Not supported on .NET Core,Version=v2.0; .NET Standard,Version=v2.0 Confuser.Runtime W:\VS2017\_Experiment\ModPhuserEx\Confuser.Runtime\RefProxy.Strong.cs 85
Just a clarification: MPX/ConfuserEx run on. NET Framework/Mono. They never themselves ran on .NET Core or were .NET Standard-compatiable; this is mainly due to dnlib choosing to stay on .NETFx. However the project does support .NET standard/core libraries.
I'll take a closer look later; for now could you please confirm that you set probe paths like described in the wiki? Thanks.
Yes. I have confirmed that. See https://github.com/0xFireball/ModPhuserEx/issues/3#issuecomment-324321458 .
BTW, I found a possibly related post on SO: 'Could not load file or assembly 'netstandard, Version=2.0.0.0, …'. Reference assemblies should not be loaded for execution.
After adding some more probePath to the project file, the original Could not resolve assembly: netstandard error is gone.
<probePath>W:\VS2017\MyApp\bin\Release\PublishOutput</probePath>
<probePath>W:\VS2017\MyApp\bin\Release\PublishOutput\runtimes\win\lib\netcoreapp2.0</probePath>
<probePath>C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\tools\net46</probePath>
<probePath>C:\Program Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\net461\lib</probePath>
But new errors occurred:
[ERROR] Failed to resolve a type, check if all dependencies are present in the correct version.
Exception: dnlib.DotNet.TypeResolveException: Could not resolve type: System.ValueTuple`2 (System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at dnlib.DotNet.TypeRef.ResolveThrow(ModuleDef sourceModule) in C:\projects\modphuserex\dnlib\src\DotNet\TypeRef.cs:line 333
at dnlib.DotNet.Extensions.ResolveTypeDefThrow(ITypeDefOrRef tdr) in C:\projects\modphuserex\dnlib\src\DotNet\ICodedToken.cs:line 490
at Confuser.Renamer.Analyzers.InterReferenceAnalyzer.ProcessMemberRef(ConfuserContext context, INameService service, ModuleDefMD module, IMemberRef r) in C:\projects\modphuserex\Confuser.Renamer\Analyzers\InterReferenceAnalyzer.cs:line 60
at Confuser.Renamer.Analyzers.InterReferenceAnalyzer.Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def) in C:\projects\modphuserex\Confuser.Renamer\Analyzers\InterReferenceAnalyzer.cs:line 26
at Confuser.Renamer.AnalyzePhase.Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, IDnlibDef def, Boolean runAnalyzer) in C:\projects\modphuserex\Confuser.Renamer\AnalyzePhase.cs:line 179
at Confuser.Renamer.AnalyzePhase.Execute(ConfuserContext context, ProtectionParameters parameters) in C:\projects\modphuserex\Confuser.Renamer\AnalyzePhase.cs:line 67
at Confuser.Core.ProtectionPipeline.ExecuteStage(PipelineStage stage, Action`1 func, Func`1 targets, ConfuserContext context) in C:\projects\modphuserex\Confuser.Core\ProtectionPipeline.cs:line 139
at Confuser.Core.ConfuserEngine.RunPipeline(ProtectionPipeline pipeline, ConfuserContext context) in C:\projects\modphuserex\Confuser.Core\ConfuserEngine.cs:line 221
at Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token) in C:\projects\modphuserex\Confuser.Core\ConfuserEngine.cs:line 175
I think this is specific to my project and still trying to find a solution.
@zwcloud have you eventually resolved this problem?
@zwcloud have you eventually resolved this problem?
No, I gave up. I was just trying ModPhuserEx.