ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

WPF issues

Open VBAndCs opened this issue 4 years ago • 4 comments

When decompiling WPF, please take care of code-behind files:

  • [x] you can get the class name from the class attr in the xml file>
  • [x] Name the code behind file after the xaml file and append .cs, and place this file in the same folder as the xaml file.
  • [x] There is some auto-generated methods in such classes, marked with AutoGeneratd and/or NouUserCode attrs. Delete them.
  • [x] There are also auto-generated fields corresponding to XAML tags, and there is a private field private bool _contentLoaded;. Delete them.
  • [ ] The Buid Action for App.xaml is page, while it should be ApplicationDefinition.
  • [ ] The Buid Action for resources like images is EmbeddedResource, while it should be Resource.

There is also a general behavior (not a WPF explosive) of creating all folders in one level with qualified names, which cause many errors with resource paths (as images, xaml, cshtml, etc). Please get rid of the namespace part, and nest folders.

Any doable part of these suggestion will save a lot of users time. Thanks

VBAndCs avatar Dec 29 '20 15:12 VBAndCs

You and anyone else are very welcome to contribute this. The decompilation pipeline might need some adjustments / additional information passed in so that the code generated by XAML compilation can be transformed properly, if you want to dive into this and need some help, please feel free to ask questions.

siegfriedpammer avatar Dec 29 '20 19:12 siegfriedpammer

Also possible to do (if assembly contains that information)

  • [ ] Set a compile tool as XamlIntelliSenseFileGenerator for .xaml files instead of MSBuild:Compile now

Neznakomec avatar Sep 18 '22 06:09 Neznakomec

I'm sorry, probably I should create a separate issue thread for WPF issues with devexpress framework xaml files?

I tried to compile one of examples in DevExpress v21.2 library (DevExpress.StockMarketTrader.Wpf project), then opened .exe file in ILSpy and exported project. As I see, some decompiled xaml files have issues with compilation due to

  1. Some string parameters haven't additional quotes, for example I see an attribute Foreground="{DXBinding Expr=CurrentPrice - PreviousPrice > 0 ? @r(greenBrush) : @r(redBrush)}" while original .xaml file had Foreground="{DXBinding Expr='CurrentPrice - PreviousPrice > 0 ? @r(greenBrush) : @r(redBrush)'}"

As I see by debugging ILSpy.BamlDecompiler project, originally single quotes were in XML document, but they were omitted later on rewrite passes. Also another product, dotPeek, decompiles .baml files without losing quotes here. Though, it have another problems with correct reconstruction of XAML markup.

  1. Sometimes tag inside tag is decompiled as attribute of some tag (why attribute, I don't know)
  2. Sometimes strange namespace declarations introduced in the middle of .xaml document, while original .xaml file haven't this namespace declarations
  3. Not necessary, but original file were pretty formatted (one attribute in a row), while decompiled .xaml file places all attributes of each tag in a single row

Neznakomec avatar Sep 18 '22 13:09 Neznakomec

When decompiling WPF, please take care of code-behind files:

  • [x] you can get the class name from the class attribute in the XML file
  • [x] Name the code behind file after the XAML file and append .cs, and place this file in the same folder as the XAML file.
  • [x] There is some auto-generated methods in such classes, marked with DebuggerNonUserCode, GeneratedCode, and/or EditorBrowsable attributes. Delete them.
  • [x] There are also auto-generated fields corresponding to XAML tags, and there is a private field private bool _contentLoaded;. Delete them.
  • [ ] The Build Action for App.xaml is page, while it should be ApplicationDefinition.
  • [ ] The Build Action for resources like images is EmbeddedResource, while it should be Resource. There is also a general behavior (not a WPF exclusive) of creating all folders in one level with qualified names, which cause many errors with resource paths (as images, XAML, CSHTML, etc). Please get rid of the namespace part, and nest folders.

Any doable part of these suggestion will save a lot of users time. Thanks

As of me upgrading from 8.1 or 8.0 to 8.2, it seems like it now it (with default settings) shows auto-generated methods marked with DebuggerNonUserCode, GeneratedCode, and/or EditorBrowsable attributes and doesn't delete auto-generated fields like _contentLoaded

RealPacket avatar Jan 22 '24 21:01 RealPacket