Weird, you shouldn't get a "security" exception when a type failed to load,
you should receive a typeload exception.
Also you don't need the type that did the serialization, what you need is
the type you are serializing/deserializing. This type can be installed as a
(preferably) private or as a global assembly, depending your needs. The
SerializationBinder is an option, but IMO shouldn't be used in this case,
it's an option when you need to deserialize to a different version.
Willy.
<no*****@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
| If anyone is interested, I ended up solving this problem.
|
| If you serialize in one app, and want to deserialize in another app, an
| exception will be thrown if dotnet can't load the assembly that did the
| serializing.
|
| Option 1: register the serializing app in the GAC. I didn't try this,
| but I assume it would work
| Option 2: use the SerializationBinder class to effectively fool the
| deserializing app into thinking that it did the serializing:
|
|
| when setting your BinaryFormatter up to deserialize, set the Binder
| property to the class below:
|
| BinaryFormatter b = new BinaryFormatter();
| b.Binder = new FooDeserializationBinder();
| myClasss = (MyClass) b.Deserialize(stream);
|
| sealed class FooDeserializationBinder : SerializationBinder
| {
| public override Type BindToType(string assemblyName, string
| typeName)
| {
| return Type.GetType(typeName + ", " +
| Assembly.GetExecutingAssembly().FullName);
| }
| }
|
|
no*****@yahoo.com wrote:
| Hi Gino,
| >
| This sounds like the same problem I'm seeing. The exception that I'm
| getting complains that it can't find info about the app that did the
| serializing:
| >
| "Cannot find the assembly RegionViewer,
| Version=1.0.2466.11715, Culture=neutral, PublicKeyToken=null."
| >
| where RegionViewer is the app that did the serializing. Do you happen
| to remember what object the property was in? The formatter, or the
| stream itself?
| >
| Thanks,
| Norvin
| >
| >
| >
| Gino wrote:
| I did something similar almost 2 years ago, so I don't remember the
details,
| but I had the same problem that you are having. I was serializing an
object
| and sending it over the network and then deserialized it and was
getting an
| error. After searching on google it turned out that when an app
serializes
| an object it puts some identifying information in a property that the
| deserializing app will not have which is what caused the error. As I
| remember it, I had to set this property to nothing, and that took care
of
| the problem.
|
|
|
| <no*****@yahoo.comwrote in message
| news:11**********************@k70g2000cwa.googlegr oups.com...
| Hi Willy,
| >
| Willy Denoyette [MVP] wrote:
| >>
| ><no*****@yahoo.comwrote in message
| >| A question: I have a class, I have a destination pointer, how can
I do
| >| the equivalent of memcpy( ptrDestination, &myClass,
sizeof(myClass); ?
| >>
| >>
| >You could use a BinaryFormater to serialize the object to a
MemoryStream.
| >Following is a small snip that illustrates how one could go for the
| >serializer, the deserializer should perform the inverse operations.
| >
| What you suggest is exactly what I'm doing at the moment. As my
initial
| post in this thread indicates, I have security issues when I try to
| deserialize a stream that was serialized in another app.
| >
| So:
| - either there is a simple way to get around those security
exceptions.
| After all, I have control of the code for both the app doing the
| serializing as well as the app doing the deserializing.
| - OR there must be a simple way to copy a class to memory without
first
| having to serialize it.
| >
| Any suggestions to accomplish either of the above?
| >
| Norvin
| >
|