Here's more info:
// ManagedEvents.h
#pragma once
using namespace System;
namespace ManagedEvents {
public ref class Class1
{
event EventHandler^ someEvent;
};
}
Here's the main C# code that tries to handle someEvent:
using System;
using ManagedEvents;
namespace TestManagedCLIEvents
{
class Program
{
static void Main(string[] args)
{
Class1 testclass = new Class1();
testclass.someEvent = new EventHandler(someEventHandler);
}
private void someEventHandler(Object ojb, EventArgs args)
{
}
}
}
The compilation error is: ManagedEvents.Class1 does not contain a definition
for 'someEvent' and no extension method 'someEvent' accepting a first
argument of type 'ManagedEvents.Class1' could be found (are you missing a
using directive or an assembly reference?)
I've made sure the ManagedEvents C++/CLI assembly is referenced from the C#
project.
> Do you have a concise-but-complete code sample that demonstrates the
> error? What is the _exact_ text of the error? Do you have the C++/CLI
[quoted text clipped - 5 lines]
>
> Pete
Peter Duniho - 31 Jul 2008 22:54 GMT
> Here's more info:
>
[quoted text clipped - 8 lines]
> };
> }
Shouldn't that be:
public ref class Class1
{
public:
event EventHandler^ someEvent;
};
???
Your original post included the "public:", but the above does not. If you
forgot that, well...that would certainly explain the error. :)
Pete
John Doe - 31 Jul 2008 22:54 GMT
Nevermind, i noticed i didn't declare the event as public...
> Here's more info:
>
[quoted text clipped - 48 lines]
>>
>> Pete
Jon Skeet [C# MVP] - 31 Jul 2008 23:06 GMT
<snip>
> The compilation error is: ManagedEvents.Class1 does not contain a definition
> for 'someEvent' and no extension method 'someEvent' accepting a first
[quoted text clipped - 3 lines]
> I've made sure the ManagedEvents C++/CLI assembly is referenced from the C#
> project.
Well, apart from anything else you shouldn't be trying to *assign* to
the event - you should be trying to *subscribe to it:
testclass.someEvent += new EventHandler(someEventHandler);
However, if that were the only problem I'd expect a different error
message.
After a bit of experimenting, it seems that the problem is just that
the event isn't public. Make it public, change the code as above, and
it should be okay.

Signature
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com