question

moondaddy-8531 avatar image
0 Votes"
moondaddy-8531 asked ·

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

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.

dotnet-aspnet-webapi
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered ·

Parameters? Parameters to what?

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YihuiSun-MSFT avatar image
0 Votes"
YihuiSun-MSFT answered ·

Hi @moondaddy-8531,
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


test.gif (989.1 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.