ASP.NET MVC4 to 5 Upgrade - asp.net

I have had to take a very old project out of it's dusty box and upgrade it from 4 to 5 and I followed the guidance on the MS Site (https://learn.microsoft.com/en-us/aspnet/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2) and it all works perfect locally on my dev machine. Yep it works on my machine so ship it right....
Well No because I publish to the server and this is where the issues start as I keep getting errors saying:
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The 'targetFramework' attribute in the
element of the Web.config file is used only to target
version 4.0 and later of the .NET Framework (for example,
''). The 'targetFramework'
attribute currently references a version that is later than the
installed version of the .NET Framework. Specify a valid target
version of the .NET Framework, or install the required version of the
.NET Framework.
I have checked that the Web.Config file has the Target set to 4.7.1 and on the server the current version is 4.7.2 so where am I going wrong.
The line in the Web.Config that is being referenced is:
<compilation debug="true" targetFramework="4.7.1" />
And at the bottom of the error page:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
I like my local machine too much to ship it to the cloud so someone please help. I have been bashing my head against the desk for hours now and Google/Bing etc are not helpful.

Have you tried to install "Runtime" SDK on the server?
The runtime SDK for Framework 4.7.1 can be found here:
https://www.microsoft.com/net/download/visual-studio-sdks
If you haven't done it, try it!

Probably you don't have the .Net version in the hosting server just install the .Net version in the server.
.Net 4.7.1 Offline Installer

Thanks for the responses but this site is hosted on a shared hosting platform so I can't install anything, but I checked and they have 4.7.2 installed.
I fixed the problem by removing the targetFramework from the compilation settings and worked a treat.
Old:
<compilation debug="true" targetFramework="4.7.1" />
New:
<compilation debug="true" />
Thanks for the help. Now onto the next issue.

Related

Issue with error in hosting my application

I am trying to deploy a project visual studio 2015 project in IIS 8 and I get the following error :
hosting_error
The target framework in the <compilation> element of the web.config
file is used only to target version only to 4.0 and later of the .NET
framework (for example <target framework="4.0">. The target
framework currently references to a version that is later than the
installed version of the .NET framework. Specify a valid version of
the .NET framework, or install the required version of .NET framework.
My .NET version is 4.5.2. So, how can I solve this issue. Please help me in this. Should I install VS 2015 in my server where the IIS 8 resides. I have checked the App_pools, They are targeted to 4.0 version. Please help me in this.
In IIS, The Application pool version need to be changed from 2.0 to 4.0. That will solve the Issue.

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

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.
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.
Registering the framework with IIS is what worked for me:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i
In IIS
Click on Application Pools
Right Click on DefaultAppPool --->> Set Application Pool Default....--->>Change .Net Version to V 4.0.
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
In Visual Studio menu:
Website -> Start Options -> build tab -> Select Target Framework in
Dropdown box (.NET FrameWork 4)
I was facing the same issue while publishing my 1'st web services. I resolved it by simply doing this:
Open IIS
Click on Application Pools
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.
for IIS 7 try according to the given picture ... mark me helpful if it works for you.
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
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>
Change the application pool to target framework 4.0 instead of classic .
RC website ->manage website->advanced setting>
the first option change from classic to framework 4 integrated.
Open Project -> press Shift + F4 (Open properties page) -> Chose Build -> in Target Framework chose .NET Framework 4 -> OK
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.
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.
Create a new pool by selecting .Net Framework v4.0.3xxxxx
use the Manage Pipeline Mode: Integrated
Assign it to your site and done.
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.
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.
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>.
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.
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.
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!
Just Remove the "Target Framework 4.0" and close the bracket.
It will Work
Follow these two steps:
Register the .net framework version version 4.0 (if it is not registered)
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i
In the app pool change the .net framework to v4.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.
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'.
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.
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>
For layering,
Just change the version of targetFramework in web.config file only, the other things no need change.
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.
following 2 steps will force refresh Visual Studio and IIS Express cache and usually resolve my similar issues:
Simply switch Project framework from 4+ to .Net framework 3.5 and run it
If it ran successfully you can revert it back to your desired 4+ target framework and see that it will probably work again.
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.
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.

Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I'm working on a project that accesses the Exchange Server. Before I replaced the project to a server, everything went fine. But now I'm getting this error.
I don't find what I search in Google, so I hope someone of you can help me. I appreciate that.
You should provide the specified assembly with your application or install it on your server.
The answer is: I copied the dll and xml file (which you get when installing EWS Managed API) to the bin-folder of my project. And it works!
I had the same exact error, in VS2005, .Net 2 and 3.5
This is how I resolved it, and I had to find another solution, because this always failed and Windows would not let me register the DLL.
regsvr32 "C:\Program Files\Microsoft\Exchange\Web services\1.1\Microsoft.Exchange.WebServices.dll"
I went into the .Net Framework Configuration Wizard from Administration tools in Windows XP. Mine is .NET Framework 2.0 Configuration (version 2.0.50727.42).
I then went into Runtime Security Policy -> Increase Assembly Trust and pointed to the above DLL in my C drive. It was set to NO TRUST, for some reason! I changed it to FULL TRUST.
I then closed and re-opened my VS2005 project and everything is now working fine.
Regards,

System.ServiceModel.Activation.HttpModule error

what is the cause of this error on below line?
<system.web>
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="fa-IR" uiCulture="fa-IR" />
<compilation targetFramework="4.0" debug="true">
<assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Everywhere the problem to this solution was mentioned as re-registering aspNet by using aspnet_regiis.exe. But this did not work for me.
Though this is a valid solution (as explained beautifully here)
but it did not work with Windows 8.
For Windows 8 you need to Windows features and enable everything under ".Net Framework 3.5" and ".Net Framework 4.5 Advanced Services".
Thanks
Neha
This happens when you install .Net 4 before enabling IIS, or if you register WCF after registering .Net 4. In either case, your App Pools will be running .Net 2.0 (which is the CLR version required for .Net 3 if you have registered WCF, which installs ASP.Net 3.5, or the default if you have installed IIS after .Net 4)).
There are many references to this on the web, e.g. the MSDN blogs:
http://blogs.msdn.com/b/webtopics/archive/2010/04/28/system-typeloadexception-for-system-servicemodel-activation-httpmodule-in-asp-net-4.aspx
The fix is to re-register ASP.Net 4 from the correct (32 or 64 bit) Framework folder (Framework64 on a 64bit server), using the aspnet_regiis.exe tool, e.g.
aspnet_regiis.exe -iru
For Windows 8 you need to Windows features and enable everything under .Net Framework 3.5 and .Net Framework 4.5 Advanced Services -> Enable Everything
For windows 8 the above configuration in
Control panel->programs->windows features on/off
enable every thing under".net Framework3.5" and ".net Framework 4.5 advanced Services"
Working fine for me.
Thanks Madhavi.B
I had this problem on a server managed by one of our clients. I didn't have the access to run the aspnet_regiis.exe tool. As a workaround I did the following:
I removed aspNetCompatibilityEnabled="true" from the <serviceHostingEnvironment> tag in the web.config
removed [AspNetCompatibilityRequirements] from the webservice.cs file
Unfortunately this means that for example HttpContext.Current becomes null, I could fix my webservice by rewriting all my HttpContext.Current.Server.MapPath calls to System.Web.Hosting.HostingEnvironment.MapPath
Hope this helps someone.
This problem surfaced for us immediately after we installed the Windows Management Framework 3.0/PowerShell 3.0 sp1 (KB2506143) on a Windows Server 2008 R2 x64. Windows Update then also installed KB2736422, KB2756921, and KB2656411 immediately after.
Our solution was to first uninstall KB2506143 (and the three updates that accompanied that), then run aspnet_regiis.exe -iru as suggested in Ed209's response above. Both steps were necessary to resolve the problem. Thank you, Ed209.
appcmd.exe set config -section:system.webServer/modules /[name='ServiceModel'].preCondition:"managedHandler,runtimeVersionv2.0" /commit:apphost
worked for me

how do I know if the correct .NET framework is installed?

I am a developer and am trying to create a very basic "Hello World" .NET 3.5 web app. However, whenever I publish the code I am getting the following error.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load the assembly 'App_Web_default.aspx.cdcab7d2'. Make sure that it is compiled before accessing the page.
Source Error:
Line 1: <%# page language="C#" autoeventwireup="true" inherits="_Default, App_Web_default.aspx.cdcab7d2" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Here are the steps I'm taking.
Open VS2008 and create a new website using C# and .NET Framework 3.5.
Update Default.aspx to say "Hello World"
Make the following changes to web.config
** add <customErrors mode="Off"/>
** comment out <authentication mode="Windows" />
Publish the site, checking the boxes for "Allow this precompiled site to be updateable" and "Use fixed naming and single page assemblies"
What I would like to know is if this is something I am doing wrong or something our web admins have setup incorrectly.
Would/could it have anything to do with where the /bin directory is located?
If you do not have access rights to the deployment server, best way to learn the framework version which your application running is to look at the bottom of the common ASP.NET error page. You can find the Framework version like that :
Version Information: Microsoft .NET
Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053
Here is a post from MSDN:
http://msdn.microsoft.com/en-us/kb/kb00318785.aspx
Are you using the correct .NET-version in IIS ?
The version in the combobox must be correct:
(screenshot only showing .NET 1.1 & 2.0)
alt text http://helpdesk.nucleus.be/content/installatie-van-dot-net-3-5/iis_dot_net_3_5.jpg
I would start by publishing the site without pre-compilation first. If it still does not work, then work with your web admin to check the following:
You can see which versions of .net are installed by looking in:
C:\Windows\Microsoft.NET\Framework
You should have a folder for every version of the framework installed, for example:
v1.0.3705
v1.1.4322
v2.0.50727
v3.0
v3.5
If IIS was installed after .net 2.0, you may need to run aspnet_regiis to install or repair the .net IIS installation:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i
Please note that in IIS you will only see v1.1.4322 and v2.0.50727 in the framework dropdown (.net v3 and v3.5 use the v2.0 runtime). Your site will need v2.0.50727 selected.
You will also want to make sure that the account your web app is running under (usually Network Service on servers) has the correct permissions on the folder that contains your web app files (read should be sufficient for your test).
The problem actually was that our web admins set up the site at a higher directory then what I thought. Therefore, when I published the site, the bin folder was not at the root of the site. That is why the files could not be found.

Resources