Skip to content

Erroneous and unused assembly referred to in XAML xmlns causes ConfuserEx to crash #536

@DavidHollman

Description

@DavidHollman

I had a C# DLL with a WPF XAML file that had a line like the following:

<ResourceDictionary
      ...
      xmlns:SomeNamespace="clr-namespace:SomeNamespace;assembly=Bogus"
      ...
>

The problem was that the Bogus assembly did not exist - however this xmlns was not actually used in XAML and so the file still compiled OK in Visual Studio. (If it had been in use I believe VS would have flagged an error.) Because of that, it slips through to obfuscation later on.

Apparently when ConfuserEx finds the nonsense reference to Bogus it tries to load bogus.dll which it cannot find. This leads to a crash:

[ERROR] Failed to resolve an assembly, check if all dependencies are present in the correct version.
Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Bogus
   at dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, String asmFullName, ModuleDef sourceModule)
   at Confuser.Renamer.BAML.BAMLAnalyzer.PopulateReferences(BamlDocument document)
   at Confuser.Renamer.BAML.BAMLAnalyzer.Analyze(ModuleDefMD module, String bamlName, Byte[] data)
   at Confuser.Renamer.Analyzers.WPFAnalyzer.AnalyzeResources(ConfuserContext context, INameService service, ModuleDefMD module)
   at Confuser.Renamer.Analyzers.WPFAnalyzer.Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
   at Confuser.Renamer.AnalyzePhase.Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, IDnlibDef def, Boolean runAnalyzer)
   at Confuser.Renamer.AnalyzePhase.Execute(ConfuserContext context, ProtectionParameters parameters)
   at Confuser.Core.ProtectionPipeline.ExecuteStage(PipelineStage stage, Action`1 func, Func`1 targets, ConfuserContext context)
   at Confuser.Core.ConfuserEngine.RunPipeline(ProtectionPipeline pipeline, ConfuserContext context)
   at Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token)

Although the crash itself might be considered a bug, the root problem is bad XAML. So ideally it would be nice if ConfuserEx could handle this. But if not, at least this post may be a useful debugging signpost for others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriageThis issue needs some initial analysis.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions