Browse Source

Fix #1436: Do not crash on unknown assembly reference.

pull/1440/head
Siegfried Pammer 7 years ago
parent
commit
1170249b1f
  1. 2
      ILSpy.BamlDecompiler.Tests/Cases/NamespacePrefix.xaml
  2. 4
      ILSpy.BamlDecompiler/Xaml/NamespaceMap.cs
  3. 6
      ILSpy.BamlDecompiler/XmlnsDictionary.cs

2
ILSpy.BamlDecompiler.Tests/Cases/NamespacePrefix.xaml

@ -1,4 +1,4 @@
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cc="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases"> <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cc="clr-namespace:ILSpy.BamlDecompiler.Tests.Cases" xmlns:unk="clr-namespace:A;assembly=Unknown">
<cc:CustomControl Grid.Row="0" Tag="{}{}{Test}" CustomName="Custom1"> <cc:CustomControl Grid.Row="0" Tag="{}{}{Test}" CustomName="Custom1">
<FrameworkElement.Style> <FrameworkElement.Style>
<Style /> <Style />

4
ILSpy.BamlDecompiler/Xaml/NamespaceMap.cs

@ -36,11 +36,11 @@ namespace ILSpy.BamlDecompiler.Xaml {
public NamespaceMap(string prefix, IModule asm, string xmlNs, string clrNs) { public NamespaceMap(string prefix, IModule asm, string xmlNs, string clrNs) {
XmlnsPrefix = prefix; XmlnsPrefix = prefix;
Assembly = asm ?? throw new ArgumentNullException(nameof(asm)); Assembly = asm;
XMLNamespace = xmlNs; XMLNamespace = xmlNs;
CLRNamespace = clrNs; CLRNamespace = clrNs;
} }
public override string ToString() => $"{XmlnsPrefix}:[{Assembly.Name}|{CLRNamespace ?? XMLNamespace}]"; public override string ToString() => $"{XmlnsPrefix}:[{Assembly?.Name}|{CLRNamespace ?? XMLNamespace}]";
} }
} }

6
ILSpy.BamlDecompiler/XmlnsDictionary.cs

@ -37,7 +37,7 @@ namespace ILSpy.BamlDecompiler {
public string LookupXmlns(IModule asm, string clrNs) { public string LookupXmlns(IModule asm, string clrNs) {
foreach (var ns in this) { foreach (var ns in this) {
if (asm.FullAssemblyName == ns.Assembly.FullAssemblyName && ns.CLRNamespace == clrNs) if (asm.FullAssemblyName == ns.Assembly?.FullAssemblyName && ns.CLRNamespace == clrNs)
return ns.XMLNamespace; return ns.XMLNamespace;
} }
@ -103,14 +103,14 @@ namespace ILSpy.BamlDecompiler {
public string LookupXmlns(IModule asm, string clrNs) { public string LookupXmlns(IModule asm, string clrNs) {
foreach (var map in piMappings) { foreach (var map in piMappings) {
if (asm.FullAssemblyName == map.Value.Assembly.FullAssemblyName && map.Value.CLRNamespace == clrNs) if (asm.FullAssemblyName == map.Value.Assembly?.FullAssemblyName && map.Value.CLRNamespace == clrNs)
return map.Key; return map.Key;
} }
var scope = CurrentScope; var scope = CurrentScope;
while (scope != null) { while (scope != null) {
foreach (var ns in scope) { foreach (var ns in scope) {
if (asm.FullAssemblyName == ns.Assembly.FullAssemblyName && ns.CLRNamespace == clrNs) if (asm.FullAssemblyName == ns.Assembly?.FullAssemblyName && ns.CLRNamespace == clrNs)
return ns.XMLNamespace; return ns.XMLNamespace;
} }

Loading…
Cancel
Save