IIS stops responding after recompile - c#

I have my web app I'm developing under local IIS (so not not the visual studio embedded one). It works fine, I can go from page to page...
But if I then change the code and recompile, IIS stops responding properly for ~2 minutes. If I attach the debugger, then there's no executing code, but it just won't serve any pages.
If I stop the App Pool in IIS, then I get a 503 error instantly, but I then am prevented from restarting the App Pool for ~2 minutes with error: Cannot Start Application Pool / There was an error while performing this operation. / Details: / The service cannot accept control messages at this time. (Exception from HRESULT: 0x80070425)
As you can imagine, this is crippling my productivity. Only started happening a couple of days ago, I haven't made any changes to the code which I would have though would cause this problem... and it doesn't matter which page I touch and recompile anyway, it takes just as long to recover. Nothing in the event log.
Any clues as to where to start looking?

Add the following line to your web.config:
<compilation optimizeCompilations="true" />
related article: http://www.dnnsoftware.com/community-blog/cid/135019/a-small-webconfig-setting-that-can-save-you-development-time

I had a similar problem and the installation of the following hotfix fixed the problem for me:
https://support.microsoft.com/en-uk/kb/3090034

Related

IIS Application Initialization with IIS 10.0 and WebAPI

Hello and good morning everyone,
I ran into an issue where the services once started, are no longer subscribing to the service discovery. In testing they were running under IIS Express. However once I flipped it over to IIS and verified everything was still working; the service no longer hits the Application_Start() within the Global.asax.cs.
Doing a bit of research, it appears that IIS requires a little configuration to get this to do some initialization work once the Application Pool is started. I am running this in a Windows 10 Professional environment with IIS 10.0.17763.1
The goal: Get the service starting up to subscribe to the service discovery was it was running under IIS Express.
I first found on the MSDN the documentation for setting all of this up including prerequisites here IIS 8.0 Application Initialization
After going through all the steps and updating the required config entries, it appears I am still not Initializing my web service when the Application Pool starts.
I have created a new endpoint on the controller for testing purposes to get this to work.
AccountController:
[System.Web.Http.HttpGet]
public IHttpActionResult Init()
{
// here is where I am registering the service thats coming up
}
Route Definition file:
{"Name": "Account - Init",
"RouteTemplate": "api/{controller}/init",
"Defaults": "controller = AccountController, action = Init"}
Web.config
<applicationInitialization skipManagedModules="false" doAppInitAfterRestart="true" remapManagedRequestsTo="/api/account/init">
<add initializationPage="/api/account/init" />
</applicationInitialization>
I am under the assumption that the Initialization will only happen ONCE, and that happens when the Application Pool first starts, or is recycled. IIS internally will make a 'managed' call to the Web Application against the mapped resource it finds in the application's web.config file. Is my understanding of how it should be working incorrect? If so, could someone please clarify why?
I am not simply trying to 'get this to work'. I would like to understand why its 'not' currently working for me.
Thanks to all in advanced who take the time to respond here.
that is correct, your web.config will only be read once when the application starts.
you can add some logging messages to see it happen.
You can actually hit debugger points if you manage to connect your Visual studio to the application pool of the IIS process in time. There is an option to attach the debugger to a process, so you can use that.
This is painfully obvious in systems where the AppSettings are in a separate file, not web.config. if you make a change, nothing will happen, until you touch web.config which triggers an application restart.
Following up,
I fixed my own problem. It appears the code IS working correctly, that its hitting the Global.asax.cs Application_Start as it should. I had an exception being thrown not related to IIS after a change I made which was resulting in what appeared to "not work".
Following the instructions on the MSDN does work.

Sudden IIS application's shutdown

I have a multiple versions of an ASP.net website, all of them are working fine except the latest version which recently started to stop suddenly. Each version runs in a different application pool. Our investigations resulted in the following:
Application_End event is getting fired after couple minutes from starting the web application. However, the Application_Start is not being triggered after that.
After the application is stopped, most pages works with no styles, as our styles are bundled using "BundleTable". All bundles return 404 error, but the login process which relies on a web service works fine, and moves me to the home page (with no styles due to 404 response)
Requesting any physical resource (image/js/css/svc) works fine
After the Application_End event get fired, the w3wp process related to this application's pool remains running. Killing it with task manager makes no change. it will start again without causing the application_start to get fired
Stop/restart/recycle IIS/pool doesn't cause the Application_Start to get fired (I'm checking using custom logging). Deleting asp temp files sometimes works but not everytime. Now I've tried everything but couldn't make it start again!
List item
I'm using windows server 2012 64x, with IIS 8.5 and .net V4.5. Any hints are appreciated
Update-1:
Here is a snapshot for the page with errors.
Update-2:
After making few tests and adding more logs here and there, I can summarize the issue in a simpler way:
First the issue shows only and only in the case I enable the "precompile during publishing" option while publishing my website, and merging all output DLLs in single assembly.
After publishing with the above configuration, the Application_Start event will triggered on first page request, which is normal, and the main code I have in this event is to register all CSS & JS bundles, and configure URL routing. The application will work fine for approx. 30 minutes, then the Application_End will be triggered (with "HostingEnvironment initiated shutdown" shutdown reason) but the Application_Start won't be triggered again!. The Strange thing that the application will continue to serve subsequent requests (Ex: connect to database, do logging, authenticate users, serving WCF services requests...) but all bundles and URL routings that are registered in the Application_Start are lost. Another hint that general errors (Ex: 404) which are processed in the global.asax file are not getting processed after the Application_End is triggered! It seems like the application just ignore or forget to process this file again!
The issue is finally solved after fixing all compilation warnings. I can't tell which one has fixed the issue, but thought to share my experience anyways. The warnings found was as for the below:
Removing unused variables (about 10) (shouldn't affect)
Duplicated namespace importing (about 10) (shouldn't affect)
We had an outdated WCF service proxy. So we generated the new one (couple new methods were not added, and some changes on data types. However, this service is usually being called by some external extension that was out of our testing scope
A warning related to a conflict in culture settings (AssemplyInfo.cs-> AssemblyCulture) between referenced projects (also not sure if this could affect, as when doing normal publish without merging pages & controls assemblies we don't have any issue)
Regards,

Azure Website Error 502

I have an ASP.NET Webforms Application on Azure but i always get the following Error on some sites:
502 - Web server received an invalid response while acting as a gateway or proxy server.
I already read a lot of topics regarding the 502 error on Azure but i still don't understand what the problem in my particular situation is.
The error occurs just on some site of the application. I can always reproduce the following pattern:
Open SITENAME.azurewebsites.net -> Error occurs
Open SITENAME.azurewebsites.net/Site1.aspx -> Error not occuring
Open SITENAME.azurewebsites.net/Site2.aspx -> Error not occuring
Refresh SITENAME.azurewebsites.net/Site2.aspx -> Error occurs and won't go away until i call Site1.aspx again
The only thing i found in the log is, that the application loads System.Windows.Forms.dll and there is an AccessViolationException. I have no idea why this dll is loaded at all because there is no Reference in any Project in Visual Studio to it but thats another story :).
But what i don't understand is that the error 502 does not always occur on Site 502.
Maybe someone can give me a hint what might be the problem or how i could find it...
Thanks for your help!
EDIT:
What i forgot to mention: In some threads regarding this error i read, that it occurs after 3 minutes or something like that. In my case it is nearly alway about 25 seconds until the errormessage shows up.
That points to an application issue. The reason you are etting 502 is because the worker process is crashing and the front end is left with a request with no response and returning a 502 to say exactly that. Look for eventlog.xml under the LogFiles folder for your website. Alternatively you can try remote debugging from VS to your website.
System.Windows.Forms.dll contains a lot of UI code that will most probably not work Azure websites sandbox. The reason it's loaded is probably because you are using something from the assembly or using something that uses something from that assembly. It doesn't have to be listed in Visual Studio to be loaded since it's a part of the standard .NET Framework.
I would suggest looking into remote debugging and figuring out at what point this is getting loaded and why.
In my case, I got 502 errors because the site was restarted by the azure auto-heal system. It turns out I made tests with that auto-heal system a few days ago, but since in the end I disabled it, I didn't think it could cause my 502 errors.
This is where I discovered that the azure interface to change auto-heal settings (mywebsite.scm.azurewebsites.net/Support -> mitigate) only affects the production slot. But when you swap your deployment slots, the settings get swapped. There is apparently no way to directly change the staging slot settings, you have to swap, change settings, and swap again.
So, I ended up having my staging slot with auto-heal enabled, and my production slot with auto-heal disabled (and of course at that time I thought it was disabled on both slots). Then I was "randomly" hitting 502 errors either on staging or production depending on how many times I swapped them. What's weird is that though the application seems to restart (or at least fails to respond to a few requests), I don't get the corresponding events in my log file, like if it wasn't running Application_Start after an app pool recycle triggered by the auto-heal system.
Took me a whole day to find out what was happening, I hope this answer can help someone in the same situation.
I got the error for a while after fiddling with connection strings, went away and came back in an hour, and the issue had disappeared and the site worked normally again. A highly technical answer for you.

ASP.net Web Application Pages Stop Responding (Web Forms) on IIS 8

Well, we have an web application deployed on:
Windows Server 2012
IIS 8.​
Target .net Framework 4.0
DevExpress Ver: 13.1.8 (third-party controls)
Now the issue is this, some of the pages stop responding when we try to load them. (after few time- not specific)
To make them in working again we have to restart 'World Wide Web Publishing Service' or sometime 'IIS' as well.
But after few hours, again the pages stop responding. Browser does't even give any error message, just keep trying
to load page and go in 'Waiting for Server Response' state.
And this behavior is not for all page. Even under this scenario some other pages still work. It means application is running
but some pages are note working.
I have also check that there is no dead lock at database level.
Also, IIS 8 is enable with both 3.5 and 4.5 options.
Note: We have some other applications on the same server running fine.
Can you please suggest me that how can I resolve this issue,
Thanks
Qazi
​
I suggest to create a Hello World! page and load it.
If the Hello World page even doesn't load, analyse the IIS log .
especially look at the value of "Win32Status" . If its not 0, use - net helpmsg [Win32StatusCode] in command line . This should give you enough clue for troubleshooting.
I suspect it is the HTTP Compression that is causing the issue; dump the HTTP Compression in Web Extensions, and then it will behave better.
Check also your CPU and RAM workload.

"A timeout was reached while waiting for the service to connect" error after rebooting

I have a custom-written Windows service that I run on a number of Hyper-V VMs. The VMs get rebooted a couple times an hour as part of some automated tests being run. The service is set to automatic start and almost all of the time, it starts up fine.
However, maybe 5% of the time, with no pattern that I can discern, the service fails to start. When it fails, I get an error in Event Viewer saying
A timeout was reached (30000 milliseconds) while waiting for the My Service Name service to connect.
When this occurs, I can start the service manually, or restart again, and the service will start fine.
The thing I can't figure out is that the 30 second timeout doesn't appear to be occurring in my code. The very first line of my service class's OnStart() method logs "Starting..." to its log4net log. When the service fails to start, I don't even get anything logged at all, which indicates to me that either log4net can't log for whatever reason, or the timeout is occurring before my OnStart() gets called.
The service runs on a variety of OSes, from XP all the way up to Win7 and 2008R2, and I know that setting the service to delayed start may solve this for Vista and later, but that seems like a hack.
I haven't been able to remote debug this because of the fact that it happens so intermittently and during system startup, and I'm at a loss as to further ways to try to figure out what's going on. Any ideas?
My guess - and that's all it is - is that the disk is thrashing hard during startup, to the point where the .NET Framework itself isn't starting in the 30 seconds that Windows allocates for services to start.
A kludgy workaround may be to set the service to start manually, then write a very small stub service in unmanaged code (e.g. C++, Delphi) to start the service.
Another approach may be to start the service remotely from another machine. The sc command should do the job nicely.
I was seeing this error in the Event Viewer when trying to install a service with powershell.
The problem I had was that I had different values for "Service Name" and "Service Display Name" in my powershell script to those that I had specified in the program.cs file of my Console Application.
For what it's worth, I discovered that I received this message (almost immediately upon service startup) because I did not have version 4.5 of the .NET framework installed on the target machine. I rolled back the version I was using to version 4.0 (which was already installed on the target machine) and the service worked as expected.
I think I may have also found another contributing factor to this kind of does not start on reboot error.
It appears that if the Windows Event Log is set to Overwrite Events > 7days.. size 512kb.. But a lot of activity has occurred within this window, then Event Log is effectively full because it can't overwrite the number of events generated inside that timeframe. If you set the eventlog to a much larger size OR to Overwrite as needed then you won't experience this issue
My issue with the same error was that the .Net installation on the server was not working correctly.
To figure this out:
I made a small console app with identical logic as the executing service, and I made a try-catch around the whole code piece, dumping it all out to console.
Not sure why the information didn't bubble up, but we saw the valuable messages about the Framework errors that we would never have seen otherwise.
We are having the same problem on Windows 2016 Server.
A fix that seems to be working is changing the user under which the service running from Local Service Account to local Administrator (not sure what's the cause).

Categories