6

I am writing a program which is targeted to run on .net framework 2.0.

I have chosen 2.0 in my VS project.

It runs fine on my machine (mine has 2.0 SP2), so there is no compile error. but when I tried to run it on another machine (only with 2.0, no sp), it cannot run. I am aware that I used some method which is supported by 2.0 but only with 2.0 SP2.

.net framework 2.0 SP2 seems not being listed in VS IDE, that's why VS cannot give me any warning when I compiled it on my machine.

How can I easily check the compatibility of my codes with .net framework 2.0 SP2? or I just have to look at msdn to check every method I have used???

thanks

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Jack
  • 3,913
  • 8
  • 41
  • 66
  • Method Not Found. I have solved that problem, which was caused by I used wrong method. – Jack Apr 26 '10 at 13:25

3 Answers3

4

You can run FxCop, which will warn you whenever you call a method introduced by a service pack.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Thanks. you mean I use FxCop to analyse the codes, it will tell me if I call a method from 2.0 SP2? – Jack Apr 26 '10 at 13:24
  • 1
    More info: http://davesbox.com/archive/2008/08/25/new-for-visual-studio-2008-sp1-and-fxcop-1-36-multi-targeting-rule.aspx – Ray Apr 26 '10 at 13:25
  • Thanks all. FxCop fills what I need. Very helpful. Thanks – Jack Apr 26 '10 at 13:37
0

If you know for sure which specific libraries (dll) distinguish 2.0 SP2 from just 2.0, you can attempt to programmatically locate and load them. If it fails, then the SP2 is not present.

In case there is no "new" dlls, you could use reflection to check if a class has a specific method. If it does, you've got SP2.

It is a solution for run-time, so you can display a friendly message to the user.

  • What if I don't know any? in the above e.g., I used some method in the library of 2.0, but the compiler did not tell me it is for 2.0 SP2. I just want to know is there any easy way to know which method or class is from 2.0 SP2 or more precise .net framework version? – Jack Apr 26 '10 at 13:22
  • @Jack: Look at the method description on MSDN pages. It always says which framework version support it, including SP data. –  Apr 26 '10 at 13:23
0

You can identify where in your code is the error when no sp is present.

Then, you just create a dummy snippet that use that structure, and catch the exception.

If no exception is catched, you are ok. If an exception is thrown, you are probably missing sp2.

Daniel Dolz
  • 2,403
  • 1
  • 18
  • 23