[RESOLVED]ArgumentException – The parameters dictionary contains a null entry for parameter

We have a single page web app that uses MVC for the back end.  The client is all javascript/ajax/jquery.

We see the following error intermittently in our ASP.NET MVC app:

"The parameters dictionary contains a null entry for parameter ‘searchId’ of non-nullable type ‘System.Int32′ for method ‘StreamViewResult GetHiglightedPage(System.String, Int32, Int32, System.String, System.String, System.String,  Boolean)’

The weird thing is that the while the URL appears to be missing the required arguments, the UrlReferrer has the required arguments.   What might cause this intermittent issue?

Url: https://foo.com/zfp/Document/GetHiglightedPage/

UrlReferrer: https://foo.com/zfp/Document/GetHiglightedPage/?docKey=MV8yNTQ1XzQyMTYzMDJfMV8xXzM=&searchId=1......

If your request doesn’t always include the searchId parameter or it is not allowed to be null, you may want to consider setting a default value for that particular action :

// This would set your default value for your searchId parameter to -1 (if it wasn't present)
public ActionResult GetHiglightedPage(int searchId = -1, ....)
{
     // Code omitted for brevity
}

You could also likely just allow your searchId property to accept nulls by changing it to a nullable integer (int?). Do you have any examples of what your existing Controller Action looks like or where it is being called from?

Intermittent errors can be hard troubleshoot.  I usually start looking at logs and logging requests.  Sometimes an error can be misleading because the actual error is masked in some way. 

Secondly, unless you’re using the UrlReferrer on the server, it has nothing to do with the current request.  Are you reading the current URL client side and using it to create the next request?

We have a server side global error handler that includes the Request.Url and Request.UrlReferrer in the log entry.  It’s strange that the arguments are all present on the UrlReferrer but missing on the URL.  Its very intermittent.

The requests are all AJAX requests on the client.

Hi skmcfadden,

skmcfadden

It’s strange that the arguments are all present on the UrlReferrer but missing on the URL.  Its very intermittent.

I suggest that you could use post type to send the request.

On the other hand, we’d better to handle the possible scenarios instead of let it throw the error. As
Rion said that set the default value and check that value.

Best Regards

Starain

Leave a Reply