all groups > dotnet remoting > march 2006 >
You're in the

dotnet remoting

group:

BindingList<T> and remoting problem (SerializationException).


BindingList<T> and remoting problem (SerializationException). news.microsoft.com
3/19/2006 6:28:54 PM
dotnet remoting: Hi,

I have a big problem with BindingList<T> and remoting (bug in dotnet 2.0 ?).
How to reproduce:

1. Create a class MyClass and implement INotifyPropertyChanged interface on
it

[Serializable()]
public class MyClass : Row, INotifyPropertyChanged
......
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new
PropertyChangedEventArgs(propertyName));
}
}

#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion

2. Create collection class (that will generate the exception):

[Serializable()]
public class MyClassCollection: BindingList<MyClass >

3. Create interface and use MyClassCollection via remoting (as ref parameter
in some method).

Exception is generated (please see below). The problem can be solved if I
remove from MyClass
implementation of the INotifyPropertyChanged (the problem is in the event
"PropertyChanged").

Exception:

System.Runtime.Serialization.SerializationException was unhandled
Message="Cannot get the member 'Child_PropertyChanged'."
Source="mscorlib"
StackTrace:
Server stack trace:
at
System.Reflection.MemberInfoSerializationHolder.GetRealObject(StreamingContext
context)
at
System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder
holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
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.Serialization.Formatters.Binary.BinaryFormatter.UnsafeDeserializeMethodResponse(Stream
serializationStream, HeaderHandler handler, IMethodCallMessage
methodCallMessage)
at
System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream
inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)
at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.DeserializeMessage(IMethodCallMessage
mcm, ITransportHeaders headers, Stream stream)
at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage
msg)
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
TestProject.Shared.Interfaces.IGroupItem.LoadRowsTest(GroupItemRows&
fieldRows)
at TestProject.Client.Test.TestGrid.btnLoad_Click(Object sender,
EventArgs e) in D:\Work\Projects\TestProject\Source\TestGrid.cs:line 41
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TestProject.Client.Program.Main() in
D:\Work\Projects\TestProject\Source\\Program.cs:line 23
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

How to make this work?

Nikolay Unguzov




Re: BindingList<T> and remoting problem (SerializationException). tomb
3/20/2006 12:00:00 AM
[quoted text, click to view]

You have to mark the handler with [NonSerialized] attribute because make no
sense to "keep" the handlers attached over the remoting boundaries, so you could
to do in this way:

[NonSerialized]
private PropertyChangedEventHandler _PropertyChanged;

public event DataChangedEventHandler PropertyChanged
{
add { _PropertyChanged += value; }
remove { _PropertyChanged -= value; }
}

Re: BindingList<T> and remoting problem (SerializationException). tomb
3/20/2006 12:00:00 AM
[quoted text, click to view]

pardòn, the right code is:

[quoted text, click to view]
Re: BindingList<T> and remoting problem (SerializationException). Nikolay Unguzov
3/20/2006 12:00:00 AM
Thanks Tomb,

The right code is:

[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged

I found this on MSDN.
Thanks for the help.

Nikolay Unguzov

[quoted text, click to view]

AddThis Social Bookmark Button