ASP.NET MVC: how is this possible? The parameter dictionary contains a null entry for the parameter 'x'

I was wondering if anyone has a clue to what is going on here and can point me in the right direction.

Ok..lets put the code in context.

I have ajax (jquery) methods:

$xmlHttp("/Api/GetWaitingMessages", { count: 20 }) .always(processResult); 

($ xmlHttp just wraps jQuery aside and some basic $ ajax options)

And in our health control I see things like this:

 Exception information: Exception type: System.ArgumentException Exception message: The parameters dictionary contains a null entry for parameter 'count' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult GetWaitingMessages(Int32)' in 'AjaxController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters 

Now the thing is, I put some traces and tried / caught (for testing) to make sure jQuery never calls GetWaitingMessages with empty or undefined "count", but with regard to healthmonitoring exceptions: GetWaitingMessages instance and passed the value null as a parameter. (from what I understand, MVC creates methods through reflection)

btw: an error occurs only, for example, from several thousand requests

Signature GetWaitingMessages:

 public virtual ActionResult GetWaitingMessages(int count) { .... } 

So, suppose mvc should not even hit the method, since there should be no signature match.

Does MVC have problems with high traffic websites (i.e. problems with multiple threads)?

The site mentioned above runs on a cluster of 5 web farm servers with network load balancing and IP affinity.

Each server receives about 1500 requests / sec at different times.

The site uses URL rewriting to display domains in the domain (i.e. test.com will just insert / check the URL), as it is a site with bright and multilingual white labels.

Additional site configuration information:

The controller that serves ajax requests is decorated

 [SessionState(SessionStateBehavior.Disabled)] 

HttpModules, where it is considered useless when it is deleted, since we need to run: runAllManagedModulesForAllRequests = "true" in MVC. I could set runAllManagedModulesForAllRequests = "false" and then try to figure out what to add, in what order, but it was easier just to delete what I know is not significant.

 <remove name="AnonymousIdentification" /> <remove name="Profile" /> <remove name="WindowsAuthentication" /> <remove name="UrlMappingsModule" /> <remove name="FileAuthorization" /> <remove name="RoleManager" /> <remove name="Session" /> <remove name="UrlAuthorization" /> <remove name="ScriptModule-4.0" /> <remove name="FormsAuthentication" /> 

All are activated and configured in the web.config file

 <pages validateRequest="false" enableEventValidation="false" enableViewStateMac="true" clientIDMode="Static"> and also: urlCompression staticContent caching outputCache 

EDIT: Just parsed my trace logs a bit more. When an error occurs, I see (Content-Length: 8) that matches (count = 20). However, I do not see any query parameters in the logs. I dumped the HttpInputStream into the logs and it is completely empty .. but, as I just mentioned, the logs also say that Content-Length = 8, so something is wrong here.

Can IIS (end up rewriting URLs) mix it somewhere along the way?

-

Any help would be greatly appreciated. I will tear my hair, trying to understand what might be wrong here.

Thanks Robert

+4
source share
3 answers

What type of request is causing your xmlHttp server problems ( GET , POST or something else)?

What is the definition of the GetWaitingMessages action GetWaitingMessages ?

It is possible that this may be a discrepancy with accepted verbs or argument names.

0
source

I have the feeling that this can be a problem when MVC cannot bind to your "count" parameter. By default, it expects the parameter to have the name 'id'.

You can try the following:

  • Modify the GetWaitingMessages action to define it using the 'id' parameter instead of 'count'
  • Create a custom model binding, as described in the accepted answer to the stack question, in the asp.net mvc routing id parameter

Hope this helps

EDIT: Just looked at your answer to another answer, stating that this is POST. In this case, binding may not be a problem.

0
source

Just for testing, try this to see if there are any problems.

 public virtual ActionResult GetWaitingMessages(FormCollection form) { var count=Int32.Parse(form["count"]); .... } 

Of course, it will throw if the count field is not set. If it always works correctly, the problem is with routing bindings or model bindings.

0
source

Source: https://habr.com/ru/post/1403428/


All Articles