Decompiling vb.net application

446 views Asked by At
    [CompilerGenerated]
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    [AccessedThroughProperty("SimpleButton1")]
    private SimpleButton _SimpleButton1;
internal virtual SimpleButton SimpleButton1
    {
        [CompilerGenerated]
        get
        {
            return this._SimpleButton1;
        }
        [MethodImpl(MethodImplOptions.Synchronized)]
        [CompilerGenerated]
        set
        {
            EventHandler value2;
            value2 = SimpleButton1_Click;
            SimpleButton simpleButton;
            simpleButton = this._SimpleButton1;
            if (simpleButton != null)
            {
                simpleButton.Click -= value2;
            }
            this._SimpleButton1 = value;
            simpleButton = this._SimpleButton1;
            if (simpleButton != null)
            {
                simpleButton.Click += value2;
            }
        }
    }

When i decompile an vb.net application using ilspy, dnspy, just decompile, reflector, etc.

all the decompilers decompiles events in this format. so i cannot open the designer file. is there any other way to decompile properly?
enter image description here

1

There are 1 answers

0
Daniel On

What you are seeing is the code that the VB compiler generates for the Sub X() Handles Field.Event syntax. The VB forms designer supports the Handles syntax, but the C# forms designer does not have any direct equivalent. In C#, event handlers are typically registered directly in the InitializeComponent method, and do not automatically de/re-register when writing to the field.

To get the designer working, you would need to:

  • verify that the property is only set inside InitializeComponent, not somewhere else
  • move the SimpleButton.Click += SimpleButton1_Click; into the InitializeComponent, e.g. so that it directly follows the SimpleButton = new Button() property assignment.
  • if the designer is picky, you may need to explicitly new the eventhandler type with a fully-qualified type name: SimpleButton.Click += new System.EventHandler(SimpleButton1_Click);
  • delete the property and remove the leading underscore from the field name

I am not aware of any tools that would automate these steps.

Turning off the C# 2.0 feature "Use implicit method group conversions" in the decompiler settings can help with the new EventHandler portion.