27

I have a console application which has target .NET 2.0

It is very short but full of unsafe code.

I converted it to VS 2010. I run it OK.

When I try to change "target framework" in properties to 3.5 or 4.0 it shows message box:

TargetFrameworkMoniker: Error parsing application configuration file at line 0. XML document must have a top level element.

the target then stays 2.0 anyway.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • For me it was this same issue when going from .NET to NET 4.5. The solution was part of TFS and turns out I was in offline mode. When I connected back online to my TFS server it all worked fine. – gideon Jul 08 '15 at 09:34

7 Answers7

30

This happened to me because my project file was marked as "Read Only" in its properties. Changed it, and it was fine.

It also could be caused by read-only app.config/web.config

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
jocull
  • 20,008
  • 22
  • 105
  • 149
21

Found the solution. Simply opened app.config in text pad (it was empty for some reason) and pasted:

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
1

For me the problem was the web.config file located outside of the project directory. I moved it back in, and was able to change the target framework.

Idan P
  • 265
  • 3
  • 8
1

I have same issue. I solved it by removing write protected attribute of web.config file. It was read only earlier.

arpan desai
  • 889
  • 2
  • 13
  • 23
1

For me, my project was using a web.config file that was a linked file back to a web.config in another project. I removed the link, changed the target, then added the link back.

jwatts1980
  • 7,254
  • 2
  • 28
  • 44
1

I faced this problem , i solved it by click app.config to open it and leave it ,then go to properties and upgrade .NET version

Baraka Ally
  • 1
  • 1
  • 5
0

I was trying to retarget from .NET 4.5.2 to .NET 4.5 In my app.config, I had to change

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

to

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

before the project properties page would let me retarget.

sirdank
  • 3,351
  • 3
  • 25
  • 58