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

Native Code Encountered when trying to subscribe to an event. #3046

Closed
Vardan2009 opened this issue Jul 16, 2024 · 4 comments
Closed

Native Code Encountered when trying to subscribe to an event. #3046

Vardan2009 opened this issue Jul 16, 2024 · 4 comments
Labels

Comments

@Vardan2009
Copy link

Area of Cosmos - What area of Cosmos are we dealing with?

Events

Expected Behaviour - What do you think that should happen?

Be able to subscribe to a custom event

Actual Behaviour - What unexpectedly happens?

The compilation fails with the following message
Exception: System.Exception: Native code encountered, plug required. Chech build output for more information
I assume this means that Cosmos is missing a plug for Event Handling, but I thought Cosmos had an implementation for that?

Reproduction - How did you get this error to appear?

Create custom event args

public class MouseEventArgs : EventArgs
{
    public uint x;
    public uint y;
}

Create an event in another class

public event EventHandler<MouseEventArgs> MouseClick;
// Call this when need to invoke event
protected virtual void OnMouseClick(MouseEventArgs e) => MouseClick?.Invoke(this, e);

Try to subscribe to the event from other class

// if I only remove this single line, the whole code compiles successfully, the only part that causes
// the compiler to throw an error is when trying to subscribe to the event
clickBtn.MouseClick += OnClickBtnClick;
/// ... ///
private void OnClickBtnClick(object sender, MouseEventArgs e)
{
    clickCount++;
    countLabel.Text = $"Clicked the button {clickCount} times";
}

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Latest DevKit with C#

@Vardan2009 Vardan2009 added the Bug label Jul 16, 2024
@9xbt
Copy link
Contributor

9xbt commented Jul 16, 2024

That means something isn't plugged. Could you show us the full output log so we can see which method needs to be plugged?

@Vardan2009
Copy link
Author

This is the part of the output since the error

1>IL2CPU : error : Exception: System.Exception: Native code encountered, plug required. Check build output for more information.
1>  DO NOT REPORT THIS AS A BUG.
1>  Please see http://www.gocosmos.org/docs/plugs/missing/
1>  Need plug for: System.MulticastDelegate  System.Delegate.InternalAllocLike(System.Delegate)(Plug Signature: System_MulticastDelegate__System_Delegate_InternalAllocLike_System_Delegate_ ).
1>  Static: True
1>  Assembly: System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
1>  Called from:
1>System.MulticastDelegate::System.MulticastDelegate NewMulticastDelegate(System.Object[], Int32, Boolean)
1>System.MulticastDelegate::System.Delegate CombineImpl(System.Delegate)
1>System.Delegate::System.Delegate CombineImpl(System.Delegate)
1>
1>
1>   at Cosmos.IL2CPU.ILScanner.ScanMethod(MethodBase aMethod, Boolean aIsPlug, String sourceItem) in C:\Users\user\Documents\GitHub\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 562
1>   at Cosmos.IL2CPU.ILScanner.ScanQueue() in C:\Users\user\Documents\GitHub\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 751
1>   at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod, IEnumerable`1 plugsAssemblies) in C:\Users\user\Documents\GitHub\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\ILScanner.cs:line 270
1>   at Cosmos.IL2CPU.CompilerEngine.Execute() in C:\Users\user\Documents\GitHub\CosmosOS\IL2CPU\source\Cosmos.IL2CPU\CompilerEngine.cs:line 187
1>IL2CPU task took 00:00:03.1548308

@ADev531
Copy link

ADev531 commented Oct 30, 2024

Sorry @gamma63 , EventHandler is not working as bug of IL2CPU. (Bug of MulticastDelegate Plugs)
You need to use List to do it.

@ascpixi
Copy link
Contributor

ascpixi commented Nov 7, 2024

Bit late, but this indeed is a bug and is tracked in #2765.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants