Intermittent occurrences of "Bad image format exception" on aspx pages - asp.net

We are seeing some strange errors on our asp.net webform sites. The sites are compiled successfully and deployed to our prod servers where they start and run without any problems.
Every morning at around 3AM we restart the application pool and here is where the mystery begins. Occassionally, let's say about one out of three times, after the restart we get the error below. The affected aspx page differs from time to time (the unaffacted aspx pages work just fine).
System.BadImageFormatException: [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\f7681018\abf51a9e\App_Web_xegahzdu.dll] A valid typedef or typeref token is expected to follow a ELEMENT_TYPE_CLASS or ELEMENT_TYPE_VALUETYPE.
at ASP.startpagetemplate_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
We have four servers in a load balanced environment and the error appears on different servers and (as stated before) on different aspx pages. I have tried to read up on the exception, but the cases I read about differ from our case as they occur instantly. Our site builds and starts fine. The error appears after an application pool restart but, notably, not after every restart.
Would be grateful for any suggestions on what to look for.

Related

Webforms showing source code instead of rendering

I'm working on a legacy project that used Webforms. There is now a bug occurring on our production servers where a few of the web pages will show source code. I cannot replicate this on our test servers or by debugging it.
If it shows source code it will persistabtly show source code until the in-private/incognito window is closed and a new one is open.
It will occur about 50% of the time (out of 100 recorded tries it failed exactly 50).
This is a screenshots of some of the source code I'm seeing:
and
A commonality between the pages that break are that it uses AjaxControlToolkit, however there are other pages that use AjaxControlToolkit that aren't breaking.
Additionally, when I try to hit these pages they don't hit the page at all. If I'm not signed in they should redirect to the login page and they don't even do that.

What exact settings required in iis for asp.net pages to process it faster?

I am having a simple blank page without any source code.The page also taking very long time to come.I am not able to understand the reason behind this.
The domain is getting a high requests.
What exact settings needs to be done in iis 7.0 so that it will be faster.
Please help.
ASP.NET pages always have an initial delay when the first request is made after the file has been created/edited/uploaded because the server needs to recompile them, however it shouldn't be more than 2-3 seconds in practice, and does not affect subsequent pageloads.
The only thing I can think of is an overloaded server. Assuming you're on a shared hosting package then I recommend you find another ISP. If not, then I'm afraid there's a lot more to it than just a "page pages load faster" switch hidden away.

Most elements of an ASP.NET page are not rendered after random idle time

We have been trying to figure this one out for a while now, without any luck.
The symptoms are as follows:
After some idle time of a specific ASP.NET 2.0 application (can be from several hours to days), one of the pages in my application stops working.
When viewing the source of the page I see many elements missing, elements that are usually there, such as: reference to WebResource.axd, the __doPostBack() function, all of the UserControls and more.
A reference to ScriptResource.axd, and the __VIEWSTATE are there.
After recycling the app pool, the application starts working correctly again and everything renders well.
This only happens on a specific server, when deploying the same application on a different server, this error does not occur.
The page that the error occurs on has only one UserControl which is not rendered when the error occurs. Nothing special happens when this page is loaded.
We tried doing periodic client refreshes, but that did not help either.
Thanks in advance.
It was a caching issue. There was a part in the code that hid specific controls when the cache was invalid. That explains the missing code parts.
I am still not sure why the cache was invalid on that specific server.

Asp.Net Impersonation Fails On First Try But Succeeds on Second

We are using RDLC's in a Asp.net web application. For reasons beyond our understanding, the first call to the database server fails with the following error:
An error has occurred during report processing.
Cannot open database "TryParkingIt2" requested by the login. The login failed. Login failed for user 'EXTRANET\OurServerNameHere$'.
Run the report again, it works.
Huh?
Update Click the button the first time, it fails. Click the button again, it works. The account being impersonated is a domain account. Also, this error occurs on all five different report pages, which is why I didn't include any code.
Look for static constructors or global.asax code that is failing. Those are run only once when the application starts up (actually for static constructors are run when the class is first accessed), so often they will cause a failure the first time, and then everything seems to work fine after that (even though something is really busted up in the background).
BTW, this is a GREAT reason to avoid static constructors.

ASP.Net Page Sometimes Freezing Before Page Loads

I have a pretty standard ASP.Net page written in C#. Most of the time it loads just fine and works a treat but occasionally the page won't load, I've inserted break points in the Page_PreInit (I don't actually have any code here, I've just created the function so I can see if the codes getting this far) but it's not getting this far. Any ideas where I should start in looking for a solution?
A couple of things to help you debug
Turn on tracing http://msdn.microsoft.com/en-us/library/y13fw6we%28VS.71%29.aspx
It may be throwing an exception you aren't seeing (although I would expect it to give you the YSOD...). Debug the application and turn on "Break when an exception is thrown" for Common Language Runtime Exceptions (hit CTRL+ALT+E to bring up the options)
When the page doesn't load, what happens? Does it never finish loading, do you get an error message?

Resources