Browse Source

prevent XmlException while reading XmlDoc from crashing the decompiler #485

pull/550/head
Siegfried Pammer 11 years ago
parent
commit
85682a0da9
  1. 7
      ILSpy/Languages/CSharpLanguage.cs
  2. 4
      ILSpy/TextView/DecompilerTextView.cs
  3. 11
      ILSpy/VB/VBLanguage.cs

7
ILSpy/Languages/CSharpLanguage.cs

@ -215,7 +215,14 @@ namespace ICSharpCode.ILSpy
additionalTransform.Run(astBuilder.SyntaxTree); additionalTransform.Run(astBuilder.SyntaxTree);
} }
if (options.DecompilerSettings.ShowXmlDocumentation) { if (options.DecompilerSettings.ShowXmlDocumentation) {
try {
AddXmlDocTransform.Run(astBuilder.SyntaxTree); AddXmlDocTransform.Run(astBuilder.SyntaxTree);
} catch (XmlException ex) {
string[] msg = (" Exception while reading XmlDoc: " + ex.ToString()).Split(new[]{'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
var insertionPoint = astBuilder.SyntaxTree.FirstChild;
for (int i = 0; i < msg.Length; i++)
astBuilder.SyntaxTree.InsertChildBefore(insertionPoint, new Comment(msg[i], CommentType.Documentation), Roles.Comment);
}
} }
astBuilder.GenerateCode(output); astBuilder.GenerateCode(output);
} }

4
ILSpy/TextView/DecompilerTextView.cs

@ -187,6 +187,7 @@ namespace ICSharpCode.ILSpy.TextView
} }
XmlDocRenderer renderer = new XmlDocRenderer(); XmlDocRenderer renderer = new XmlDocRenderer();
renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr)); renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr));
try {
XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module); XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module);
if (docProvider != null) { if (docProvider != null) {
string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr)); string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
@ -195,6 +196,9 @@ namespace ICSharpCode.ILSpy.TextView
renderer.AddXmlDocumentation(documentation); renderer.AddXmlDocumentation(documentation);
} }
} }
} catch (XmlException) {
// ignore
}
return renderer.CreateTextBlock(); return renderer.CreateTextBlock();
} }
return null; return null;

11
ILSpy/VB/VBLanguage.cs

@ -32,6 +32,7 @@ using ICSharpCode.Decompiler.Ast.Transforms;
using ICSharpCode.ILSpy.XmlDoc; using ICSharpCode.ILSpy.XmlDoc;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
using CSharp = ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.VB; using ICSharpCode.NRefactory.VB;
using ICSharpCode.NRefactory.VB.Visitors; using ICSharpCode.NRefactory.VB.Visitors;
using Mono.Cecil; using Mono.Cecil;
@ -439,8 +440,16 @@ namespace ICSharpCode.ILSpy.VB
void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, ModuleDefinition module) void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, ModuleDefinition module)
{ {
astBuilder.RunTransformations(transformAbortCondition); astBuilder.RunTransformations(transformAbortCondition);
if (options.DecompilerSettings.ShowXmlDocumentation) if (options.DecompilerSettings.ShowXmlDocumentation) {
try {
AddXmlDocTransform.Run(astBuilder.SyntaxTree); AddXmlDocTransform.Run(astBuilder.SyntaxTree);
} catch (XmlException ex) {
string[] msg = (" Exception while reading XmlDoc: " + ex.ToString()).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
var insertionPoint = astBuilder.SyntaxTree.FirstChild;
for (int i = 0; i < msg.Length; i++)
astBuilder.SyntaxTree.InsertChildBefore(insertionPoint, new CSharp.Comment(msg[i], CSharp.CommentType.Documentation), CSharp.Roles.Comment);
}
}
var csharpUnit = astBuilder.SyntaxTree; var csharpUnit = astBuilder.SyntaxTree;
csharpUnit.AcceptVisitor(new NRefactory.CSharp.InsertParenthesesVisitor() { InsertParenthesesForReadability = true }); csharpUnit.AcceptVisitor(new NRefactory.CSharp.InsertParenthesesVisitor() { InsertParenthesesForReadability = true });
var unit = csharpUnit.AcceptVisitor(new CSharpToVBConverterVisitor(new ILSpyEnvironmentProvider()), null); var unit = csharpUnit.AcceptVisitor(new CSharpToVBConverterVisitor(new ILSpyEnvironmentProvider()), null);

Loading…
Cancel
Save