Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rules for C# class backward compatibility/avoiding breaking changes

I'm working on a C# 3.5 assembly that is consumed by many different applications in an enterprise server environment. I would like to add some properties to an existing C# class (not abstract) and maintain backwards compatibility with current clients without recompiling. It’s a strongly named 3.5 assembly. Existing client applications will not be recompiled. Instead we use publisher policy assemblies to re-direct existing clients to the updated version.

What are the rules for maintaining this type of class backward compatibility?

I'm looking for some set of rules I can validate my code changes against.

After my current attempts at updating the class clients are throwing a "The located assembly's manifest definition does not match the assembly reference" exception.

like image 721
ErnieL Avatar asked Feb 22 '11 22:02

ErnieL


People also ask

What is the k and C rule in phonics?

In 1-syllable words use the letter 'c' with the vowels a, o, u. 'c' is the most common spelling for /k/ at the beginning of words. Use the letter 'k' with the vowels i and e. Use the consonant digraph 'ck' only at the end of 1-syllable words when the /k/ sound IMMEDIATELY follows a vowel.


3 Answers

The best reference is Justin's answer: A definite guide to API-breaking changes in .NET

@Justin - if you ever post this as an answer, I'll give you the check.

like image 95
ErnieL Avatar answered Oct 09 '22 19:10

ErnieL


You have to maintain the same assembly version (i.e. don't increment it across builds) — see the AssemblyVersionAttribute in MSDN.

Also, you could leverage assembly binding redirects, but that involves config file changes which I don't expect to be desirable in your case.

like image 27
Ondrej Tucny Avatar answered Oct 09 '22 18:10

Ondrej Tucny


At his point error that you are getting is not related to compatibility between classes, but rather problem loading assembly - see The located assembly's manifest definition does not match the assembly reference if it helps.

Adding properties/methods to exisitng class should be ok for backward compatibility. Removing fields/methods/properties, changing class to struct, changing base class is definitely not. Modifying constants, enum values is dangerous.

like image 32
Alexei Levenkov Avatar answered Oct 09 '22 17:10

Alexei Levenkov