Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1017611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:43:53+00:00 2026-05-16T10:43:53+00:00

I want to raise an event from a .NET class, and receive this event

  • 0

I want to raise an event from a .NET class, and receive this event in Silverlight code (out-of-browser, using the COM interop support added in SL4).

Can anyone point out the problem in my code? Do I maybe need to do more attribute-decorated interface boilerplate to get this working?

Code:

Rather than write native COM code, I am writing .NET code and exposing it via COM interop.

My event-raising .NET class looks like this:

using System;

namespace TestComInterop2 {
  public class TestClass {
    public event EventHandler TestEvent;
    public void Fire() {
      if (TestEvent != null)
        TestEvent(this, EventArgs.Empty);
    }
  }
}

My SL4 client code looks like this:

...

private delegate void HandlerDelegate(dynamic sender, dynamic eventArgs);

private void TestEventSinking(object sender, RoutedEventArgs e)
{
  // Create instance of COM-registered .NET class
  var testClass = AutomationFactory.CreateObject("TestComInterop2.TestClass");

  // Subscribe to event (second line fails with System.Exception)
  //
  //    "Failed to add event handler. Possible reasons include: the object does not
  //    support this or any events, or something failed while adding the event."
  //
  AutomationEvent testEvent = AutomationFactory.GetEvent(testClass, "TestEvent");
  testEvent.AddEventHandler(new HandlerDelegate(HandleTestEvent));

  // Fire the event
  testClass.Fire();
}

private void HandleTestEvent(object sender, object eventargs)
{
  MessageBox.Show("Event fired");
}

...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:43:54+00:00Added an answer on May 16, 2026 at 10:43 am

    Use the [ComSourceInterface] attribute on your class. The relevant MSDN Library topic is here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing out some xml from C# using the .net framework's XmlTextWriter. This works
I want to do something like this: class Dictable: def dict(self): raise NotImplementedError class
How can I raise an event from a mock/stub using Rhino Mocks? I've found
I want to bubble an event from a class to a Custom Usercontrol. My
I have convert class from c# to vb.net .. My point that I want
I want to raise an event that shows up in the system event viewer
-I want to raise an event whenever method showmessage is called.I want to catch
In my .NET application I am subscribing to events from another class. The subscription
This is a problem i have with data that i receive from a library
I want to handle a custom event on an asp.net page with C# as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.