Thanks for the suggestion. I am at present exploring all my options.
If one marks a value type as NonSerialized it still has storage associated
with it after deserialization. It is just uninitialized. For example if you
had an int variable to which you assigned the value 5 and it was attributed
with NonSerialized. Upon deserialization the value is 0 as this is the value
given to an uninitialized integer. A reference type declared with stack
semantics needs to behave in the same fashion. Under the covers the
deserialization code needs to assign an uninitialized object of that type to
the variable.
I have tried to assign it storage in the OnDeserialized routine, something
like this...
//~~~~~~~~~~~~~~
// Declared previously as
[NonSerialized]
MyClass myClass;
//~~~~~~~~~~~~~~~~
void OnDeserialziation(Object^ sender)
{
%myClass = gcnew MyClass( ) // unfortunately it doesn't work like this.
}
I am going to put in a support call today at some point.
I agree that C++ / CLI is complex, but it is a wonderful tool to do what it
is designed for, to straddle the managed and unmanaged worlds. It is light
years ahead of its predecessor managed C++. It has a few bugs still to be
worked out, unfortunately mine is one of them. It makes interoperating
between the two worlds as painless as possible and I think is a very elegant
means of doing it. It is really quite remarkable the way that it allows you
to move, almost seamlessly, between managed and unmanaged. There are still
barriers that .Net imposes that it must work within. I would very much like
to be able to use unmanaged types as template parameters to managed classes
and I would very much like to be able to write inline assembler in an
unmanaged assembly. It is very unlikely that this will ever come to pass.
But, all in all a wonderful tool that I hope keeps evolving.
Bronek Kozicki said:
Howard said:
Is anyone aware of a fix for the apparent bug in C++ /CLI 2005...
If you create a class with a ref type member variable declared with
stack semantics and you declare this member as [NonSerialized], when you
deserialize an object of this class type, the member can no longer be
used.
It is essentially orphaned.
OK, you deserialize a class, but one of its members is marked and
[NonSerialized]. What do you expect the semantics of this member would be?
It cannot be deserialized, because you marked it so. I guess you should
either allow it to be deserialized and augment the data later, or
customize deserialization with your own code as to ignore this marking.
Feel free to ignore my advice, though. I personally think that C++/CLI is
devilishly difficult and only real experts in both domains C++ AND .NET
stand a chance to use it fluently. I'm not an expert in .NET by any means.
B.