CreateInstanceAndUnwrap

M

Max

I'm using CreateInstanceAndUnwrap as follows:

object myinstance = myAppDomain.CreateInstanceAndUnwrap("LibraryFile",
"LibraryFileNamespace.LibraryFileClass", true, 0, null, null, null, null, null);

to get an instance of the LibraryFileClass so I can call a function in this class, and I

get the following compile error:

System.Runtime.Serialization.SerializationException: The type LibraryFileNamespace.LibraryFileClass in Assembly LibraryFile,
Version=1.0.2117.26436, Culture=neutral, PublicKeyToken=null is not marked as serializable.

Can someone explain to me why am I getting this error and how I can fix it?
 
N

Nicholas Paldino [.NET/C# MVP]

Max,

When you create an instance in another app domain, you have to either
serialize the object when you use it in your current app domain, or have it
derive from MarshalByRefObject so that you can access it through a proxy.

If you want the instance of the object to live in the new application
domain, then you have to have that object derive from MarshalByRefObject.
This means that all calls to the object will be forwarded through a proxy to
that app domain. Otherwise, it has to be serializable, and all calls will
be on a copy created in the local domain.

Hope this helps.
 
M

Max

Got it, thanks.



Nicholas Paldino said:
Max,

When you create an instance in another app domain, you have to either
serialize the object when you use it in your current app domain, or have it
derive from MarshalByRefObject so that you can access it through a proxy.

If you want the instance of the object to live in the new application
domain, then you have to have that object derive from MarshalByRefObject.
This means that all calls to the object will be forwarded through a proxy to
that app domain. Otherwise, it has to be serializable, and all calls will
be on a copy created in the local domain.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Max said:
I'm using CreateInstanceAndUnwrap as follows:

object myinstance = myAppDomain.CreateInstanceAndUnwrap("LibraryFile",
"LibraryFileNamespace.LibraryFileClass", true, 0, null, null, null, null,
null);

to get an instance of the LibraryFileClass so I can call a function in
this class, and I

get the following compile error:

System.Runtime.Serialization.SerializationException: The type
LibraryFileNamespace.LibraryFileClass in Assembly LibraryFile,
Version=1.0.2117.26436, Culture=neutral, PublicKeyToken=null is not marked
as serializable.

Can someone explain to me why am I getting this error and how I can fix
it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top