Exception that goes away with Clean/Rebuild. How to diagnose/prevent? - asp.net

Pre-Problem: our office was hit by a worm due to a corporate patching oversight, and the boys in the lab repaved my machine. I needed to re-install all my development tools (Visual Studio 2005, SP1, and the Web Application Project Setup patch) again. The following problem did not occur before this event.
I've been working on an ASP.NET web application project for several months now. I've been editing, debugging, etc without a problem. Then, I added a single line of code, ran it in Debug and got this error:
System.Web.HttpUnhandledException:
Exception of type 'System.Web.HttpUnhandledException'
was thrown.
System.IO.FileLoadException: The given assembly name
or codebase was invalid. (Exception from HRESULT: 0x80131047)
I uncommented the new code, built the project and ran in debug again, but got the same error.
New Code:
Me.frm.btnSubmitChanges.Attributes.Add("onclick", "javascript:return validateSubmit();")
The only way I've been able to fix this is to Clean, then Rebuild the project. I haven't been able to trap where it's happening using breakpoints.
It's happened a couple times in the last few days. What should I be looking at to fix this?
Thank you!

Have you tried to enable Fusion Logger to see if it's an assembly that is failing to load? In C# you can tell the debugger to break at any exception (There's a command you can add by customizing the tool bar called Exceptions). I'm not sure if VB has this but I would assume they do. Can you tell it break on FileLoadException and that might help you understand what's going on.
The line of code you added is pretty innocuous. When you add the code it breaks, have you then done a clean build with that line of code still in and does it work or not?

I did run the Fusion Logger, but did not get any results when the exception occurred. I tried all 4 settings.
The new line of code runs fine after a clean/rebuild.
I haven't used the break on all exceptions before; I'll see if I can find it.

Related

ASP.NET deployment error

I am attempting to deploy a change to a legacy ASP.NET solution. I have copied over the views and css files, but when I try to copy over a modified assembly, I get this error when the application runs:
Compiler Error Message: BC30456: 'InitializeCulture' is not a member of 'ASP.dashboard_aspx'.
I understand that the site may need to recompile itself, but it is complaining about a view I haven't changed. It is also griping about missing member InitializeCulture which I can't even find a reference for in my code.
The site works fine in debug and when deployed locally BTW.
Any ideas?
In the end I lost patience with trying to deploy what I thought had changed and simply published the website to a directory and then copied that over en masse.
Clearly there is some code or linkage somewhere that I had overlooked but the error message is a complete red herring.

What is causing intermittent "Object reference not set to an instance of an object" at compile time in VS 2010?

I am sorry if this is not really a coding question (it depends on if its my code causing the problem I suppose).
I have seen this question: Tracking down intermittent 'Object reference not set to an instance of an object.' error on build
However, it has not been of much help (although if you read the comments, you will see that I thought it did help for a while there).
When I try publish my website, occasionally, I will get an error with no file or line reference:
Pre-compiling Web Site
Building directory '/App_Code/'.
Building directory '/'.: Publication (web): Object reference not set to an instance of an object.
Pre-compilation Complete
------ Skipped Publish: Project X:\, Configuration: Debug Any CPU ------
I know the usual causes of "Object reference not set to an instance of an object" but this seems a bit different, isn't it supposed to be a runtime error? Not a build error?
What is weird is that it happens, seemingly at random (about 25%-33% of the time). I can try to publish it and have it fail. Then try again straight after, without changing anything and it works fine.
I started getting this error after moving some of my functions (VB.net btw) to a new file in the App_Code folder so they can be accessed by all pages of the site.
If you need any more info, please let me know.
Thanks,
EDIT: After further investigation, it seems to only happen if I try to publish the website within a few seconds of saving changes to any file within it. What could cause this?
The same error occurred for me to, I deleted the dlls of the custom controls in the web site that are already in the bin, then i published the web site, and succeeded
IF you have any custom/usercontrols in your project, they are actually running at design time and can give object ref errors. This can occur during builds too. In that case, a property is being referenced that is NOTHING and throws the error.
I had a similar problem with a Windows Form project.
Wherever I try to move a custom control on the windows form, and then try to save the form, VS2010 comes back with "Object not set to an instance of an object".
I suspected the error was deep down in the layers of abstraction in my inherited code, but couldn't work out how deep to go, without reviewing every line of code.
My solution to this problem is this.
Open up another instance of Visual Studio 2010
Menu: Debug | Attach to Process..
Search for "devenv.exe xxx YourApplicationName..." and select it
Click "Attach"
Menu: Debug | Exceptions..
Tick all the boxes in the thrown column, then "OK"
Your second instance of VS2010 is not debugging your first instance, including all the custom controls.
Return to the first instance of VS2010, and repeat the actions that caused the error in the first place, the second instance of VS2010 will break at the line of code that has the error.
You may want to look at this link there is a bug in vs2012
https://connect.microsoft.com/VisualStudio/feedback/details/749901/error-when-i-click-publish-object-reference-not-set-to-an-instance-of-an-object

VS2010 and ASP.NET unit test problems / WebHostAdapter exception

I've spent half a day trying to get an ASP.NET unit test to work as described in Alan's Development Blog. I don't have VS2008 but VS2010 with SP1 and Resharper 5.1, and no matter what I try I just run into different kinds of errors.
When I add a test project with a test method as follows and specify .NET 4 as target framework, I run into exception
Updated to show more detailed information about the exception
"The test adapter 'WebHostAdpater' threw an exception while running test 'TestMethod1'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:49676/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error..."
[TestMethod]
[HostType( "ASP.NET" )]
[UrlToTest( "http://localhost:49676/Default.aspx" )]
[AspNetDevelopmentServerHost( #"C:\...\Projects\ProjectX\ProjectX\", "/Default.aspx") ]
public void TestMethod1()
{
}
I've performed numerous searches on the internet regarding this error message, but never really found a solution - I tried adding a section so all users would be allowed access to "VSEnterpriseHelper.axd" which is also mentioned in the error message, but it didn't help.
Trying to set the test project's target framework to .NET 3.5 also doesn't help and returns the same error.
While playing around with different settings I also happened to get the error message that the assembly "Microsoft.VisualStudio.QualityTools.CommandLine" couldn't be loaded, even though I added the correct version (with the correct public key token) as reference.
Maybe the combination of things (ReSharper, .NET target framework, ...) messes things up, but I also tried disabling the ReSharper unit testing so that MSTest would be used, unfortunately to no avail.
The description in Alan's blog post seems to be quite straightforward, but it doesn't want to work for me.
Update 2
I also tried to run the example projects from Alan's page in VS2008, but the error is still the same as in VS2010 SP1.
Update 3
Still no luck, but I've added the file Microsoft.VisualStudio.Enterprise.AspNetHelper.dll (located in %PROGRAMFILES%\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies) to the web.config as a ConfigurationErrorException in the Windows Event Log indicated that this file was not found:
<dependentAssembly xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentityVersion name="Microsoft.VisualStudio.Enterprise.AspNetHelper" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<codeBase version="10.0.0.0" href="file:///C:/Program%20Files%20(x86)/Microsoft%20Visual%20Studio%2010.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.AspNetHelper.dll" />
</dependentAssembly>
This fixed the problem with the AspNetHelper.dll, but I get the same error message for the AspNetAdatpter, but amending the web.config in the same way doesn't work as the error persists. Within Visual Studio I can also see that (when I try to add a handler entry as shown below) the QualityTools.HostAdapters.ASPNETAdapter part is shown in red, indicating in a tooltip "Cannot resolve symbol 'QualityTools'":
<add name="HostAdapter" verb="GET" path="ASPNETAdapter" type="Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
This is all a big mess, and it seems I've completely lost track, why does it seem to be impossible to run ASP.NET unit tests within VS2010? Is there nobody else who's got the same kind of problems (or, ask the question differently, is there anybody who can run ASP.NET unit test in VS2010 without problems)?
Still trying to get things working...
Update 4
Still no luck, am I the only one? Who can run such tests?
End of update
Any ideas what I'm doing wrong here? Thanks in advance for any pointers into the right direction
G.
You can use Ivonna for Asp.Net testing. More features, and much cleaner test syntax imo.
I've run into the same issue, disabling code coverage analysis does fix this for me.
But unfortunately this is no option in my case.
I'm a year too late but i just had this error and had a quick google. All results said to disable code coverage but that option wasnt available for me. All i done was check the localhost ports and i had the wrong one and it all worked fine.
for those that don't know, run the project UI and check the process in the task bar. you can hover and check it or right-click and show details.
I changed this by double-clicking the testsettings and changing the host type to ASP.NET and then setting the "URL to test" to "http://localhost:49676/Default.aspx" the port number to change is in bold. however in the question at the top a tag is used "[UrlToTest( "http://localhost:49676/Default.aspx" )]". I think this does the same thing.
FYI, I've only been developing C# just over a year, sorry if I state the obvious.
I have a similar problem and the only solution I've found so far is changing the application pool to classic, instead of integrated.

ASP.Net MissingMethodException - "ctor" method not found

We are getting intermittent problems on a production server that we cannot recreate.
There are two very strange things about the issue. Firstly it's a method not found error on the constructor (ctor) for an exception handling helper class and secondly we have custom errors switched on for remote users and this property is being ignored.
The detail of the error is:
Server Error in '/MyWebsite' Application.
Method not found: 'Void MyExceptionHelperClass..ctor (System.Exception)'.
...
Exception Details: System.MissingMethodException: Method not found: 'Void MyExceptionHelperClass..ctor (System.Exception)'.
...
The stack trace is pretty unhelpful.
My thoughts are that there may be an out-of-memory error or something like that that is killing the page. When the exception handling code kicks in it tries to create an exception object which fails for the same reason giving this error.
However this is wild speculation. We are waiting for the event logs to see whether anything is amiss with the server but in the meantime does anyone have any thoughts or suggestions?
UPDATE:
It has proven difficult to get information out of the team responsible for the production servers but I have managed to find out that as far as load balancing is concerned, this site is currently only running on one server (this can be made to switch over onto another if necessary). Given that this is an intermittent problem and there is only one server involved, then I find it difficult to believe that this could be an assembly issue. Surely if it was then the problem would occur every time?
If you see this error happening on a site that has custom errors turned on, then the error is happening in the custom error handling routine itself.
From the look of the .NET error message it appears that your routine is expecting a constructor that accepts an exception by reference - your comment above shows a constructor that accepts by value.
Check carefully that there isn't a stale version of an assembly in your system somewhere. These can lurk in the Temporary ASP.NET Files folder; you'll need to do an "iisreset /stop" before you can clear them out.
In that regard it's always a good idea to make sure that AssemblyInfo.cs is set up to automatically stamp version numbers in some way. We have our version numbers tied to our source code repository system and CI build box so we can tell exactly what was in what assembly really easily.
I would use elmah: http://code.google.com/p/elmah/ to hopefully give you a bit more insight into the issue. It is free and can be used on an existing site without any recompilation. Try it - and post back if the issue is still happening.
As others have also mentioned, I would suspect that your site is somehow using an out of date version of an assembly. Something you could try doing is a full Precompile of your site before deploying to your production server. This ensures that ASP .Net doesn't dynamically compile the site on the fly, and therefore should mean that it's using completely up to date code throughout.
Do you have a no parameter public constructor defined for MyExceptionHelperClass in your code? Or is the class meant to only have static methods, in which case it should be a static class.
public class MyExceptionHelperClass()
{
public MyExceptionHelperClass() { }
}
Unfortunately, this may be one of those cases where the error message is of little to no value. In my experience, this general class of exception may be the result of either a configuration issue or bad logic aroung threading/app domains. For example, I have seen similar issues upon attempting to load the same assembly into an app domain more than once.
You mention that this is difficult to reproduce. If it's only happening on one server in the production farm it's more likely to be a config issue (with that machine). If it's happening on more than one server than it could be either config or threading.
It might be worth spending some time looking at the larger code base around the areas mentioned above. The root cause may not be in this class. Good luck!
I think it's a Framework issue with keeping compiled versions consistency. It's common to see same sort of errors while updating site sources repeatedly. Just try something like
net stop iisadmin /y && del /q /f /s "%systemroot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*" && iisreset
I encountered this exception today on a webforms page. I found a solution, but I'm not sure why it worked.
Nest the code behind in a 'Namespace [YourNamespace]' tag.
Add the namespace to the html Page tag's Inherits property in the aspx page 'Inherits="PathStart.YourNameSpace.ClassName"'.
Rebuild
Navigate to the page again and you should not encounter the exception.
After following the steps above I reverted the changes and did not re-encounter the exception.

Tracking down intermittent 'Object reference not set to an instance of an object.' error on build

I could use some help trying to track down an intermittent error that I've been having with our ASP.Net project for quite some time.
Intermittently when building the solution, the build will fail with the error "/: Build (web): Object reference not set to an instance of an object." The error has no associated file, line, column or project information. The weird thing about the error is that it will go away on successive rebuilds and doesn't seem to result in any run-time errors that we've come across once the build is successful. Sometimes the error will pop only once, sometimes 3-4 times, but eventually the build will finish successfully and then seems to build just fine each time after. I haven't been able to nail down a pattern as to why and when the error will happen, and since it always eventually builds it hasn't been a critical problem for us. Just an annoyance. But one that I want gone for obvious reasons.
I guess I should add that this is an application that was originally developed in ASP.net 1.1 and converted to 2.0 and I inherited it somewhere down the line after that, so I don't know when the problem originally surfaced. As far as everyone here is concerned, it's always been there.
Obviously I'm not expecting someone to pick out the cause of my problem as that would require them to look at our entire solution to pick out potential problems. Just hoping someone can give me a couple fresh ideas as to how to go about tracking down the actual source of the error in code. It has to be coming from somewhere, right? How would you go about finding out where?
I've seen this when you have a web control in a page where there is invalid HTML. If your codebehind is trying to do something with the control, it won't be able to find it and will give you Object Reference... error at compile time. In my experience, it doesn't create a runtime error, and the project will build if the file in question is closed at the time of build. HTH, Good Luck!
Run this command at the command line and see if you get some more detailed information
%WINDIR%\Microsoft.NET\Framework\v3.5\msbuild.exe YourSolution.sln /v:n
To follow up on this problem, we never did track down the origin of the error but it disappeared when we upgraded to Visual Studio 2008 and converted the project to a Web Application.
The first thing I'd try would be to increase the compiler verbosity. This can be set in the Visual Studio options - e.g. "Tools->Options->Projects and Solutions-Build and Run->MSBuild project build output verbosity" for VS2005. If you set it to diagnostic then it should tell you what it's doing at the time the exception is raised at the very least.
I had this problem for a long time and finally found a solution that work fine for me.
It doesn't make sense to me... but altering my web.config file with the following gets definitively rid of this intermittent build error :
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<!-- add this line below -->
<remove extension=".rdlc"/>
</buildProviders>
Hope this help !
I had this at build time when my project contained custom datasources (my own objects returning collections) with compile errors (that is, my objects had errors).
You'll also get this error if you try and add a datasource and your project doesn't have any datasources in the project's root (e.g. if you've put all your datasource classes in a subfolder). The only solution I found was to create a datasource in the project's root.
Sorry not to be more precise, but there seems to be several things that can go wrong with datasources/objects at compile-time.
An "Object reference not set to an instance of an object" is clearly a run-time error, not a compile-time error. So what that says to me is that Visual Studio is choking on something, which may not necessarily be in your code, or which something in your code is only indirectly causing.
Next question I'd ask: Does this happen only in Visual Studio, or does the same thing show up when you build using MSBuild or CSC?
What's really odd is that it's a run-time error. You shouldn't see that at compile time. Do you have any pre- or post- build steps attached to the solution? Any unit tests you're including with your 'build' process?
Where does this error show up?
Check the Application Log of your Event Viewer - It should tell you where the exception is being thrown.
Just to clarify, is it the compiler itself that is choking? Are you doing anything weird with #define and #if directives in your code? Maybe something is being done out of order at some point... Just a thought...
See if there are any post-build events that could be failing. These can be found on each project's property page.
Try using Rebuild Solution instead of Build Solution. You may need to add Rebuild Solution from Tools > Customize. If your web app installs or registers any windows services, and those services are started, Rebuilding plows through those types of problems.

Resources