Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Can I use C# 4.0 with the target framework set to .NET 3.5 to develop an extension for ArcMap 9.3? Or does it have to be C# 3.0 or earlier?

share|improve this question
    
If the target framework 3.5 then you are using C# 2.0 with extensions. ArcEngine 10 needs to target .NET 3.5 so you miss out on some 4.0 goodies. I wanted to use a wpf calendar control in my app, but I couldn't because that's 4.0. So I had to use the winforms one. –  patrick Feb 28 '12 at 15:32
    
I was using C# 4.0 to develop an extension for ArcMap 10 with the target framework set to 3.5 so I was wondering if it would be backwards compatible as long as the framework stayed 3.5. Should I change my ArcMap 10 extension to C# 2.0 so it can be recompiled with ArcMap 9 without having to make many code edits? Will C# 3.0 work with ArcMap 9? –  Mike Rogers Feb 28 '12 at 15:58
add comment

2 Answers

up vote 11 down vote accepted

Short answer: In my experience, there should be absolutely no problem developing .NET 3.5-based code for ArcGIS 9.3 in Visual Studio 2010 (with C# language version 4), as long as you explicitly target the .NET Framework 3.5. The C# language version is mostly irrelevant here.

P.S.: This answer does not go into the differences that exist between developing an ArcGIS extension for versions 9.3 and 10. (ESRI has made quite a few major changes to the add-in model, but I'm assuming you're aware of that.)

Longer answer: You need to distinguish between the C# language version, and the targeted Framework version.

You can think of the .NET Framework as being made up of two major parts: the CLR (Common Language Runtime), and the BCL (Base Class Library). The former is the "virtual machine", while the latter is the class library (containing all the types that you can look up on MSDN).

.NET Frameworks 2 until 3.5 all use the same CLR (version 2), that is, the execution environment hasn't really evolved. What has evolved, however, is the BCL. If you're running a .NET 3.5 application on a .NET 2 machine, the main problem will not be that the "bytecode" (CIL) will be incompatible (it won't), but that the application might refer to and use types that were not yet available in the .NET 2 BCL.

Now, when you tell Visual Studio 2010 to target the .NET Framework 3.5, it will make sure that you won't use BCL types from any later Framework version. It will also make sure that the code output by the C# compiler will not require features only available in the CLR version 4.

The C# language version has very little to do with all this. What the C# compiler really does it to take your source code and translate it to a much lower-level programming language called CIL (Common Intermediate Language). Certain C# language constructs will no longer be recognisable in CIL: For example, yield return and yield break do not exist in CIL. They are simply translated to implementations the IEnumerator<T> interface.

To sum this up: The C# language version becomes irrelevant as soon as your code is compiled. What is important is...

  • whether the output CIL/"bytecode" is compatible with the targeted .NET Framework (if you target .NET 3.5, it will be compatible even with .NET 2 for the reasons mentioned above); and

  • whether your code refers to / makes use of types that are available in the target framework.

One notable exception (in the sense that a C# language construct requires a particular version of the framework; this was last the case whwn generics were introduced IIRC) might be the C# keyword dynamic. It might be compiled to code that requires types from the System.Dynamic namespace, which is only available since .NET 4. But don't worry: If you've set up your Visual Studio 2010 project to target the .NET 3.5, you should get a compiler error if you're trying to use stuff that is not available, or compatible with, that particular .NET Framework version.

share|improve this answer
1  
Thank you for the detailed explanation! –  Mike Rogers Feb 28 '12 at 17:57
1  
@SeaJunk, this is not fully correct. Even if there might be no ESRI SDK extension for ArcGIS 9.3/VS2010, this won't stop you from referencing ArcGIS assemblies and start writing code. That is, it's still possible to use that IDE, only more uncomfortable. There might also be some more manual work involved (registering components etc.) but again, it's feasible AFAIK. –  stakx Feb 28 '12 at 18:20
    
Yep sorry, just looked that up :) –  SeaJunk Feb 28 '12 at 18:24
    
You provided a good explanation, but the relationships are a bit more complex, as the features of all three (CLR, BCL and C#) are heavily influenced by each other. –  Petr Krebs Feb 28 '12 at 21:57
1  
Eric Lippert's blog (blogs.msdn.com/b/ericlippert) is a wonderful resource on various dark corners of .NET/C# and decisions behind their design. –  Petr Krebs Feb 28 '12 at 22:08
show 3 more comments

Keep in mind that VS2010 isnt a supported IDE for 9.3 development. You wont get any assembly references, help or template integration.

You can kind of make it work however: http://forums.arcgis.com/threads/29935-VS2010-with-version-9.3.1

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.