[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

Deserialization exception when using MarshalByRef object with events

scayze

10/27/2004 6:50:00 PM

Hello all,

I'm getting the following exception on the client when attempting to
assign a delegate to a MarshalByRefObject's event on the server:

"An unhandled exception of type 'System.Security.SecurityException'
occurred in mscorlib.dll

Additional information: Type System.DelegateSerializationHolder and
the types derived from it (such as System.DelegateSerializationHolder)
are not permitted to be deserialized at this security level."

I saw all sorts of documentation telling me to change the
typeFilterLevel to full, either in a .config file or in code. I've
tried it both ways and it still doesn't work. Here are the key parts
of code from the server, client, MarshalByRef object, and .config
files:

***************** Server code **************************

public class Server
{
.
.
public void Start()
{
RemotingConfiguration.Configure("Server.exe.config");
}
.
.
}

***************** Client code **************************

public class Client
{
.
.
public void Start()
{
RemotingConfiguration.Configure("Client.exe.config");
Bomb bomb = new Bomb();
bomb.BombDetonated += new BombHandler(BombDetonated);
bomb.Detonate();
}

private void BombDetonated(Bomb bomb)
{
Console.WriteLine("Bomb Detonated");
}
.
.
}

***************** MarshalByRefObject code **************************

public class Bomb : MarshalByRefObject
{
public delegate void BombHandler(Bomb bomb);
public event BombHandler BombDetonated;
public event BombHandler BombDiffused;

public void Detonate() {...}
public void Diffuse() {...}
}


***************** Server.exe.config **************************

<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="Tcp" port="4000" />
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channels>

<service>
<wellknown mode="Singleton" type="SharedObjects.Bomb,
SharedObjects"
objectUri="Bomb.rem" />
</service>
</application>
</system.runtime.remoting>
</configuration>

***************** Client.exe.config **************************

<configuration>
<system.runtime.remoting>
<application>

<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>

<client>
<wellknown type="SharedObjects.Bomb, SharedObjects"
url="Tcp://localhost:4000/Bomb.rem" />
</client>

</application>
</system.runtime.remoting>
</configuration>

*********************************************************

Also, if I start the program without debugging, part of the exception
refers to the Microsoft .Net security policy and altering it. Can
anyone tell me what I'm doing wrong? I've seen many threads where
people have gotten it to work, so I know it's possible, but I think
I'm missing something small.

Thanks in advance,
Shannon
2 Answers

Ken Kolda

10/27/2004 7:07:00 PM

0

In your server's config file you have the <serverProviders> element outside
of the <channel> element. It should be inside (as you have it in yoyur
client's config file).

<channel ref="tcp" port="4000">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>

Ken


"Shannon Cayze" <scayze@us.loreal.com> wrote in message
news:f9c7c737.0410271050.71e5971a@posting.google.com...
> Hello all,
>
> I'm getting the following exception on the client when attempting to
> assign a delegate to a MarshalByRefObject's event on the server:
>
> "An unhandled exception of type 'System.Security.SecurityException'
> occurred in mscorlib.dll
>
> Additional information: Type System.DelegateSerializationHolder and
> the types derived from it (such as System.DelegateSerializationHolder)
> are not permitted to be deserialized at this security level."
>
> I saw all sorts of documentation telling me to change the
> typeFilterLevel to full, either in a .config file or in code. I've
> tried it both ways and it still doesn't work. Here are the key parts
> of code from the server, client, MarshalByRef object, and .config
> files:
>
> ***************** Server code **************************
>
> public class Server
> {
> .
> .
> public void Start()
> {
> RemotingConfiguration.Configure("Server.exe.config");
> }
> .
> .
> }
>
> ***************** Client code **************************
>
> public class Client
> {
> .
> .
> public void Start()
> {
> RemotingConfiguration.Configure("Client.exe.config");
> Bomb bomb = new Bomb();
> bomb.BombDetonated += new BombHandler(BombDetonated);
> bomb.Detonate();
> }
>
> private void BombDetonated(Bomb bomb)
> {
> Console.WriteLine("Bomb Detonated");
> }
> .
> .
> }
>
> ***************** MarshalByRefObject code **************************
>
> public class Bomb : MarshalByRefObject
> {
> public delegate void BombHandler(Bomb bomb);
> public event BombHandler BombDetonated;
> public event BombHandler BombDiffused;
>
> public void Detonate() {...}
> public void Diffuse() {...}
> }
>
>
> ***************** Server.exe.config **************************
>
> <configuration>
> <system.runtime.remoting>
> <application>
> <channels>
> <channel ref="Tcp" port="4000" />
> <serverProviders>
> <formatter ref="binary" typeFilterLevel="Full" />
> </serverProviders>
> </channels>
>
> <service>
> <wellknown mode="Singleton" type="SharedObjects.Bomb,
> SharedObjects"
> objectUri="Bomb.rem" />
> </service>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> ***************** Client.exe.config **************************
>
> <configuration>
> <system.runtime.remoting>
> <application>
>
> <channels>
> <channel ref="tcp" port="0">
> <clientProviders>
> <formatter ref="binary" />
> </clientProviders>
> <serverProviders>
> <formatter ref="binary" typeFilterLevel="Full" />
> </serverProviders>
> </channel>
> </channels>
>
> <client>
> <wellknown type="SharedObjects.Bomb, SharedObjects"
> url="Tcp://localhost:4000/Bomb.rem" />
> </client>
>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> *********************************************************
>
> Also, if I start the program without debugging, part of the exception
> refers to the Microsoft .Net security policy and altering it. Can
> anyone tell me what I'm doing wrong? I've seen many threads where
> people have gotten it to work, so I know it's possible, but I think
> I'm missing something small.
>
> Thanks in advance,
> Shannon


Shannon Cayze

10/27/2004 7:33:00 PM

0

Thank you so much Ken. That seems to have fixed it. I have another
exception with the versioning of the assembly, but I think that's
totally unrelated. I can't believe I missed something that simple.

Thanks again for all your help,
Shannon

*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!