Object reference not set to an instance of an object-datacontext - asp.net

I am trying to publish asp.net mvc site on remote server I am getting the error as shown in figure. Any idea

I solved it the problem was that in the designer file connection name was different then that of web.config. Once both name are same it started running fine.

Any chance you could post a larger scale of the image, the stack trace is very tricky to read.
As a guess, it looks like the exception is being raised in the database context area of code - possibly Entity Framework??
First, have a look at the Models.EvloetDatabaseContext constructor - is there anything in there that might cause the null reference exception?
You could put some Trace.WriteLine calls in that method and use a tool such as DebugView to see how many of those messages are being sent out. I use his often when debugging issues on a client's server.

Related

Strange Code first Migration behavior, or IIS issue?

Ok, so the background is this.
I have created a hardware controller for a fingerprint reader, and a web application that allows users that have scanned in to do things in the web application. The web application was created using Code First, and the communication is done through signalr 2.0 The problem that I am having is this. Everything works beautifully for about a day, this used to be about half a day, but in IIS 7.0 I changed the idle time on the application pool to 200 mins, but I am still getting an error at random times on the web server, I have managed to have extended the amount of time that is stays running. However, what confuses me, and why I cannot seem to get a handle on what is happening is that when it does go down;
A) I do not know why? (I am leaning towards a timeout somewhere)
B) The error message is the same one you get when you make a change to the database structure and forget to use Database-Update from the package manager console, Yet no one is changing the database.
c) If you leave it alone it will fix itself, and I do not know why or how.
Has anyone seen behavior like this? and if so what caused it and how did you fix it? Or can anyone offer how I can debug this?
Thanks so much for any help!
Kelso
If the exception is "The model backing the 'YourContext' context has changed since the database was created. Consider using Code First Migrations to update the database" you could try to catch that exception and log the content of the following method and compare it to the return value of the method in Application_Start or whenever it worked for you.
((System.Data.Entity.DbContext)(context)).InternalContext.QueryForModel(0)
The method gives you a XML representation of your database schema.
Just to update on this issue, it turns out that the IIS server had been set to only a single CPU and a single thread, (VMare setting) and that thread was getting hung, and could not create a new thread to continue processing, once we updated the cpu's and increased the thread count to 5, everything works like a dream.

Asp.net Web API self host service unhandled exception when client drops connection

I'm using web api self host inside a windows service and I've encountered a problem and after googling for couple of hours haven't found a reasonable answer.
One of the api controllers serves large stream of data (not really that large, couple of tens of MB). It takes some time to produce data so I've decided to use TransferMode.StreamedResponse to minimize the time client has to wait for response. I've also added a CompressHandler and custom CompressedContent (derived from HttpContent) mostly based on a following answer.
The controller returns an instance of IDataReader, which is then serialized by custom formatter which is lastly compressed inside CompressedContent that I've mentioned. The whole data passing is streamed so while the client receives data, a data reader on server side may still be reading rows from database. Everything works fine when client is acting nicely.
The problem occurs when a client drops connection while the data is still being serialized to the underlying network stream. I've tried to watch for IsFaulted task inside of ContinueWith delegate (in CompressedContent from the link) and dispose underlying network Stream. Unfortunately the CommunicationException (The specified network name is no longer available) is still being thrown when the control leaves my code. From the stacktrace it looks like the exception is thrown when the Web Api tries to close (end) the underlying network stream (http channel?). As it happens with unobserved exceptions it brings entire windows service down.
I've mitigated the problem by setting windows service recovery options but I would like to know if this failure can be handled in code.
Is there a way to setup a custom error handler (IErrorHandler presumably) inside web api self hosting service mode to prevent this kind of error?
I'm using Beta version, I will try to reproduce this error on RC but I somehow doubt that setting up this kind of error handler would change in any way
We had the same issue. I was able to submit a fix to MS and they have in turn released a nightly build that fixes this. They are looking at back porting the fix to the RTM. You can see the pull release here: http://aspnetwebstack.codeplex.com/SourceControl/network/forks/rdean79/issue284/contribution/3329

How to get more info on NHibernate's Illegal attempt to associate a collection with two open sessions

Our project has been using NHibernate with success for quite some time. However, in the last months of new development we managed to make a change that gives us lots of:
NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
This shows up on our test server. It does not/hardly happen on our development systems.
Question: Is there a way to find some more info about this exception. It would help if we knew e.g. which Collection is giving the problem.
We tried NHibernate Profiler but that does not give that type of information.
Thanks, Willem
NHibernate uses (by default) log4net for logging.
You can configure it, set the DEBUG level for the root logger, and you'll get all the possible information about the inner workings of NHibernate related to the error.
Of course, you can also get a stack trace of your own code, figure which calls are causing the exception, and post them here.

Error reporting from Flex app

I have a Flex 3 app which I want to instrument to report errors generated by the app to a server via simple HTTPService call.
My idea is to wrap all the methods in try ... catch blocks which then pass the Error object to the reportError() function (which then fires off the HTTP request and pops up a dialog) but is there a better way?
I have implemented a system such as the one you suggest, wrapping all of my methods in try/catch and sending the stack trace to a service that emails me the errors. I created a basic format for the error that logs which method the error occurred in. I noticed that sometimes I end up getting null from the stack traces, so I wanted to log that information for these situations.
It GREATLY improved my application. I tracked down a (large) handful of errors and released a much cleaner build to my users. Now I don't ever get the emails.
The better way IMO is something like this.
I've no idea how good is this particular project (aside from this spooky GPL license), but I don't see why logging in action script should be any different from J2EE, C++, or say Python. Yes, it has some sand box security issues, but I think if this solved, you could log into some centralized log server..
Unfortunately, there really isn't -- errors don't bubble up in such a way as to be trappable at a global level, so the only real way you have to catch errors is to try and catch them all manually. (The community's been pretty vocal in asking for a global exception-handling feature for a while, but it's not there yet.)

ServerError due to Memory issues?

In my Project (ASP.NET, VB.NET), sometimes a Server Error is showing.
When this error is shown, Users cannot submit their Applications, so that they have to re-type full details and submit again.
How can I escape from these Server Errors?
I think the reason may be Memory issues. Because if the user try to submit again (after Sign Out->Sign In ) then they can submit. Daily twice or thrice Error is happening.
The word "Server" in the phrase "Server Error" refers to your ASP.NET code. You are the server!
If you are running .NET 2.0 or later, you can look into the Application event log (use the Event Viewer applet) for warnings from "ASP.NET". They will include details of what went wrong.
You need to debug your code to find out what's causing this, but the event logs will give you a starting point.
"Server Error" is just a generic message that indicates the the server code (your code) threw an exception that wasn't handled. It shows the user "server error" instead of a specific message so that no implementation details are exposed to outside users.
In other words, without debugging or looking at a log file or something, all you can tell from "Server Error" is that an Exception of any type was thrown.
Sorry, but the information you provided is not helpful in determining the issue.
I think that you'll need to provide a bit more info to get meaningful solutions.
Do you have server logs?
Can you debug through the app as the error occurs?
Does the error occur at a certain time of day, or after a certain regular action?
Does your app attempt to write to a file that may not be accessible?
is it possible that you are experiencing memory issues?
the list could go on, best to do some more investigation and if a more specific issue comes to light edit your question with the extra detail.
AFTER EDIT:
From the extra detail you've provided I wouldn't jump to memory as an issue, in signing out and back in the user is refreshing their session so everything is reset. If you are not seeing anything in your logs you'll need to look at your exception/error handling.
You just haven't provided enough info yet for us to work out the root issue, let alone suggest a solution. That's what you're seeing from all the answers here thus far. Find the event log info and there should be something there to help you, or at least something more to post here.
Try debugging the error? Server Error can be caused by various reasons.
Check for potential infinite loops.
Check for code in the constructor that might fail (especially for web services).
I think I've had cases like this which led to 'Server Error'. I'm assuming you mean the big red 'Server Error' message?
Save all your files and close your Visual Studio and now right click on Visual studio and run as administrator. It worked for me.

Resources