1

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?

1
  • The code you shared doesn't tell us anything, how are you using it? Commented Oct 16 at 14:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.