I am trying to create an event in Windows Runtime C# Component in this way,
namespace SampleNamespace
{
public sealed class SampleClass
{
private static readonly Lazy<SampleClass> _instance = new Lazy<SampleClass>(() => new SampleClass());
public static SampleClass Instance => _instance.Value;
private SampleClass() { }
public event EventHandler<string> SampleEvent;
public void TestCode()
{
Debug.WriteLine("This is for test");
SampleEvent?.Invoke(this, "value");
}
}
}
But when I try to build the project it gives this error,
error WME1026: Event add method 'SampleNamespace.SampleClass.add_SampleEvent(System.EventHandler<System.String>)' has return type 'System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken'. Event add methods must return System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken. Was the module that you are exporting compiled as a winmdmodule (/target:winmdobj) for Windows Metadata export?
I could not find anything to solve this issue. How can I solve it?