Fixed: Aspect code: assign function address to delegate

I am trying to generate and assign to that delegate based on a method in the existing code. The project compiles without errors.

The delegate is generated correct (as far As I can see) - decompiled code:
image
Note that I can not find the definition of the Delegate type in the decompiled code.

Then I want to set this delegate.
The code I want is:

ExitApplication_Delegate = AddressOf(ExitApplication)

Decompiled, this looks like:

ExitApplication_Delegate = New CloseAppDelegate(AddressOf Me.ExitApplication)

But the code that is generated is (decompiled):

ExitApplication_Delegate = New ExitApplicationDelegate(Me, ExitApplication)

The generated code is thus using another constructor than written code, and fails on runtime with error

Could not load type 'ExitApplicationDelegate because it cannot inherit directly from the delegate class

The code I use to generate the addressOf code is:

new ProcPtrValue(new SelfValue, "ExitApplication")

What am I doing wrong?

can I see this in a project?

It’s a little bit big …

Solution to reproduce: ClassLibrary6 1.bugreport.zip (1.6 MB)

Build log (succeeded): ClassLibrary6 1.bugreport.txt (62.2 KB)

Print screen of written code:

Print screen of decompiled code of Class1 in ClassLibrary6 (to VB code):

Print screen of decompiled code of Class1 in ClassLibrary6 (to IL):


In this decompiled code, Example is what was written in code and Test is what was generated.
What I see is:

  • For Test, the Public Delegate Sub TestDelegate is missing from the code, while it is used (second line of the class).
  • The generated assignment in the constructor is different than the written assignent for Example.

Edit: When I look at the IL, the only difference I see is that the TestDelegate isn’t defined, but somehow it is used.

let me rephrase that: can you illustrate that in a simple project, rather than me having to try and do that based on the code snippets :wink:

Already did. see the post above yours.

1 Like

Were you able to reproduce? (As it is not marked as a bug)

Weird, I could have sworn I had logged this yesterday…

1 Like

Thanks, logged as bugs://85845

Edit: When I look at the IL, the only difference I see is that the TestDelegate isn’t defined, but somehow it is used.

what am I missing?

In my decompiler it isn’t in the IL.
And when you instantiate the class, it will crash with a typeload exception on the line Test_Delegate = Test

Well, in mine it is, so it has to be there :wink:

I cant run this, as its a class library project.

peverify shows errors:

➜  Cherry:~/Downloads/ClassLibrary6 2/Bin/Debug # peverify ClassLibrary6.dll
➜  Cherry:~/Downloads/ClassLibrary6 2/Bin/Debug # 

here’s my dll: ClassLibrary6.dll.zip (4.5 KB)

all I did was open your project and build it, no changes.

I added

  Public Shared Sub Main
    New Class1
    writeLn(1)
  End Sub

and made it an exe. runs fine:

ClassLibrary6 2.zip (1.6 MB)

this is with shipped 2621, but I doubt this got broken, post?

It doesn’t work in:
image

So, I am upgrading now and test again.

1 Like

“This is the Water and this is the Well. Drink full and descend” - what interesting poem.
@mh - a fan of Twin Peaks? Reminds me of the move “Get Out (2017)” too.

Indeed - problem is solved - my apologies.

1 Like

bugs://85845 got closed with status fixed.