432

I'm trying to up load my site and I'm getting this error message:

Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

<compilation debug="true" targetFramework="4.0">

The site works fine on my local PC but won't open when I loaded it to my host and tried to view it online.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Mike Nacci
  • 4,319
  • 2
  • 14
  • 7
  • Does it not show which file contains that or where? – Jon Skeet Sep 23 '11 at 14:39
  • 2
    Was it built previously on pre 4.0 framework? http://elegantcode.com/2009/11/10/unrecognized-attribute-targetframework-asp-net-4-0/ – Ta01 Sep 23 '11 at 14:42
  • This issue may be resolved by 4.0.3. [You can check out the KB article here.](http://support.microsoft.com/kb/2599651) @ me and let me know if this fixes your issue, I may try to get a canonical question/answer for this error and close dupes. Thanks. –  Nov 28 '11 at 20:03
  • When I try to install KB2599651 (64-bit download) on Win 7 x64, I get the error message that it "does not apply or is blocked by another condition on your computer". I have the same error as OP, have framework 4.0 installed and have registered it with IIS, and have chosen it as the Application Pool. – Tim Oct 28 '12 at 11:20
  • Did you open in an older version of visual studio than the project was developed in? Or was it developed in Webmatrix and then opened in an older visual studio? – ruffrey Apr 30 '13 at 14:50
  • If you are using Plesk Admin (Godaddy users), then 1. Log into your account. 2. Go to Websites and domains. 3. Scroll to the website which is having this problem. 4. Click on "Hosting Settings". 5. Scroll down to Microsoft ASP.NET support (Version ) and select 4.8.03761 (latest version as of Jan 2021). 6. Click OK – user3267567 Jan 07 '21 at 08:07

30 Answers30

633

This typically happens when you have an attribute of targetFramework="4.0" in the web.config but the App Pool is set to run ASP.NET 2.0. The targetFramework attribute is entirely unrecognized by ASP.NET 2.0 - so changing it to 2.0 won't have the desired effect.

Contact Support / Your Administrator and have the AppPool switched to 4.0.

You could also remove the attribute entirely, however if your site was coded with the 4.0 Framework, then I'm sure something else will cause an error as well.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
  • 20
    Thanks, this solved the problem, check this link for a step by step guide to have your AppPool switched to 4.0: http://stackoverflow.com/questions/4890245/how-to-add-asp-net-4-0-as-application-pool-on-iis-7-windows-7 – user1010572 Feb 22 '12 at 10:44
  • thanks @vcsjones..my website is now up and running just because of you.. :) – Shiva Pareek Jan 10 '13 at 17:54
  • just to add to @vcsjones solution registering .net 4.0 might also be missed. You can do .net 4.0 registration using [procedure in this link](http://stackoverflow.com/questions/4890245/how-to-add-asp-net-4-0-as-application-pool-on-iis-7-windows-7) and then you need to chagne the application pool to 4.0. – Ram Jan 11 '13 at 02:31
  • 4
    When I googled the error message, I found this page, with this beautiful question and even a more beautiful answer, which I alreay upvoted months ago. – Memet Olsen Jul 29 '14 at 17:44
83

Registering the framework with IIS is what worked for me:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i
kenik
  • 1,788
  • 13
  • 12
  • 7
    This works! for 64bit is under C:\Windows\Microsoft.NET\Framework64\v4.0.30319 – OKEEngine Nov 26 '12 at 11:58
  • 1
    I've had the same problem, but the regiis didn't fix it - I had to drop & recreate the entire website tree and reassign the pool for each app, and now it works... – veljkoz Dec 19 '12 at 12:22
  • 1
    If this is a fresh version of IIS (no other sites running on it) or you're not worried about the hosted sites breaking with a framework change you can use -i instead of -ir while registering. – Ram Jan 11 '13 at 02:34
48

In IIS

Click on Application Pools

Right Click on DefaultAppPool --->> Set Application Pool Default....--->>Change .Net Version to V 4.0.

Alexander Zaldostanov
  • 2,907
  • 4
  • 30
  • 39
45

open your IIS (type inetmgr in run) and change your Application pool setting,To view large this Image Right Click Image and open image in new tab enter image description here

Ankit
  • 4,755
  • 2
  • 22
  • 14
27

In Visual Studio menu:

Website -> Start Options -> build tab -> Select Target Framework in Dropdown box (.NET FrameWork 4)

Jonas Äppelgran
  • 2,617
  • 26
  • 30
elaiyaraja
  • 287
  • 3
  • 2
12

I was facing the same issue while publishing my 1'st web services. I resolved it by simply doing this:

  1. Open IIS

  2. Click on Application Pools

  3. Right Click on DefaultAppPool => Set Application Pool Default => Change .Net Version to V 4.0. (You can also change .Net Framework Version of your application specifically)

Hope, it'll work.

Arsman Ahmad
  • 2,000
  • 1
  • 26
  • 34
9

for IIS 7 try according to the given picture ... mark me helpful if it works for you.

enter image description here

gm arif
  • 154
  • 1
  • 6
8

I had to register ASP.Net in IIS to get it resolved in the Windows Server 2008 R2. Sreenshot of the commands attched below

cd /d C:\Windows\Microsoft.NET\Framework\v4.0.30319

iisreset /stop

aspnet_regiis -i

iisreset /start

%systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /[path='%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll'].allowed:True 

%systemroot%\system32\inetsrv\appcmd set config /section:isapiCgiRestriction /[path='%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll'].allowed:True 

enter image description here

LCJ
  • 22,196
  • 67
  • 260
  • 418
7

I'm using IIS Express, rather than IIS.

The problem was in the applicationhost.config file located in: {solution_folder}\.vs\config\applicationhost.config.

One of the application pool entries had a managedRuntimeVersion value of "v2.0". I changed it to "v4.0", and it worked properly.

I'm fairly sure the root cause was one of the NuGet packages I had installed recently.

    <system.applicationHost>
       <applicationPools>
          <add name="BadAppPool1" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
       </applicationPools>
    </system.applicationHost>
NightShovel
  • 3,032
  • 1
  • 31
  • 35
5

Change the application pool to target framework 4.0 instead of classic .

  1. RC website ->manage website->advanced setting>
  2. the first option change from classic to framework 4 integrated.
Mhd. Yasseen
  • 1,027
  • 3
  • 16
  • 27
dev.Magdy
  • 51
  • 1
  • 1
4

Open Project -> press Shift + F4 (Open properties page) -> Chose Build -> in Target Framework chose .NET Framework 4 -> OK

Chưa biết
  • 919
  • 8
  • 6
4

I also got the same issue while running my application locally which is pointing to .Net Framework 4.7.1. The bug was "Unrecognized attribute TargetFrameWork" as shown below. enter image description here

But none of the above answers helped me. At last when I changed my present port (1413) number to some other value(60179) as shown below it worked fine for me.But I am not sure for the actual reason behind this , but it worked.

enter image description here

Rinoy Ashokan
  • 1,501
  • 17
  • 14
  • I am just verifying that I have had this exact error, and I tried simply changing the port as indicated in this answer. I'm running the WCF Test Client to start this service on localhost. After changing the port number, the service was able to start. Thank you for your suggestion. – Evan Jan 29 '19 at 17:47
  • After trying all the suggestions only this one solved my issue. Thank you so much. – Prabo Mar 11 '20 at 15:30
  • IIS Express creates a new configuration for each site that you run, and it's bound to the url (host/port). This means that if you have a project using framework 2.x (2.0 to 3.5) running on some port and then later you open another project using framework 4.x in the same port you'll see that issue. The footer shows that it's running under framework 2.x and that framework 2.x doesn't recognize the "targetFramework" attribute, which started in 4.x. – drizin Dec 01 '20 at 16:44
3

Create a new pool by selecting .Net Framework v4.0.3xxxxx

use the Manage Pipeline Mode: Integrated

Assign it to your site and done.

Ali Adravi
  • 21,707
  • 9
  • 87
  • 85
2

To fix this problem simply click the ASP.NET Version icon in the Site Tools section of Control Panel to switch the framework to 4.0.

Sumanuski
  • 21
  • 2
2

I had this error from a failed MSBuild compile, in a project file converted from an earlier version of VS into VS2010 and .NET 4.0. It was actually a Web Deployment project, and the solution that worked for me was adding the following entries into the PropertyGroup section at the start of the MSBuild file:

<ProductVersion>10.0.11107</ProductVersion>

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

Maybe these get automatically updated when other types of project are converted in VS2010, but they were missing from my Web Deployment project file after it was converted.

ergolargo
  • 53
  • 6
2

What I did: I did change the value of Application Pool to DefaultAppPool from a previous value. You do this in the Advanced Settings (Website --> Manage Website --> Advanced Setting>.

Eldon
  • 21
  • 2
1

Just had this in VS 2010.

Fixed by editing the .sln file and changing the TargetFrameworkMoniker to have the value ".NETFramework,Version%3Dv4.0" assigned to it.

Matt
  • 11
  • 1
1

If you're using IIS Express, it creates a new configuration for each site that you run, and it's bound to the url (host/port). However, when it opens a new project using the same port it doesn't refresh the configuration.

This means that if you have a project using CLR 2.0 (.NET Framework 2.0 to 3.5) running on some port and then later you open another project in the same port using CLR 4 (.NET Framework 4.x+) the new project will try to run using CLR 2, which fails - and in case it doesn't even recognize the "targetFramework" attribute.

One solution is cleaning IIS Express sites, but the easiest method is changing the port so that IIS Express will create a new site (using CLR 4) for your project.

drizin
  • 1,737
  • 1
  • 18
  • 44
0

If you compile the files and the value of the "targetFramework" is set as being a particular version i.e. 4.0,

Make sure the host is running .net framework as the same version stated.

If not, download the .net framework.

After downloading, if it is not automatic being set in the IIS manager to be using the extension of the newly downloaded version of .net framework,

add the extension manually by going to the folder of the recently downloaded .net framework THROUGH IIS manager:

1.right-click website folder

2.go to "Properties"

3.under "virtual directory" , click "configuration"

4.edit the executable path of extension ".aspx" (of which the path being pointed to version other than the version of the recently downloaded .net framework) to the correct path which is the folder of the NEWLY downloaded version of .net framework and then select the "aspnet_isapi.dll" file.

5.click ok!

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Feed
  • 1
0

Just Remove the "Target Framework 4.0" and close the bracket.

It will Work

Vignesh
  • 17
  • 1
0

Follow these two steps:

Register the .net framework version version 4.0 (if it is not registered)

  1. C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i

  2. In the app pool change the .net framework to v4.0

SharpCoder
  • 18,279
  • 43
  • 153
  • 249
0

If you install the IIS after the installation of .Net FrameWork. You need install the .net framework again for IIS. So all we need to do is run aspnet_regiis -i. Hope it is helpful.

Joe.wang
  • 11,537
  • 25
  • 103
  • 180
0

Saw the error "Unrecognized attribute 'targetFramework'" in the 'Console output' page of Jenkins on a build server. This was after I changed the 'target framework' for several projects from '.NET Framework 3.5' to '.NET Framework 4' and committed my changes.

In Jenkins the project settings had to be changed. For the solution the 'MSBuild Version' had to be changed from 'v3.5' to 'v4.0'.

mathijsuitmegen
  • 2,270
  • 1
  • 34
  • 36
0

Just had this issue deploying a new app to an old IIS box. The investigation led to the v4.5.1 run-time being installed but the app requiring v4.5.2

Nothing apart from installing the correct version of ASP .Net run-time was required.

rob
  • 8,134
  • 8
  • 58
  • 68
0

It could be that you have your own MSBUILD proj file and are using the <AspNetCompiler> task. In which case you should add the ToolPath for .NET4.

<AspNetCompiler
    VirtualPath="/MyFacade"
    PhysicalPath="$(MSBuildProjectDirectory)\MyFacade\"
    TargetPath="$(MSBuildProjectDirectory)\Release\MyFacade"
    Updateable="true"
    Force="true"
    Debug="false"
    Clean="true"
    ToolPath="C:\Windows\Microsoft.NET\Framework\v4.0.30319\">      
</AspNetCompiler>
intrepidis
  • 2,870
  • 1
  • 34
  • 36
0

For layering, Just change the version of targetFramework in web.config file only, the other things no need change.

Cheah Eng Teong
  • 39
  • 1
  • 2
  • 12
0

I had the same issue and I found this nice poweshell script to update all of your app pools at the same time: https://gallery.technet.microsoft.com/scriptcenter/How-to-set-the-IIS-9c295a20

Make sure to set you $IISAppPoolDotNetVersion = "v4.0" variable at the top.

Hector S.
  • 303
  • 3
  • 12
0

following 2 steps will force refresh Visual Studio and IIS Express cache and usually resolve my similar issues:

  1. Simply switch Project framework from 4+ to .Net framework 3.5 and run it
  2. If it ran successfully you can revert it back to your desired 4+ target framework and see that it will probably work again.
Iman
  • 17,932
  • 6
  • 80
  • 90
0

Changing the port number for the local development helped me Thanks @Rinay Ashokan. I have done all the trouble shooting and finally found that the project configurations are stored in the IIS express for the port number. enter image description here

-1

For anyone having this who doesn't have IIS running on their dev PC, here's what happened to me: I had one website on, overwrote with files from a diff website that was 4 while the previous was 3.5. Got this error. Fixed it simply by changing the directory name of the website, which on a dev PC can be anything, so no problem. The above are probably more elegant to be sure, but sometimes simple works, IF you can get away with it, i.e., you're in dev rather than QA or Prod.

Paul
  • 1
  • 1