skip to Main Content

I understand what this error is stating and the typical cause, but in this case, I’m not sure why it is being thrown.

Here’s the full error message:

System.ArgumentException: The parameters dictionary contains a null
entry for parameter ‘Id’ of non-nullable type ‘System.Int32’ for
method ‘System.Threading.Tasks.Task`1[System.String] AppUninstalled(Int32)’ in
‘Storefront.Controllers.ShopifyWebhooksController’. An optional
parameter must be a reference type, a nullable type, or be declared as
an optional parameter. Parameter name: parameters

The url being called against my app is: /storefront/wh/AppUninstalled/88564. So it is passing the Id as int.

Here’s the route definition:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Storefront_default",
        "Storefront/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}

Here’s the action signature that is being called: public async Task<string> AppUninstalled(int id)

Now when I test this locally or against my staging server using Postman, I don’t get this error. But when Shopify calls it, I do get the error. And I can verify via the Elmah error generated, that the url that was called is just as I posted above, with the trailing Id value.

UPDATE: 1

I also tried having shopify call the url with the id explicitly named: /storefront/wh/AppUninstalled?id=88564 but get the same error.

Could it be something in the encoding that MVC can’t convert the id to an int?

UPDATE 2

This works, but it doesn’t explain why the above did not work.

Changing the action method in MVC to: public async Task<string> AppUninstalled(string strId)

Changing the Shopify call back url to: /storefront/wh/AppUninstalled?strId=88564

2

Answers


  1. I suspect that since id is declared optional in MapRoute you should declare your action like this:

    public async Task<string> AppUninstalled(int? id)
    

    And check if id has a value and take action if not.

    Login or Signup to reply.
  2. Could you try RouteParameter.Optional and MapHttpRoute instead of UrlParameter.Optional and MapRoute

       routes.MapHttpRoute( // <-- this
                    name: "Storefront_default",
                    routeTemplate: "Storefront/{controller}/{action}/{id}",
                    defaults: new {action ="Index", id = RouteParameter.Optional // <-- this 
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search