1
    [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

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35
  • The result is autogenerated C# code. What exactly are you looking for? – David Aug 24 '22 at 13:40
  • is there any way to change the code like this? SimpleButton SimpleButton1; and bind the event handling in initializecomponent method. so designer will open – Muthu Narayanan Aug 24 '22 at 14:45
  • Not sure really what context you're working here (if this was your app or someone else's, in which case I hope you've got permission) DevExpress is a 3rd party control suite, have you got the DevExpress.Editors library installed? – Hursey Aug 24 '22 at 20:51
  • yes. i have installed devexpress.editors installed. this is one of our very old projects. we lost the source code. so we r trying to get the source code from assembly. when i change this code like SimpleButton SimpleButton1; the designer works. we cannot amend the code like this manually since it is a larger project. so im looking for a way to change the code in this way automatically. – Muthu Narayanan Aug 25 '22 at 02:19

1 Answers1

0

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.

Daniel
  • 15,944
  • 2
  • 54
  • 60