Question: I've a few Classes from a assembly which is .Net 2.0. These Classes are marked with Serializable.

In my project, I use these classes in my Classes, which are marked with DataContract(IsReference=true) and DataMember.

Now I have the problem, with DataContractSerialiser that it serializes the private fields of my .Net 2.0 Classes, which will not work. But when I use XMLSerialiser, I cannot use IsReference, and so I can also not do this.

Is there a easy (simple) Solution for this? Maybe a someone has a own XMLSerializer which supports references?

Here is a bit of my code:

```
[DataContract(IsReference = true)]
public class ConnectionConfig: INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
            PropertyChanged(this, new PropertyChangedEventArgs("ObjectAsString"));
        }
    }

    private PLCConnectionConfiguration _configuration;
    [DataMember]
    public PLCConnectionConfiguration Configuration
    {
        get { return _configuration; }
        set { _configuration = value; NotifyPropertyChanged("Configuration"); }
    }
}

```

where PLCConnectionConfiguration comes from a .NET 2.0 assembly, and is decorated with [Serializeable]

Answer: 
You are right: exception constructor takes the **pointer** to the string, it does not store a copy of string content. That content is stored in local variable

```
   char adieu[128];

```

which goes out of scope upon exit from Foo::bar method. 

The stack contains 'activation records' (also called 'stack frames') for functions which are currently executing. Each function call allocates memory on that stack for all local variables declared in that function (at machine level, this may be implemented as 'push' or any other command that advances stack pointer). Each return from the function - it does not matter if it's a normal return or exit by throwing an exception - frees the memory which was allocated when entering the function (at machine level, this is implemented as 'pop' or 'restore stack pointer to the value it had when entering the function').

So, when the stack is unwound, all 'activation records' in 'function call chain' or 'stack' between the function where exception was thrown and the function where the exception is caught are freed.
You have a far easier solution:

```
struct MyExcept : public std::exception {
   std::string errstr;
   const char* what() const throw() {return errstr_.c_str();}
   MyExcept(int errno, std::string prefix = "") : errstr (prefix + LibErrString(errno)) {}
};
...
throw MyExcept(err, "In Foo::bar... ");

```

With C strings, you have to worry a lot more about scopes and manual memory managament. You correctly noticed that you exit a few scopes (pop variables and functions off the stack), so C strings are even worse there. C++ strings on the other hand behave much more like integers. Memory management is an integrated feature.

For the same reason, I've moved the `LibErrString` call inside your exception class. Error handling code fits naturally in exception classes, and should not clutter business code.

---

So much for practical code, back to theory. What happens when an exception is thrown and caught? C++ first determines *where* the exception will be caught. There must be an enclosing `try{ }` scope, but possibly there are a lot more scopes in between: function scopes, for-scopes, if-scopes, or just plain block scopes. 

These scopes are then exited from the inside out. As each scope is exited, the variables local to that block are destroyed. When a function scope is exited, the next scope to consider is of course the caller; for the other scopes the next scope is the surrounding scope.

You see that variables are destroyed, and functions are exited in a LIFO order. That means that a stack structure is a natural fit. You could also use two stacks, keeping return addresses and variables separate. Or three, to avoid big buffers on the stack. Since there are many reasonable implementations, C++ doesn't actually describe a precise implemenation, just the behavior.