[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Re: Problem with serializing business object instead of core objects

Ken Kolda

9/17/2004 11:15:00 PM

My guess is that you have defined the RemoteTest class twice -- once in your
server assembly and once in the client assembly. Since the assembly name is
part of the full name of a class (which is passed as part of the
serialization info), these type definitions will not be recognized as the
same, even if the namespaces and the class names are exactly the same in the
client and server assemblies. To solve this, put this class definition in a
separate assembly which will be shared by both client and server.

That said, it looks like you must already be doing this to some degree since
your able to use the IApptikRemoteCache interface (which I assume is in a
separate assembly). So, if what I described above isn't the problem, let me
know.

Ken


"Alex" <Alex@discussions.microsoft.com> wrote in message
news:C7DC2C7D-30D4-457B-95E4-418037C0FE7F@microsoft.com...
> I have created a simple remoting client-server setup where I am having
> problems when attempting to deal with business objects. If I run the
client
> and server, and pass in a standard object such as a string, integer, guid,
> etc., everything works fine. However, if I try to pass in a business
object
> that I have marked as serializable, I get the following error:
>
> Unable to find assembly '__codeyqhbdlhs, Version=0.0.0.0, Culture=neutral,
> PublicKeyToken=null'.
>
> I have marked the business object as serializable and to test, I created a
> simple business object that just has a couple of string fields. The error
> also appears to occur when I try to run deserialize or serialize directly
on
> an object instead of allowing the framework to handle the serialization so
> the problem seems to be serialization. The same error occurs whether I
use
> Binary or SOAP formatters. I am running my server as a windows app. The
> relevant code to activate remoting on the server is as follows:
>
> private void button1_Click(object sender, EventArgs e)
> {
> BinaryServerFormatterSinkProvider ServerProvider = new
> BinaryServerFormatterSinkProvider();
> TcpServerChannel tsc = new TcpServerChannel("TCPChannel",
7777,
> ServerProvider);
> ChannelServices.RegisterChannel(tsc);
>
>
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ApptikRemoteObject
), "ApptikCache", WellKnownObjectMode.SingleCall);
>
> infobox.Items.Add("Initializing cache server initialized");
>
>
> stopped = false;
>
> }
>
> }
>
>
> The relevant client portion is run from an asp page and is as follows:
>
> Global.asax
> System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider
> ClientProvider = new
> System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
> System.Runtime.Remoting.Channels.Tcp.TcpClientChannel tsc = new
> System.Runtime.Remoting.Channels.Tcp.TcpClientChannel("TCPChannel",
> ClientProvider);
>
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tsc);
>
> appobject.aspx
>
> IApptikRemoteCache remoteobj =
> (IApptikRemoteCache)Activator.GetObject(typeof(IApptikRemoteCache),
> "tcp://localhost:7777/ApptikCache");
>
> RemoteTest findtestvalue = (RemoteTest)
> remoteobj.Find("RemoteTestTest11");
> if (findtestvalue == null)
> {
>
> HttpContext.Current.Trace.Write("Test not found");
> // if I pass a string in the next line instead of remotetest
object
> // then everything works fine
> RemoteTest test = new RemoteTest();
> remoteobj.Add("RemoteTestTest11", test, null);
> }
> else
> {
>
> HttpContext.Current.Trace.Write("Test " +
> findtestvalue.Test2.ToString());
>
> }
>
> The remote class that I am attempting to pass through is as follows:
>
> [Serializable]
> public class RemoteTest {
>
> private string test = string.Empty;
> private string test2 = string.Empty;
> public string Test2
> {
> get
> {
> return test2;
> }
>
> set
> {
> test2 = value;
> }
> }
>
>
> public RemoteTest()
> {
>
> test2 = "Palookaville";
>
> }
>
> }
>
>
>


5 Answers

Steve L

9/18/2004 3:34:00 PM

0

I was also getting this and it should be noted that if you are using
interfaces (in a separate assembly or not), you will NOT be able to pass by
value (Serialized) but rather will have to derive the base class from
MarshalByRefObejct. The downside to this is that you call the server for
EVERY property get/set and method access, BUT the gain is that you have 0
code implementation deployed to the client.

If you are always calling methods and passing everything needed, then
interfaces may work well for you. I had to change my code to implement those
parts needed at the client (basically just structs to send data back and
forth) in a separate DLL that is used by both the server and client.

Hope this helps a bit, I am new to Remoting but came across this early.

Fred

"Ken Kolda" <ken.kolda@elliemae-nospamplease.com> wrote in message
news:uZfT8wQnEHA.3076@TK2MSFTNGP15.phx.gbl...
> My guess is that you have defined the RemoteTest class twice -- once in
your
> server assembly and once in the client assembly. Since the assembly name
is
> part of the full name of a class (which is passed as part of the
> serialization info), these type definitions will not be recognized as the
> same, even if the namespaces and the class names are exactly the same in
the
> client and server assemblies. To solve this, put this class definition in
a
> separate assembly which will be shared by both client and server.
>
> That said, it looks like you must already be doing this to some degree
since
> your able to use the IApptikRemoteCache interface (which I assume is in a
> separate assembly). So, if what I described above isn't the problem, let
me
> know.
>
> Ken
>
>
> "Alex" <Alex@discussions.microsoft.com> wrote in message
> news:C7DC2C7D-30D4-457B-95E4-418037C0FE7F@microsoft.com...
> > I have created a simple remoting client-server setup where I am having
> > problems when attempting to deal with business objects. If I run the
> client
> > and server, and pass in a standard object such as a string, integer,
guid,
> > etc., everything works fine. However, if I try to pass in a business
> object
> > that I have marked as serializable, I get the following error:
> >
> > Unable to find assembly '__codeyqhbdlhs, Version=0.0.0.0,
Culture=neutral,
> > PublicKeyToken=null'.
> >
> > I have marked the business object as serializable and to test, I created
a
> > simple business object that just has a couple of string fields. The
error
> > also appears to occur when I try to run deserialize or serialize
directly
> on
> > an object instead of allowing the framework to handle the serialization
so
> > the problem seems to be serialization. The same error occurs whether I
> use
> > Binary or SOAP formatters. I am running my server as a windows app.
The
> > relevant code to activate remoting on the server is as follows:
> >
> > private void button1_Click(object sender, EventArgs e)
> > {
> > BinaryServerFormatterSinkProvider ServerProvider = new
> > BinaryServerFormatterSinkProvider();
> > TcpServerChannel tsc = new TcpServerChannel("TCPChannel",
> 7777,
> > ServerProvider);
> > ChannelServices.RegisterChannel(tsc);
> >
> >
>
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ApptikRemoteObject
> ), "ApptikCache", WellKnownObjectMode.SingleCall);
> >
> > infobox.Items.Add("Initializing cache server initialized");
> >
> >
> > stopped = false;
> >
> > }
> >
> > }
> >
> >
> > The relevant client portion is run from an asp page and is as follows:
> >
> > Global.asax
> >
System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider
> > ClientProvider = new
> > System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
> > System.Runtime.Remoting.Channels.Tcp.TcpClientChannel tsc = new
> > System.Runtime.Remoting.Channels.Tcp.TcpClientChannel("TCPChannel",
> > ClientProvider);
> >
> System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tsc);
> >
> > appobject.aspx
> >
> > IApptikRemoteCache remoteobj =
> > (IApptikRemoteCache)Activator.GetObject(typeof(IApptikRemoteCache),
> > "tcp://localhost:7777/ApptikCache");
> >
> > RemoteTest findtestvalue = (RemoteTest)
> > remoteobj.Find("RemoteTestTest11");
> > if (findtestvalue == null)
> > {
> >
> > HttpContext.Current.Trace.Write("Test not found");
> > // if I pass a string in the next line instead of remotetest
> object
> > // then everything works fine
> > RemoteTest test = new RemoteTest();
> > remoteobj.Add("RemoteTestTest11", test, null);
> > }
> > else
> > {
> >
> > HttpContext.Current.Trace.Write("Test " +
> > findtestvalue.Test2.ToString());
> >
> > }
> >
> > The remote class that I am attempting to pass through is as follows:
> >
> > [Serializable]
> > public class RemoteTest {
> >
> > private string test = string.Empty;
> > private string test2 = string.Empty;
> > public string Test2
> > {
> > get
> > {
> > return test2;
> > }
> >
> > set
> > {
> > test2 = value;
> > }
> > }
> >
> >
> > public RemoteTest()
> > {
> >
> > test2 = "Palookaville";
> >
> > }
> >
> > }
> >
> >
> >
>
>


alex

9/18/2004 4:53:00 PM

0

I actually only have the remotetest class defined in the client because this
is what I pass back and forth between client and server but it is not defined
on the server. The server simply holds the value as an object that is passed
to it so it does not need to have remotetest defined. The remoting class
that I call is definied at the server within the server app and is in a
separate assembly as an interface for the client. Initially, I had the
remoting class in a separate assembly dll that was used by the client and the
server and I had the same problems.

Oh, duh. I just think I figured it out. I may be an idiot. I do not have
the business class that is being serialized defined at the server end. I am
guessing that the server needs to know what the class definition is in order
to properly deserialize the class. Am I right?

Thanks,

Alex

"Ken Kolda" wrote:

> My guess is that you have defined the RemoteTest class twice -- once in your
> server assembly and once in the client assembly. Since the assembly name is
> part of the full name of a class (which is passed as part of the
> serialization info), these type definitions will not be recognized as the
> same, even if the namespaces and the class names are exactly the same in the
> client and server assemblies. To solve this, put this class definition in a
> separate assembly which will be shared by both client and server.
>
> That said, it looks like you must already be doing this to some degree since
> your able to use the IApptikRemoteCache interface (which I assume is in a
> separate assembly). So, if what I described above isn't the problem, let me
> know.
>
> Ken
>
>
> "Alex" <Alex@discussions.microsoft.com> wrote in message
> news:C7DC2C7D-30D4-457B-95E4-418037C0FE7F@microsoft.com...
> > I have created a simple remoting client-server setup where I am having
> > problems when attempting to deal with business objects. If I run the
> client
> > and server, and pass in a standard object such as a string, integer, guid,
> > etc., everything works fine. However, if I try to pass in a business
> object
> > that I have marked as serializable, I get the following error:
> >
> > Unable to find assembly '__codeyqhbdlhs, Version=0.0.0.0, Culture=neutral,
> > PublicKeyToken=null'.
> >
> > I have marked the business object as serializable and to test, I created a
> > simple business object that just has a couple of string fields. The error
> > also appears to occur when I try to run deserialize or serialize directly
> on
> > an object instead of allowing the framework to handle the serialization so
> > the problem seems to be serialization. The same error occurs whether I
> use
> > Binary or SOAP formatters. I am running my server as a windows app. The
> > relevant code to activate remoting on the server is as follows:
> >
> > private void button1_Click(object sender, EventArgs e)
> > {
> > BinaryServerFormatterSinkProvider ServerProvider = new
> > BinaryServerFormatterSinkProvider();
> > TcpServerChannel tsc = new TcpServerChannel("TCPChannel",
> 7777,
> > ServerProvider);
> > ChannelServices.RegisterChannel(tsc);
> >
> >
> RemotingConfiguration.RegisterWellKnownServiceType(typeof(ApptikRemoteObject
> ), "ApptikCache", WellKnownObjectMode.SingleCall);
> >
> > infobox.Items.Add("Initializing cache server initialized");
> >
> >
> > stopped = false;
> >
> > }
> >
> > }
> >
> >
> > The relevant client portion is run from an asp page and is as follows:
> >
> > Global.asax
> > System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider
> > ClientProvider = new
> > System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
> > System.Runtime.Remoting.Channels.Tcp.TcpClientChannel tsc = new
> > System.Runtime.Remoting.Channels.Tcp.TcpClientChannel("TCPChannel",
> > ClientProvider);
> >
> System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tsc);
> >
> > appobject.aspx
> >
> > IApptikRemoteCache remoteobj =
> > (IApptikRemoteCache)Activator.GetObject(typeof(IApptikRemoteCache),
> > "tcp://localhost:7777/ApptikCache");
> >
> > RemoteTest findtestvalue = (RemoteTest)
> > remoteobj.Find("RemoteTestTest11");
> > if (findtestvalue == null)
> > {
> >
> > HttpContext.Current.Trace.Write("Test not found");
> > // if I pass a string in the next line instead of remotetest
> object
> > // then everything works fine
> > RemoteTest test = new RemoteTest();
> > remoteobj.Add("RemoteTestTest11", test, null);
> > }
> > else
> > {
> >
> > HttpContext.Current.Trace.Write("Test " +
> > findtestvalue.Test2.ToString());
> >
> > }
> >
> > The remote class that I am attempting to pass through is as follows:
> >
> > [Serializable]
> > public class RemoteTest {
> >
> > private string test = string.Empty;
> > private string test2 = string.Empty;
> > public string Test2
> > {
> > get
> > {
> > return test2;
> > }
> >
> > set
> > {
> > test2 = value;
> > }
> > }
> >
> >
> > public RemoteTest()
> > {
> >
> > test2 = "Palookaville";
> >
> > }
> >
> > }
> >
> >
> >
>
>
>

alex

9/18/2004 7:35:00 PM

0

OK, I still don't think I've solved this. Since I am marking the class as
Serializable, this marshals by value which would mean they don't need to have
a remote identity. If I derive from MarshalByRef, wouldn't I then have to
insure the class does have a remote identity on the server? I don't want to
do this since the server does not need to know the type of object I am
passing and will, in fact, be passed a number of different object types which
are just going to get stored in cache and then returned to the client when
requested.

I have a feeling I am misunderstanding something pretty fundamental with
remoting, but not sure what it is. Thanks for bearing with me.

Alex

"Ken Kolda" wrote:

> My guess is that you have defined the RemoteTest class twice -- once in your
> server assembly and once in the client assembly. Since the assembly name is
> part of the full name of a class (which is passed as part of the
> serialization info), these type definitions will not be recognized as the
> same, even if the namespaces and the class names are exactly the same in the
> client and server assemblies. To solve this, put this class definition in a
> separate assembly which will be shared by both client and server.
>
> That said, it looks like you must already be doing this to some degree since
> your able to use the IApptikRemoteCache interface (which I assume is in a
> separate assembly). So, if what I described above isn't the problem, let me
> know.
>
> Ken
>
>
> "Alex" <Alex@discussions.microsoft.com> wrote in message
> news:C7DC2C7D-30D4-457B-95E4-418037C0FE7F@microsoft.com...
> > I have created a simple remoting client-server setup where I am having
> > problems when attempting to deal with business objects. If I run the
> client
> > and server, and pass in a standard object such as a string, integer, guid,
> > etc., everything works fine. However, if I try to pass in a business
> object
> > that I have marked as serializable, I get the following error:
> >
> > Unable to find assembly '__codeyqhbdlhs, Version=0.0.0.0, Culture=neutral,
> > PublicKeyToken=null'.
> >
> > I have marked the business object as serializable and to test, I created a
> > simple business object that just has a couple of string fields. The error
> > also appears to occur when I try to run deserialize or serialize directly
> on
> > an object instead of allowing the framework to handle the serialization so
> > the problem seems to be serialization. The same error occurs whether I
> use
> > Binary or SOAP formatters. I am running my server as a windows app. The
> > relevant code to activate remoting on the server is as follows:
> >
> > private void button1_Click(object sender, EventArgs e)
> > {
> > BinaryServerFormatterSinkProvider ServerProvider = new
> > BinaryServerFormatterSinkProvider();
> > TcpServerChannel tsc = new TcpServerChannel("TCPChannel",
> 7777,
> > ServerProvider);
> > ChannelServices.RegisterChannel(tsc);
> >
> >
> RemotingConfiguration.RegisterWellKnownServiceType(typeof(ApptikRemoteObject
> ), "ApptikCache", WellKnownObjectMode.SingleCall);
> >
> > infobox.Items.Add("Initializing cache server initialized");
> >
> >
> > stopped = false;
> >
> > }
> >
> > }
> >
> >
> > The relevant client portion is run from an asp page and is as follows:
> >
> > Global.asax
> > System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider
> > ClientProvider = new
> > System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
> > System.Runtime.Remoting.Channels.Tcp.TcpClientChannel tsc = new
> > System.Runtime.Remoting.Channels.Tcp.TcpClientChannel("TCPChannel",
> > ClientProvider);
> >
> System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tsc);
> >
> > appobject.aspx
> >
> > IApptikRemoteCache remoteobj =
> > (IApptikRemoteCache)Activator.GetObject(typeof(IApptikRemoteCache),
> > "tcp://localhost:7777/ApptikCache");
> >
> > RemoteTest findtestvalue = (RemoteTest)
> > remoteobj.Find("RemoteTestTest11");
> > if (findtestvalue == null)
> > {
> >
> > HttpContext.Current.Trace.Write("Test not found");
> > // if I pass a string in the next line instead of remotetest
> object
> > // then everything works fine
> > RemoteTest test = new RemoteTest();
> > remoteobj.Add("RemoteTestTest11", test, null);
> > }
> > else
> > {
> >
> > HttpContext.Current.Trace.Write("Test " +
> > findtestvalue.Test2.ToString());
> >
> > }
> >
> > The remote class that I am attempting to pass through is as follows:
> >
> > [Serializable]
> > public class RemoteTest {
> >
> > private string test = string.Empty;
> > private string test2 = string.Empty;
> > public string Test2
> > {
> > get
> > {
> > return test2;
> > }
> >
> > set
> > {
> > test2 = value;
> > }
> > }
> >
> >
> > public RemoteTest()
> > {
> >
> > test2 = "Palookaville";
> >
> > }
> >
> > }
> >
> >
> >
>
>
>

Robert Jordan

9/18/2004 9:15:00 PM

0

Alex wrote:

> OK, I still don't think I've solved this. Since I am marking the class as
> Serializable, this marshals by value which would mean they don't need to have
> a remote identity. If I derive from MarshalByRef, wouldn't I then have to
> insure the class does have a remote identity on the server? I don't want to
> do this since the server does not need to know the type of object I am
> passing and will, in fact, be passed a number of different object types which
> are just going to get stored in cache and then returned to the client when
> requested.

If you want to cache objects of types the server doesn't
know about, than you have to serialize the objects
on the client and send them as binary data to the server.

you can even send the objects as a string using that
method:


/// <summary>
/// Converts a serializable object to a base64 coded string
/// representation of the serialized data.
/// </summary>
/// <param name="data"></param>
/// <exception cref="SerializationException">The data is not
serializable.
/// </exception>
/// <returns></returns>
public static string SerializeToBase64(object data)
{
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, data);
stream.Position = 0;
return Convert.ToBase64String(stream.ToArray());
}


/// <summary>
/// Deserializes a string previously written by SerializeToString.
/// </summary>
/// <param name="data">The Base64 string.</param>
/// <exception cref="FormatException">The specified string is
not Base64-coded.</exception>
/// <exception cref="SerializationException">The data cannot be
deserialized.</exception>
/// <returns></returns>
public static object DeserializeFromBase64(string data,
SerializationBinder binder)
{
MemoryStream stream = new
MemoryStream(Convert.FromBase64String(data));
stream.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
return formatter.Deserialize(stream);
}


bye
rob



>
> I have a feeling I am misunderstanding something pretty fundamental with
> remoting, but not sure what it is. Thanks for bearing with me.
>
> Alex
>
> "Ken Kolda" wrote:
>
>
>>My guess is that you have defined the RemoteTest class twice -- once in your
>>server assembly and once in the client assembly. Since the assembly name is
>>part of the full name of a class (which is passed as part of the
>>serialization info), these type definitions will not be recognized as the
>>same, even if the namespaces and the class names are exactly the same in the
>>client and server assemblies. To solve this, put this class definition in a
>>separate assembly which will be shared by both client and server.
>>
>>That said, it looks like you must already be doing this to some degree since
>>your able to use the IApptikRemoteCache interface (which I assume is in a
>>separate assembly). So, if what I described above isn't the problem, let me
>>know.
>>
>>Ken
>>
>>
>>"Alex" <Alex@discussions.microsoft.com> wrote in message
>>news:C7DC2C7D-30D4-457B-95E4-418037C0FE7F@microsoft.com...
>>
>>>I have created a simple remoting client-server setup where I am having
>>>problems when attempting to deal with business objects. If I run the
>>
>>client
>>
>>>and server, and pass in a standard object such as a string, integer, guid,
>>>etc., everything works fine. However, if I try to pass in a business
>>
>>object
>>
>>>that I have marked as serializable, I get the following error:
>>>
>>>Unable to find assembly '__codeyqhbdlhs, Version=0.0.0.0, Culture=neutral,
>>>PublicKeyToken=null'.
>>>
>>>I have marked the business object as serializable and to test, I created a
>>>simple business object that just has a couple of string fields. The error
>>>also appears to occur when I try to run deserialize or serialize directly
>>
>>on
>>
>>>an object instead of allowing the framework to handle the serialization so
>>>the problem seems to be serialization. The same error occurs whether I
>>
>>use
>>
>>>Binary or SOAP formatters. I am running my server as a windows app. The
>>>relevant code to activate remoting on the server is as follows:
>>>
>>> private void button1_Click(object sender, EventArgs e)
>>> {
>>> BinaryServerFormatterSinkProvider ServerProvider = new
>>>BinaryServerFormatterSinkProvider();
>>> TcpServerChannel tsc = new TcpServerChannel("TCPChannel",
>>
>>7777,
>>
>>>ServerProvider);
>>> ChannelServices.RegisterChannel(tsc);
>>>
>>>
>>
>>RemotingConfiguration.RegisterWellKnownServiceType(typeof(ApptikRemoteObject
>>), "ApptikCache", WellKnownObjectMode.SingleCall);
>>
>>> infobox.Items.Add("Initializing cache server initialized");
>>>
>>>
>>> stopped = false;
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>The relevant client portion is run from an asp page and is as follows:
>>>
>>>Global.asax
>>> System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider
>>>ClientProvider = new
>>>System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
>>> System.Runtime.Remoting.Channels.Tcp.TcpClientChannel tsc = new
>>>System.Runtime.Remoting.Channels.Tcp.TcpClientChannel("TCPChannel",
>>>ClientProvider);
>>>
>>
>>System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tsc);
>>
>>>appobject.aspx
>>>
>>> IApptikRemoteCache remoteobj =
>>>(IApptikRemoteCache)Activator.GetObject(typeof(IApptikRemoteCache),
>>>"tcp://localhost:7777/ApptikCache");
>>>
>>> RemoteTest findtestvalue = (RemoteTest)
>>>remoteobj.Find("RemoteTestTest11");
>>> if (findtestvalue == null)
>>> {
>>>
>>> HttpContext.Current.Trace.Write("Test not found");
>>> // if I pass a string in the next line instead of remotetest
>>
>>object
>>
>>> // then everything works fine
>>> RemoteTest test = new RemoteTest();
>>> remoteobj.Add("RemoteTestTest11", test, null);
>>> }
>>> else
>>> {
>>>
>>> HttpContext.Current.Trace.Write("Test " +
>>>findtestvalue.Test2.ToString());
>>>
>>> }
>>>
>>>The remote class that I am attempting to pass through is as follows:
>>>
>>>[Serializable]
>>>public class RemoteTest {
>>>
>>> private string test = string.Empty;
>>> private string test2 = string.Empty;
>>> public string Test2
>>> {
>>> get
>>> {
>>> return test2;
>>> }
>>>
>>> set
>>> {
>>> test2 = value;
>>> }
>>> }
>>>
>>>
>>> public RemoteTest()
>>> {
>>>
>>> test2 = "Palookaville";
>>>
>>> }
>>>
>>>}
>>>
>>>
>>>
>>
>>
>>

alex

9/18/2004 11:55:00 PM

0

I get the error when using the methods you provided below. However, I have
narrowed the issue down. The error seems to appear during deserialization
only after I have recompiled the asp app but not restarted the server. The
purpose of our remoting setup is to create a centralized caching server for
our business objects. The client sends an object to the server and the
server holds the object in memory until one of the servers in the web farm
request it again.

Everything works fine if I clear out the cache on the server and then
recompile the asp end. It also works fine if I stop and restart the server
end since the objects just get cleanly populated. However, if I recompile
the asp application, and the client attempts to deserialize an object that
already exists in the server, then the error occurs again.

So I am guessing there is either a security context that gets applied to the
serialized object that can't be deserialized by a new instance of the asp
application, or that the remoting proxy gets rebuilt when recompiled and that
the rebuilt proxy does not have the same signature as the proxy that
generated the object. Does that make sense, and where might I look to
pinpoint the problem?

Thanks,

Alex

"Robert Jordan" wrote:

> Alex wrote:
>
> > OK, I still don't think I've solved this. Since I am marking the class as
> > Serializable, this marshals by value which would mean they don't need to have
> > a remote identity. If I derive from MarshalByRef, wouldn't I then have to
> > insure the class does have a remote identity on the server? I don't want to
> > do this since the server does not need to know the type of object I am
> > passing and will, in fact, be passed a number of different object types which
> > are just going to get stored in cache and then returned to the client when
> > requested.
>
> If you want to cache objects of types the server doesn't
> know about, than you have to serialize the objects
> on the client and send them as binary data to the server.
>
> you can even send the objects as a string using that
> method:
>
>
> /// <summary>
> /// Converts a serializable object to a base64 coded string
> /// representation of the serialized data.
> /// </summary>
> /// <param name="data"></param>
> /// <exception cref="SerializationException">The data is not
> serializable.
> /// </exception>
> /// <returns></returns>
> public static string SerializeToBase64(object data)
> {
> MemoryStream stream = new MemoryStream();
> BinaryFormatter formatter = new BinaryFormatter();
> formatter.Serialize(stream, data);
> stream.Position = 0;
> return Convert.ToBase64String(stream.ToArray());
> }
>
>
> /// <summary>
> /// Deserializes a string previously written by SerializeToString.
> /// </summary>
> /// <param name="data">The Base64 string.</param>
> /// <exception cref="FormatException">The specified string is
> not Base64-coded.</exception>
> /// <exception cref="SerializationException">The data cannot be
> deserialized.</exception>
> /// <returns></returns>
> public static object DeserializeFromBase64(string data,
> SerializationBinder binder)
> {
> MemoryStream stream = new
> MemoryStream(Convert.FromBase64String(data));
> stream.Position = 0;
> BinaryFormatter formatter = new BinaryFormatter();
> return formatter.Deserialize(stream);
> }
>
>
> bye
> rob
>
>
>
> >
> > I have a feeling I am misunderstanding something pretty fundamental with
> > remoting, but not sure what it is. Thanks for bearing with me.
> >
> > Alex
> >
> > "Ken Kolda" wrote:
> >
> >
> >>My guess is that you have defined the RemoteTest class twice -- once in your
> >>server assembly and once in the client assembly. Since the assembly name is
> >>part of the full name of a class (which is passed as part of the
> >>serialization info), these type definitions will not be recognized as the
> >>same, even if the namespaces and the class names are exactly the same in the
> >>client and server assemblies. To solve this, put this class definition in a
> >>separate assembly which will be shared by both client and server.
> >>
> >>That said, it looks like you must already be doing this to some degree since
> >>your able to use the IApptikRemoteCache interface (which I assume is in a
> >>separate assembly). So, if what I described above isn't the problem, let me
> >>know.
> >>
> >>Ken
> >>
> >>
> >>"Alex" <Alex@discussions.microsoft.com> wrote in message
> >>news:C7DC2C7D-30D4-457B-95E4-418037C0FE7F@microsoft.com...
> >>
> >>>I have created a simple remoting client-server setup where I am having
> >>>problems when attempting to deal with business objects. If I run the
> >>
> >>client
> >>
> >>>and server, and pass in a standard object such as a string, integer, guid,
> >>>etc., everything works fine. However, if I try to pass in a business
> >>
> >>object
> >>
> >>>that I have marked as serializable, I get the following error:
> >>>
> >>>Unable to find assembly '__codeyqhbdlhs, Version=0.0.0.0, Culture=neutral,
> >>>PublicKeyToken=null'.
> >>>
> >>>I have marked the business object as serializable and to test, I created a
> >>>simple business object that just has a couple of string fields. The error
> >>>also appears to occur when I try to run deserialize or serialize directly
> >>
> >>on
> >>
> >>>an object instead of allowing the framework to handle the serialization so
> >>>the problem seems to be serialization. The same error occurs whether I
> >>
> >>use
> >>
> >>>Binary or SOAP formatters. I am running my server as a windows app. The
> >>>relevant code to activate remoting on the server is as follows:
> >>>
> >>> private void button1_Click(object sender, EventArgs e)
> >>> {
> >>> BinaryServerFormatterSinkProvider ServerProvider = new
> >>>BinaryServerFormatterSinkProvider();
> >>> TcpServerChannel tsc = new TcpServerChannel("TCPChannel",
> >>
> >>7777,
> >>
> >>>ServerProvider);
> >>> ChannelServices.RegisterChannel(tsc);
> >>>
> >>>
> >>
> >>RemotingConfiguration.RegisterWellKnownServiceType(typeof(ApptikRemoteObject
> >>), "ApptikCache", WellKnownObjectMode.SingleCall);
> >>
> >>> infobox.Items.Add("Initializing cache server initialized");
> >>>
> >>>
> >>> stopped = false;
> >>>
> >>> }
> >>>
> >>> }
> >>>
> >>>
> >>>The relevant client portion is run from an asp page and is as follows:
> >>>
> >>>Global.asax
> >>> System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider
> >>>ClientProvider = new
> >>>System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider();
> >>> System.Runtime.Remoting.Channels.Tcp.TcpClientChannel tsc = new
> >>>System.Runtime.Remoting.Channels.Tcp.TcpClientChannel("TCPChannel",
> >>>ClientProvider);
> >>>
> >>
> >>System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tsc);
> >>
> >>>appobject.aspx
> >>>
> >>> IApptikRemoteCache remoteobj =
> >>>(IApptikRemoteCache)Activator.GetObject(typeof(IApptikRemoteCache),
> >>>"tcp://localhost:7777/ApptikCache");
> >>>
> >>> RemoteTest findtestvalue = (RemoteTest)
> >>>remoteobj.Find("RemoteTestTest11");
> >>> if (findtestvalue == null)
> >>> {
> >>>
> >>> HttpContext.Current.Trace.Write("Test not found");
> >>> // if I pass a string in the next line instead of remotetest
> >>
> >>object
> >>
> >>> // then everything works fine
> >>> RemoteTest test = new RemoteTest();
> >>> remoteobj.Add("RemoteTestTest11", test, null);
> >>> }
> >>> else
> >>> {
> >>>
> >>> HttpContext.Current.Trace.Write("Test " +
> >>>findtestvalue.Test2.ToString());
> >>>
> >>> }
> >>>
> >>>The remote class that I am attempting to pass through is as follows:
> >>>
> >>>[Serializable]
> >>>public class RemoteTest {
> >>>
> >>> private string test = string.Empty;
> >>> private string test2 = string.Empty;
> >>> public string Test2
> >>> {
> >>> get
> >>> {
> >>> return test2;
> >>> }
> >>>
> >>> set
> >>> {
> >>> test2 = value;
> >>> }
> >>> }
> >>>
> >>>
> >>> public RemoteTest()
> >>> {
> >>>
> >>> test2 = "Palookaville";
> >>>
> >>> }
> >>>
> >>>}
> >>>
> >>>
> >>>
> >>
> >>
> >>
>