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

Invalid interface method implementations #310

Closed
thegu5 opened this issue Jul 1, 2024 · 4 comments · Fixed by #346
Closed

Invalid interface method implementations #310

thegu5 opened this issue Jul 1, 2024 · 4 comments · Fixed by #346
Labels
bug Something isn't working output-format: dummydll

Comments

@thegu5
Copy link
Contributor

thegu5 commented Jul 1, 2024

This was already mentioned in #cpp2il-support, I'm making this issue for organization.

example:
image
image
The method in the interface is public, but the method in the implementing class is private, causing the type to be invalid

Method 'OnBeforeSerialize' in type 'UnityEngine.Events.UnityEvent`1' from assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

(this specific example's error is because UnityEvent`1 extends UnityEventBase which implements ISerializationCallbackReceiver, and it doesn't see the method impl in UnityEventBase)

https://github.com/Unity-Technologies/UnityCsReference/blob/c4a2a4d90d91496bf3d4602778223a0e660c2a56/Runtime/Export/UnityEvent/UnityEvent.cs#L743

@ds5678
Copy link
Contributor

ds5678 commented Aug 10, 2024

From my perspective, everything is fine, except for your decompiler. That's an explicit interface implementation, so it's supposed to be private. It's just not supposed to show an access modifier in the source code.

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation

@SamboyCoding
Copy link
Owner

SamboyCoding commented Aug 10, 2024

I'm guessing one possibility is that the explicit implementation info is not being set (it's a separate field to specify it should inherit from the interface) and so ILSpy is decompiling it wrong. That or one of the combinations of flags (private final hidebysig specialname newslot virtual) is missing.

@thegu5
Copy link
Contributor Author

thegu5 commented Aug 10, 2024

explicit implementation info is not being set

Looked at it again, this seems to be the case (?)

Correct example (sharplab):

    .method private final hidebysig newslot virtual 
        instance void A.Method () cil managed 
    {
        .override method instance void A::Method()
        .maxstack 8

        IL_0000: ret
    }

Cpp2IL output, missing .override:

	.method private final hidebysig newslot virtual 
		instance void UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize () cil managed 
	{
		.maxstack 8

		IL_0000: ldnull
		IL_0001: throw
	}

@SamboyCoding
Copy link
Owner

Yup ok, this is an old issue that's resurfaced then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working output-format: dummydll
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants