System.Runtime.Serialization.SerializationException: Because of security restrictions, the t

I have this .NET Remoting stuff i'm currently trying for my company since we have an idea of using .NET Remoting in the next version of our application. The basic is a windows form application as client and IIS as host for our objects. After i have been through several examples, guide, tutorials and so on i got it to work, but nothing lasts forever. When i bind the List<T> i get from our remoting to a BindingSource i get an exception in my Dispose on the form every time i try to close my window.

The layout of my form is very very simple a form (offcourse), a bindingsource, and a datagridview.

My form:

public partial class Form1 : Form
{
ServiceClass service;
List<Tags> tList = null;

public Form1()
{
InitializeComponent( );

RemotingConfiguration.Configure( "SimpleFormClient.exe.config", false );

service = new ServiceClass( );
}

private void Form1_Load( object sender, EventArgs e )
{
tList = service.GetAllTags();

bindingSource1.DataSource = tList;
}
}

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="http" useDefaultCredentials="true" port="0">
<clientProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</clientProviders>
</channel>
</channels>
<client>
<wellknown url="http://localhost/Remoting/SAService.rem" type="ServiceClass, ServiceClass" />
</client>
</application>
</system.runtime.remoting>
</configuration>

Server is simple as far as i can see

web.config is like:

<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" objectUri="SAService.rem" type="ServiceClass, ServiceClass"/>
</service>
<channels>
<channel name="http ServiceClass" ref="http">
<serverProvider>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProvider>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

The problem is now that i get following exception, and i have not been able to find any answers to my questions anywhere

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.Serialization.SerializationException: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed. > System.Security.SecurityException: Request failed.
at System.Runtime.Serialization.FormatterServices.nativeGetSafeUninitializedObject(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Infrastructure"/>

The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Infrastructure"/>
</PermissionSet>

The only permitted permissions were:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="SerializationFormatter"/>
</PermissionSet>

The method that caused the failure was:
System.Runtime.Remoting.Channels.ServerProcessing ProcessMessage(System.Runtime.Remoting.Channels.IServerChannelSinkStack, System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Channels.ITransportHeaders, System.IO.Stream, System.Runtime.Remoting.Messaging.IMessage ByRef, System.Runtime.Remoting.Channels.ITransportHeaders ByRef, System.IO.Stream ByRef)
End of inner exception stack trace

Server stack trace:
at System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObject(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at DomainObjects.Facade.Domain.PersistableObject.Equals(Object obj)
at System.Collections.Hashtable.KeyEquals(Object item, Object key)
at System.Collections.Hashtable.get_Item(Object key)
at System.ComponentModel.PropertyDescriptor.RemoveValueChanged(Object component, EventHandler handler)
at System.ComponentModel.ReflectPropertyDescriptor.RemoveValueChanged(Object component, EventHandler handler)
at System.Windows.Forms.BindingSource.UnwirePropertyChangedEvents(Object item)
at System.Windows.Forms.BindingSource.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.ComponentModel.Container.Dispose(Boolean disposing)
at System.ComponentModel.Container.Dispose()
at SimpleFormClient.Form1.Dispose(Boolean disposing) in C:\Projects\dotNET ObjectBinding\DObjTest\SimpleFormClient\Form1.Designer.cs:line 18
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Form.WmClose(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
-
SimpleFormClient
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Projects/dotNET%20ObjectBinding/DObjTest/SimpleFormClient/bin/Debug/SimpleFormClient.exe
-
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
-
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
-
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
-
ObjHandling
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Projects/dotNET%20ObjectBinding/DObjTest/SimpleFormClient/bin/Debug/ObjHandling.DLL
-
DomainObjects.Core
Assembly Version: 1.0.1.0
Win32 Version: 1.0.1.0
CodeBase: file:///C:/Projects/dotNET%20ObjectBinding/DObjTest/SimpleFormClient/bin/Debug/DomainObjects.Core.DLL
-
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
-
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
-
ServiceClass
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Projects/dotNET%20ObjectBinding/DObjTest/SimpleFormClient/bin/Debug/ServiceClass.DLL
-
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
-

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

I haven't got a clue why this fails except that it is probably something about rights but every where i search for answers i only get posts about typeFilterLevel i .net 1.1, but i got that sorted out and i am running 2.0.

[12052 byte] By [StefanDaugaardPoulsen] at [2007-12-26]
# 1

Stefan,

I've recently come across the same problem using .NET 1.1 and was wondering if you've had any success. If so, I'd appreciate hearing how you fixed it. Thanks!

- Joe

JMoore at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 2
The only solution that i have found is binding my data direct to the UI instead of using the BindingSource.
StefanDaugaardPoulsen at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 3
Turns out my error was from a typo in my config file Thanks for the info though. I'm sure it'll come in handy down the road.
JMoore at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 4

Please don't leave me hanging...What was the typo?!

Buzzby at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 5

I believe it was because I had the provider tag outside the channel tag. The configuration parser seems very forgiving (or maybe just very flexible), but it means little mistakes are easy to make.

Try editing your config files in an XML editor like XMLSpy or XMLPad so you can expand/collapse the tags to be sure they're nested correctly.

Hope this helps.

JMoore at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...

.NET Development

Site Classified