Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The baml decompiler sometimes throws an unhandled exception #365

Closed
ecobisi opened this issue Oct 26, 2012 · 1 comment
Closed

The baml decompiler sometimes throws an unhandled exception #365

ecobisi opened this issue Oct 26, 2012 · 1 comment
Assignees
Labels

Comments

@ecobisi
Copy link

ecobisi commented Oct 26, 2012

Hello,

first of all thanks for the great work you are doing with ILSpy: I really love it.
I have found a bug with the baml decompiler (even with the current stable version of ILSpy - 2.1.0.1603), which happens whenever you try to decompile some baml (more specifically, the ones contained within some of the Visual Studio 2010 internal dlls).

Here is the full stack trace for the exception:

System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info)
at Mono.Cecil.AssemblyNameReference.Parse(String fullName)
at ILSpy.BamlDecompiler.CecilTypeResolver.GetTypeByAssemblyQualifiedName(String name)
at Ricciolo.StylesExplorer.MarkupReflection.TypeDeclaration.get_Type()
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.get_NamespaceURI()
at Ricciolo.StylesExplorer.MarkupReflection.XmlBamlReader.get_Prefix()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream)
at ILSpy.BamlDecompiler.BamlResourceEntryNode.LoadBaml(AvalonEditTextOutput output)
at ILSpy.BamlDecompiler.BamlResourceEntryNode.<>c__DisplayClass3.b__1()

Perhaps CecilTypeResolver should react silently to the exception and try to decompile with the information it already has?

Thanks a lot for your support.
Cheers

@ghost ghost assigned siegfriedpammer May 10, 2013
@lextm
Copy link
Contributor

lextm commented Jun 16, 2014

I can provide more information as I just received a detailed report for Obfuscar. A patch is required to fix this issue. I might send a pull request soon,

diff --git a/ILSpy.BamlDecompiler/CecilTypeResolver.cs b/ILSpy.BamlDecompiler/CecilTypeResolver.cs
index 9768472..b6d1320 100644
--- a/ILSpy.BamlDecompiler/CecilTypeResolver.cs
+++ b/ILSpy.BamlDecompiler/CecilTypeResolver.cs
@@ -37,7 +37,13 @@ namespace ILSpy.BamlDecompiler

        public IType GetTypeByAssemblyQualifiedName(string name)
        {
-           int comma = name.IndexOf(',');
+            int bracket = name.LastIndexOf(']');
+            int comma = bracket > -1 ? name.IndexOf(',', bracket) : name.IndexOf(',');

            if (comma == -1)
                throw new ArgumentException("invalid name");

The cause is that for generics types, the name can be very complex, such as

System.Windows.Controls.DataVisualization.Charting.ColumnBarBaseSeries`1[[System.Windows.Controls.DataVisualization.Charting.ColumnDataPoint, System.Windows.Controls.DataVisualization.Toolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Windows.Controls.DataVisualization.Toolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35

@dgrunwald dgrunwald mentioned this issue Jun 29, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants