You are crossing a process boundary, object references are not valid in another process. The DataObject class supports serializing objects to get them across the wall, it uses BinaryFormatter. So, yes, you'll need to apply the Serializable attribute to your class and make sure your objects can de/serialize properly.
Yeah, that's what I was afraid of. Any idea if I'm going to introduce performance regressions if I implement ISerializable? The binary serialization of this object might be hundreds of KB.
– EricLaw -MSFT- Jan 21 '10 at 19:26 Let us know when you find out please. – Hans Passant Jan 21 '10 at 19:44 Hmmm... implementing ISerializable doesn't help-- the method is never called. Similarly, adding the Serializable attribute to the class has no impact at all.
Any other ideas? – EricLaw -MSFT- Jan 24 '10 at 20:20 Use DataFormat. Serializable to trigger the serialization code.
– Hans Passant Jan 24 '10 at 20:29 It turns out that if I add both ISerializable AND the Serializable attribute, and put a MessageBox in the ISerializable implementation, then I see it get hit. If I simply let my ISerializable implementation emit a Not Yet Implemented exception, that exception gets eaten somewhere along the way and I still get the old "cannot convert object to Session" exception. So, now I've just got to write a bunch of code to make my ISerializable implementation work.
Thanks for your help! – EricLaw -MSFT- Jan 25 '10 at 18:02.
Ok this is a shot, instead of using a whole array of Sessions, try doing it individually like this... Session oDroppedSessions; try { if (e.Data. GetData("Fiddler. Session")!
= null){ object objs = e.Data. GetData("Fiddler. Session"); if (objs!
= null && objs. Length > 1){ oDroppedSessions = new Sessionobjs. Length; int nIndex = 0; foreach(object obj in objs){ if (obj is Session){ oDroppedSessionsnIndex = (Session)obj; nIndex++; } } } } } catch (Exception eX) { // reaches here } Worth a shot, other than shooting myself in the foot as I do not fully understand the Session part, try it... Hope this helps, Best regards, Tom.
You could use "as" for casting which will avoid the exception ("as" will return "null" without throwing an exception if the cast fails) - but I don't think this will solve your problem (it will just avoid the actual exception), as I agree it's likely you'll have to make your class Serializable. You could test your hypothesis by commenting out the fields that will be harder to make it work - just for now to test it.
1: Trading an InvalidCastException for a NullReferenceException is a loss of information. The as keyword is good if you expect that a cast might fail. Otherwise, it's bad, and I've seen it overused a lot.
– P Daddy Jan 21 '10 at 18:12.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.