0

I have a dll written in C# which contains only data classes. These classes are filled reading the datas from a file.

I need to use this library within two or more applications, which are deployed separately, so they can contain different versions of the dll.

The file from which data are read is aligned with one application, but not with the others.

In this situation, if an application reads a file which contains a newer version, it can crash during runtime.

What are the best practices to deal with a problem like that?

Maurizio Reginelli
  • 3,152
  • 2
  • 27
  • 41
  • 1
    Perhaps have a version number in the file and avoid reading it if it's not the same version as the application? – Xerillio Jan 31 '21 at 15:40
  • Either a version number as mentioned, or a method to detect and ignore extra fields. You don't describe which serialization method so cannot advise. – Charlieface Jan 31 '21 at 15:49
  • I'm using DataContractSerializer as serialization method. – Maurizio Reginelli Jan 31 '21 at 17:09
  • I cannot use a version number and avoid reading. I need to read a newer file without errors. Then the application should ignore the newer properties and methods. In that way, the application doesn't change its behavior if the known properties aren't changed. – Maurizio Reginelli Jan 31 '21 at 17:14
  • @MaurizioReginelli It sounds like a recipe for disaster to deserialize with version mismatch and trusting that you're getting the full picture deserialized. In any case, please show us how you are configuring your classes - perhaps take a look at [this answer](https://stackoverflow.com/a/28796211/3034273) – Xerillio Feb 02 '21 at 18:07

0 Answers0