0

I have a set of applications as a single Project developed in C# using .NET3.5. The app doesn't work in PC with NET4, I added and testing to see all functionality is working in NET4 or not. Changed the Net framework to 4.0 instead of 3.5.

The same app got compiled & build without a single error in NET4. The app contains UserSettings in Properties.Settings. I changed the version in to 4.0.0 from 2.0.0 and now app starts its execution.

My QUESTION: The code is compatible for NET3.5 & 4.0. But the only problem lies at present is value of Version in in appConfig will be different for version with .NET3.5 & .NET4.0. Is their anyway, I can use the same code for NET3.5 & 4 in addition to handle the above mentioned situation i.e. value of Version tag ? Also can I add

  <startup>
<!-- FOR .NET 3.0 & 3.5, 3.0.50727 CLR is only used -->

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0" />  <!-- For Net 2.0, 3.0, 3.5 -->

to make the app run on PC with NET 4.0 or 3.5 ?

Any help, guidance is appreciated.

Thanks

Tvd
  • 4,463
  • 18
  • 79
  • 125

1 Answers1

2

You should build against v3.5 instead of v4. Then I'd expect you to be able to run it on machines with either just 4.0 or just 3.5 without any app.config file at all - or one which doesn't mention supported runtimes. It's expected that most code which runs on 3.5 should just be able to run on 4.0 without change.

(One change is around native code in mixed mode assemblies, IIRC - but unless you know that you're including native code, I doubt that you'll be bitten by that.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • the original version is of 3.5 only and it doesn't execute in 4.0 enviornment. While migrating When I changed the value of Version value from 2.0.0.0 to 4.0.0.0 in configSections in app.config, then only it started to show up. Else it was facing problem with updating & Saving values in Properties.Setting. – Tvd Feb 22 '13 at 13:12
  • @Tvd: "Doesn't execute" is very vague. What went wrong? How else did you try to fix it? Did you have a `supportedRuntime` element in the original application? Did you try *removing* that or *adding* to it, instead of just changing it? – Jon Skeet Feb 22 '13 at 13:14
  • Yes when I migrated to 4.0, supportedElement is added to it. Initially that was top child in configuration, I made configSections to top that made it execute the app. Just now, I tried replacing the Version back to 2.0.0.0 and it does execute. BUT supportedElement is added. FYI, AT this moment I am working with NET 4.0 version for the app. I have app verion of 3.5 also avbl. – Tvd Feb 22 '13 at 13:25
  • @Tvd: I'm afraid I didn't follow your comment there, but basically you should certainly be able to get the .NET 3.5 build to work on .NET 4... and I would personally remove *all* of the configuration to do with this, and let .NET work it out itself. – Jon Skeet Feb 22 '13 at 13:28
  • Thanks Jon. Once I check the functionality properly working in net4.0, If all well, will do as u have suggested. – Tvd Feb 22 '13 at 14:27