Showing posts with label exception. Show all posts
Showing posts with label exception. Show all posts

29 November 2011

Error during serialization or deserialization using the JSON JavaScriptSerializer

Today one of the internal web applications that we have wouldn't run properly on my development machine (it works fine on the production server). When opened it would produce the following exception:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

It seems that the production server has a higher maxJsonLength value in its machine.config than my development machine. To solve this problem, add the following in your web.config.

5 January 2011

ThreadAbortException on Response.Redirect(), Response.End() and Response.Transfer()

If you have ever used a call to Response.Redirect("url"), Response.End() or Server.Transfer() within a try block, you will probably have noticed that these calls always throw a ThreadAbortException.
This is normal behaviour, but can mess up your program if the corresponding catch is executed unexpectedly.
To avoid this, catch the ThreadAbortException in a separate catch, or write a try/catch around the call.
For instance, if you have:

try
{
    Do something here;
    
    Response.Redirect("some url");

    Do some more work;
}

catch(Exception ex)
{
    Do something useful with the excepion here;
}

You can rewrite it like so:

30 December 2010

Crystal Reports: The maximum report processing jobs limit configured by your system administrator has been reached.

This exception is produced by Crystal Reports when the maximum number of concurrent report processes have been initiated. I have had troubles with this exception in my asp.net application, but at first it seemed almost to occur at random. Recycling the app pool solved the problem when it occurred. After a while (when the application was used more intensively) this became a real problem, as it began to occur more and more often.

My application does not use a ReportViewer, but rather generates a pdf file and sends it to the client as a download, using the following code:
ReportDocument repDoc = new ReportDocument();

repDoc.Load(filename);
// update the crystal report database connection
repDoc.SetCrystalReportDatabase("ConnectionString");

// send the resulting document to the user (as PDF).
Response.ClearContent();
Response.ClearHeaders();

repDoc.ExportToHttpResponse(formatType, Response, true, "Report");

repDoc.Dispose();

At first, I fixed this problem quite easily, by altering one value in the registry:

An error occurred while validating. HRESULT = '80004005'

I was having trouble with this error today, when I was trying to build a Deployment package. I also noticed that my deployment package showed no Detected References anymore.
The weird thing was, that my solution build properly and I could even run the software. It was just the deployment package that was producing errors.

As I found, the first thing to check is missing references. If they are not in use in the code, debugging the project will not produce any errors, building the deployment will. This also includes references to other projects, which are not included in the solution. If not pointing directly to the pre-built dll, these will produce problems.

For me though, this did not solve my problem, but I did find something else that caught my eye;

17 December 2010

Could not load file or assembly 'System.Data' or one of its dependencies

The full exception is:
Could not load file or assembly 'System.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format.

This problem seems to occur rather a lot and it seems there are different causes for it to occur. I have had this problem today and the information I found on the internet did not help at all. I have tried setting System.Data to not copy local, but then it just started with other libraries. I have also changed the .net version in my web.config, but that did not solve my problem either.
The only real difference that I could find between the old and new server was the fact that the new server was 64-bits. So looked into that and found an option in the advanced settings of an app pool in IIS7, named "Enable 32-Bit Applications".


After setting it to true, everything worked as before.