yck1509 / ConfuserEx

An open-source, free protector for .NET applications
http://yck1509.github.io/ConfuserEx/
Other
3.56k stars 1.61k forks source link

"Failed to resolve a type" with generic types and XAML #93

Closed bignoncedric closed 9 years ago

bignoncedric commented 9 years ago

The type resolution fails with generic types properties used in XAML.

For example:

class MyGenericClass<T>
{
    T Value { get; set; }
}
class MyDerivedClass : MyGenericClass<int>
{
}

And used in XAML:

<MyDerivedClass Value="15" />

Resolution of attribute Value will fail because the BAML analyzer tries to guess the returned type of the property Value using the Basic type of it's declaring class which is MyGenericClass'1 (it does not contain the generic argument type).

Here is the exception details:

Failed to resolve a type, check if all dependencies are of correct version.
Exception: dnlib.DotNet.TypeResolveException: Can't resolve a null pointer
   at dnlib.DotNet.Extensions.ResolveTypeDefThrow(ITypeDefOrRef tdr) in d:\Open Source Projects\ConfuserEx\dnlib\src\DotNet\ICodedToken.cs:line 500
   at Confuser.Renamer.BAML.BAMLAnalyzer.AnalyzeAttributeReference(TypeDef declType, AttributeInfoRecord rec) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\BAML\BAMLAnalyzer.cs:line 513
   at Confuser.Renamer.BAML.BAMLAnalyzer.PopulateReferences(BamlDocument document) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\BAML\BAMLAnalyzer.cs:line 149
   at Confuser.Renamer.BAML.BAMLAnalyzer.Analyze(ModuleDefMD module, String bamlName, Byte[] data) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\BAML\BAMLAnalyzer.cs:line 79
   at Confuser.Renamer.Analyzers.WPFAnalyzer.AnalyzeResources(ConfuserContext context, INameService service, ModuleDefMD module) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\Analyzers\WPFAnalyzer.cs:line 234
   at Confuser.Renamer.Analyzers.WPFAnalyzer.Analyze(ConfuserContext context, INameService service, IDnlibDef def) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\Analyzers\WPFAnalyzer.cs:line 33
   at Confuser.Renamer.AnalyzePhase.Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, IDnlibDef def, Boolean runAnalyzer) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\AnalyzePhase.cs:line 77
   at Confuser.Renamer.AnalyzePhase.Execute(ConfuserContext context, ProtectionParameters parameters) in d:\Open Source Projects\ConfuserEx\Confuser.Renamer\AnalyzePhase.cs:line 54
   at Confuser.Core.ProtectionPipeline.ExecuteStage(PipelineStage stage, Action`1 func, Func`1 targets, ConfuserContext context) in d:\Open Source Projects\ConfuserEx\Confuser.Core\ProtectionPipeline.cs:line 141
   at Confuser.Core.ConfuserEngine.RunPipeline(ProtectionPipeline pipeline, ConfuserContext context) in d:\Open Source Projects\ConfuserEx\Confuser.Core\ConfuserEngine.cs:line 206
   at Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token) in d:\Open Source Projects\ConfuserEx\Confuser.Core\ConfuserEngine.cs:line 160
yck1509 commented 9 years ago

Related to #82

yck1509 commented 9 years ago

Fix by 357873b866b004d8f9dd8ef5cac1f0b32d2bee05