Showing posts with label Asp.Net Exceptions. Show all posts
Showing posts with label Asp.Net Exceptions. Show all posts

Friday, June 29, 2012

System.ArgumentException: Invalid postback or callback argument


This error occurs when the mapping between the controls in the .aspx page and the corresponding events in the code-behind file is changed.

For example if you try to fire the Button1_Click event while clicking Button2 then this error will occur.

Invalid postback or callback argument.  Event validation is enabled using &ltlpages enableEventValidation="true"/> in configuration or &ltl%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

This is done explicitly by Asp.net to make sure that there are no breach is security, to prevent some hacking script to trigger the code-behind events.

Solution
1. If your application is not a very critical or if it a restricted intranet application then you can set the
enableEventValidation attribute in the @Page directive to false, this will prevent Asp.net from checking the control-event mappings

EnableEventValidation="false"

2. If your application is critical then you can use the ClientScriptManager.RegisterForEventValidation method to register the postback.

Monday, June 4, 2012

ORA-00911: invalid character\n in Asp.Net


I got the error ORA-00911: invalid character\n while trying to execute the following Oracle query from Asp.Net

string strQuery = "SELECT * FROM PROJECTS;";

Tried to figure out what the \n meant, but surprisingly the reason for the error had nothing to do with the \n

Cause:
The additional ";" at the end of the SELECT query

Resolution:
Remove the ";" and the query will start working
string strQuery = "SELECT * FROM PROJECTS";
 
Additional Information:
The query will still work even with the ";" in Oracle editors like Oracle SQL Developer, but will throw the exception ORA-00911: invalid character\n in .Net, this made it even difficult to debug the issue, since the same query works fine in Oracle, but throws an exception when called from .Net, finally removed the ";" and resolved the issue.

The ";" is required only while running the query inside a code block like BEGIN.... END;

string strQuery = "BEGIN UPDATE PROJECTS SET Name = 'Dashboard Project' WHERE PROJECT_ID = 100; END;";

The above query works fine without any issues sicne it is placed in a code block, but a single SQL statement will throw the exception ORA-00911: invalid character\n, when a ";" is placed at the end.



Monday, April 23, 2012

Operation is not valid due to the current state of the object


When the number of controls / fields in an Asp.Net 3.0 form exceeds 1000, the following error message will be thrown.

Operation is not valid due to the current state of the object.  
  at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()    
  at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)    
  at System.Web.HttpRequest.FillInFormCollection()



This is because the Microsoft security update MS11-100 limits the maximum number of form keys, files, and JSON members to 1000 in an HTTP request.

When there is a HTTP request requesting for a page which has more than 1000 fields/controls, this exception in thrown.

The good thing is, that there is a fix for the issue, which can be made by altering the settings in the web.config file. Adding the following line to the <appSettings> section will increase the limit from 1000 to 2000, you can configure the <appSettings> section based on your needs.

<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2001" />
appSettings>

For more information please visit the following post in Microsoft’s support center.




http://support.microsoft.com/kb/2661403