ASP.NET Web API Error: "Attempted to divide by zero" when parameters exceed 29

moondaddy 911 Reputation points
2021-02-06T23:23:18.713+00:00

Using VS 2019 c# 4.8 I have an API containing a lot of parameters as a test. It seems if I exceed 29 parameters I will get this error:

Exception Details: System.DivideByZeroException: Attempted to divide by zero.
Source Error:
Line 18: protected void Application_Start(object sender, EventArgs e)
Line 19: {
Line 20: GlobalConfiguration.Configure(WebApiConfig.Register);
Line 21: FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
Line 22: RouteConfig.RegisterRoutes(RouteTable.Routes);

If I remove the last parameter it builds and runs. Here are the last 2 parameters in the list:

.../{aParamFiller24}/{aParamFiller25}")]

this gets the exception. If I remove the last one so it looks like this:

.../{aParamFiller24}")]

It runs OK. Note: even though the last parameter is "{aParamFiller25}", I have 5 non-numbered parameters at the beginning of the list.

Is this a bug in .net?
Is this by design?
Is there a work-around for this?

Thank you.

ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
343 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Duane Arnold 3,211 Reputation points
    2021-02-07T01:15:20.19+00:00

    Parameters? Parameters to what?

    0 comments No comments

  2. Yihui Sun-MSFT 801 Reputation points
    2021-02-08T07:50:30.077+00:00

    Hi @moondaddy ,
    How do you configure Web API routing?
    If it is convenient, can you provide the routing configuration of Web API?
    I used Attribute Routing to test and did not reproduce your error.

     public class ValuesController : ApiController  
        {        [Route("test/{test1}/{test2}/{test3}/{test4}/{test5}/{test6}/{test7}/{test8}/{test9}/{test10}/{test11}/{test12}/{test13}/{test14}/{test15}/{test16}/{test17}/{test18}/{test19}/{test20}/{test21}/{test22}/{test23}/{test24}/{test25}/{test26}/{test27}/{test28}/{test29}/{test30}")]  
            public string test(string test1, string test2, string test3, string test4, string test5, string test6, string test7, string test8, string test9, string test10, string test11, string test12, string test13, string test14, string test15, string test16, string test17, string test18, string test19 , string test20, string test21, string test23, string test24, string test25, string test26, string test27, string test28, string test29, string test30)  
            {  
                return "value";  
            }  
        }  
    

    65282-test.gif


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Best Regards,
    YihuiSun

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.