1

When i try to open a serialized file, that is generated using old Application(.NET), in new application(.NET) then i am getting SerilizationException "Cannot get the member 'b__319_0".

Key points 1.) Serialization and deserialization working in the same version of code without any exception. 2.) Across versions it is not working. 3.) It is WPF application and I am serializing MyViewModel class that is derived from ViewModel. 4.) Using BinaryFormatter

Detail description I added new variables, properties and method in my class in new version(as project required). Now when i try to open my old serialized file in new version then i get Serialization Exception "Cannot get the member 'b__319_0'".

To Identify this issue i commented all newly added code and try to open my older data in newer version(In which i commented new code) this older data open in this version without any Exception.

I prepared sample program out of my application and it is working fine. Now I am really confused about the actual problem and not able to find out the solution.

Any suggestion will help Thank you in advance

  • Please provide a proper example of the code that does not work. – Silvermind Feb 05 '19 at 11:06
  • 1
    the bad news: `BinaryFormatter` is *notorious* for being brittle between versions, *especially* when using automatically-implemented properties or moving between different projects / layouts (basically: it hates refactors); the number of times I recommend using `BinaryFormatter` ... well, it isn't *actually* zero, but it isn't far from it; is it even remotely possible to change serializer at this point (into the old code first, obviously) and re-export? or is the existing version done and done, and whatever the file is: is what you need to work with? – Marc Gravell Feb 05 '19 at 11:08
  • @Silvermind in this case, I don't think that will help; I understand the problem, and it isn't as simple as just showing a few lines of code – Marc Gravell Feb 05 '19 at 11:08
  • @MarcGravell Maybe, but it could also be some type that was serializable in older versions, but is not serializable anymore. The problem could also be the same as described in this thread [SerializationException "Cannot get the member...](https://social.msdn.microsoft.com/Forums/windows/en-US/f04697bd-41a1-4326-a5e2-010cdeccd921/serializationexception-quotcannot-get-the-member-childpropertychangedquot-when?forum=winformsdatacontrols) – Silvermind Feb 05 '19 at 11:13
  • @Silvermind perhaps, but that's *another* notorious problem re events; seeing as it *used* to work, that seems unlikely *in this case* (since the target framework looks to be the same, although it could be a different version, perhaps); but yes, I'll grant that it could be useful. The mention of `b__319_0` means it could be a large type, however :/ – Marc Gravell Feb 05 '19 at 11:16
  • 1
    @Silvermind I have to say, though... I'm terrified by "that is derived from ViewModel." and it increases the chance of what you're talking about - that could indeed make this fundamentally painful; serialization that touches the UI framework is just ... bad territory (sorry Pankaj, but you've wandered into a minefield of problems with that choice) – Marc Gravell Feb 05 '19 at 11:19
  • @MarcGravell I agree. These are the kind of design problems that are a often a consequence of fix-fast-worry-later mentality. – Silvermind Feb 05 '19 at 12:20
  • 1
    @Silvermind,@MarcGravell Thanks, I agree with fix-fast worry later mentality point.This was very old code i can not change complete functionality now. if in case if you come across any other idea. let me know – Pankaj Kherodiya Feb 05 '19 at 12:36
  • `b__319_0` sounds like the name of an **anonymous delegate** such as an `Action`. If your view model has an `Action` member that is not marked as `[NonSerialized]`, `BinaryFormatter` will try to serialize it, which will sometimes work, but often not -- but it is always a **bad idea** to do so. For why, see [how come BinaryFormatter can serialize an Action<> but Json.net cannot](https://stackoverflow.com/a/49139733/3744182). – dbc Feb 05 '19 at 22:39

0 Answers0