Hi guys, I really need some help on this as i'm going slowly insane.

What I have is a windows service written in C++/CLI exposing an object with TCP remoting. The remoted object loads a bunch of other objects from a database into a List<> and keeps them in memory for the lifetime of the service.

I have another project which is a C# Winforms application which accesses the service using TCP remoting and wants to get access to an object in the list.

However, when my C# project gets the object it seems to get a copy of it rather than a reference to it. All the parameters look the same but if I attempt to update it, the C++/CLI "copy" of it doesn't change.

I have an event in the object which fires when a property of the object is changed. I want to consume this event in the C# project. Now if I change the C# copy of the object the event gets fired and my C# delegate gets called. However, if I pass an ID and get the C++/CLI code to find the object matching the ID it updates the object but the event is not fired.

I hope this makes sense. Does it sound possible, what i'm trying to do Or maybe i'm just missing something obvious. Any help would be greatly appreciated.

Thanks in advance

Re: Visual C++ Language C# and C++/CLI sharing objects

David Anton

The object being exposed from C++/CLI: is it a value class (or value struct) instance or ref class (or ref struct) instance If it's a value class or value struct, then you have copy semantics - any reference you get is a copy of the data and updating it doesn't affect the one living in the C++/CLI assembly.

David Anton
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter, VB to C++ converter
Instant Python: C# to Python converter, VB to Python converter

Re: Visual C++ Language C# and C++/CLI sharing objects


Thanks for your response.

It's declared with "public ref class" - but it also has the [Serializable] attribute to solve a barf about the object not being serializable. I read somewhere that this attribute causes the object to be marshalled by value. Could this be the problem