2

For some reason I've always had trouble remembering the backwards/forwards compatibility guarantees made by the framework, so I'd like to put that to bed forever.

Suppose I have two assemblies, A and B. A is older and references .NET 2.0 assemblies; B references .NET 3.5 assemblies. I have the source for A and B, Ax and Bx, respectively; they are written in C# at the 2.0 and 3.0 language levels. (That is, Ax uses no features that were introduced later than C# 2.0; likewise Bx uses no features that were introduced later than 3.0.)

I have two environments, C and D. C has the .NET 2.0 framework installed; D has the .NET 3.5 framework installed.

Now, which of the following can/can't I do?

Running:

  1. run A on C? run A on D?
  2. run B on C? run C on D?

Compiling:

  1. compile Ax on C? compile Ax on D?
  2. compile Bx on C? compile Bx on D?

Rewriting:

  1. rewrite Ax to use features from the C# 3 language level, and compile it on D, while having it still work on C?
  2. rewrite Bx to use features from the C# 4 language level on another environment E that has .NET 4, while having it still work on D?'

Referencing from another assembly:

  1. reference B from A and have a client app on C use it?
  2. reference B from A and have a client app on D use it?
  3. reference A from B and have a client app on C use it?
  4. reference A from B and have a client app on D use it?

More importantly, what rules govern the truth or falsity of these hypothetical scenarios?

1
  • Have to learn more to know about this question! Commented Feb 25, 2010 at 13:10

1 Answer 1

2

run A on C? run A on D?

No problem here.

run B on C? run C on D?

You can't run B on C because it references 3.5 assemblies which are not available on C. No problem to run C on D.

compile Ax on C? compile Ax on D?

No problem here.

compile Bx on C? compile Bx on D?

You can't compile Bx on C because it doesn't have the 3.5 assemblies installed which it references. No problem to compile Bx on D.

rewrite Ax to use features from the C# 3 language level, and compile it on D, while having it still work on C?

Yes this is possible.

rewrite Bx to use features from the C# 4 language level on another environment E that has .NET 4, while having it still work on D?

No this is not possible because if you target the CLR 4.0 the assembly won't be able to run on a previous CLR version.

As a conclusion:

ildasm.exe yourassembly.dll. Double click on MANIFEST, look at Metadata version. If it is v2.0.50727 it means that this assembly has been compiled for the CLR 2 version. Then you look at the referenced assemblies. If in the references you see a referenced assembly called System.*** with version 3.5.0.0 it means that .NET 3.5 framework is required. If not it probably will run fine with only .NET 2.0 installed (of course it shouldn't reference any other assembly that itself depends on .NET 3.5).

Sign up to request clarification or add additional context in comments.

4 Comments

My understanding was that by virtue of installing .NET 3.5, you also install the 2.0 assemblies (that is, it's a superset). Is this not the case? Also, why is it the case that I can rewrite Bx but not Ax? Is there something special about CLR 4 that breaks things?
Yes, absolutely, that's why you can do whatever you want with A and B on the D environment.
.Net 3.5 does (should?) install the 2.0 assemblies, as they both use the same version of the CLR. You can rewrite Ax and Bx however you choose - if you rewrite them to use C# 3.0 features, you wont be able to run them on your .Net 2.0 environment; if you rewrite them to use C# 4.0 features, you'll need to run them on an environment with .Net 4.0 installed.
@Graham: C#3.0 does not require .NET 3.5. You can use C#3.0 features in a .NET 2.0 program.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.