Unable to use unpublished Epicor Functions in Rest calls

Good morning. Hoping someone has some insights on this issue we are experiencing. Per Epicor documentation:
An unpublished library, meaning a new library that contains functions that are still under development or a previously published library that has been demoted from production for an update, can still be called via REST by developers for testing purposes. To do this, use a special staging segment in the request URL:

https://[KineticServer]/[KineticInstance]/api/v2/efx/staging/[Company]/[Library]/[Function]/

This works as documented in 2022.1.13. It does not work in 2023.1 or 2023.2. Using Postman to test the unpublished function, I get an error 500. The logging on the server is System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter ‘length’)

I have tried a function with parms and a totally blank function with no parms and the error message is the same.

Full error here:

<Exception act="unknown" machine="xxxxxxx" pid="6676" tid="154"><![CDATA[System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService.ParseRestSharedNames(ReadOnlySpan`1 pathParts) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 158
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService.ParseRestV2Names(String[] pathParts) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 147
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService.GetNames(HttpRequest request, CallRouteType callType) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 101
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService..ctor(IHttpContextAccessor contextAccessor) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 39
   at ResolveService(ILEmitResolverBuilderRuntimeContext , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider sp, Type type, Type middleware)
   at lambda_method563(Closure , Object , HttpContext , IServiceProvider )
   at Ice.Hosting.AspNetCore.Middleware.CallHeaderMiddleware.InvokeAsync(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\CallHeaderMiddleware.cs:line 52
   at Ice.Hosting.AspNetCore.Middleware.OperationDisposerMiddleware.InvokeAsync(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\OperationDisposerMiddleware.cs:line 34
   at Epicor.RESTApi.Middleware.ApiKeyEnforcerMiddleware.Invoke(HttpContext context) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\ApiKeyEnforcerMiddleware.cs:line 79
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)]]></Exception>
System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService.ParseRestSharedNames(ReadOnlySpan`1 pathParts) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 158
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService.ParseRestV2Names(String[] pathParts) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 147
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService.GetNames(HttpRequest request, CallRouteType callType) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 101
   at Ice.Hosting.AspNetCore.Services.CurrentCallInformationService..ctor(IHttpContextAccessor contextAccessor) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Services\CurrentCallInformationService.cs:line 39
   at ResolveService(ILEmitResolverBuilderRuntimeContext , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider sp, Type type, Type middleware)
   at lambda_method563(Closure , Object , HttpContext , IServiceProvider )
   at Ice.Hosting.AspNetCore.Middleware.CallHeaderMiddleware.InvokeAsync(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\CallHeaderMiddleware.cs:line 52
   at Ice.Hosting.AspNetCore.Middleware.OperationDisposerMiddleware.InvokeAsync(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\OperationDisposerMiddleware.cs:line 34
   at Epicor.RESTApi.Middleware.ApiKeyEnforcerMiddleware.Invoke(HttpContext context) in C:\_releases\ICE\ICE4.2.400.4\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\ApiKeyEnforcerMiddleware.cs:line 79
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

Hi Carol,

Can you show us how you are passing the parameters into your function and show us how you have the parameters defined?

Hi Mark - thanks so much for responding. As a note - we are on-prem, single-company.

This is an issue whether the function has parms or not. The behavior and error is exactly the same on our “real” functions as it is on this dummy function.

Steps to replicate in the most simple way:
Create a new function library. Create a new function. The function widget can be blank. Just make sure that you add all companies as authorized under Security tab.
Publish the function.
Test function in Postman (see screen shot of results). You should get a successful return (200) and an empty result is returned
Unpublish the function.
Test function again in Postman with the addition of the “staging” folder in the url. You get an error 500. See screenshot.

Here’s my function:

Appreciate any input!
Carol

`... Length cannot be less than zero. (Parameter 'length')`

I’m going off the error message. Do you have code with a variable named ‘length’ or a business object that you’re calling that requires a parameter called ‘length’?

I hadn’t been able to get it to work either on recent versions. I gave up on the Staging path and have hit the acceptance stage of grief that I just need to publish it.

1 Like

I know right? - the error message does not make sense to me either. This dummy function has no parms and no related BO. Even in the production functions that we were working with that had parms, there is no parm called “length”.

I have the exact same functions in our 2022.1.13 Dev install and it works perfectly whether published or not.

I did just google the error message - System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter ‘length’) - and it appears to be a message from a C# parse. I’m wondering if it has anything to do with us being single-company, Not the first time we have run into an odd issue due to single company, single site, single currency… Just spit-balling here.

Carol

Joshua - thank you for the confirmation! Curious - are you testing with single company instance of Epicor?

I do have a Case open with Epicor on this so any common ground we can find might help. It did convert to a problem and the developers could not recreate the issue.

Carol

I have seen the same behavior. We discussed it here a bit back but I forgot to report it.

It’s broken.

We are multi-company

I did a ton of searching here before I actually posted my question - I must have missed it. Do you have a link to the discussion by chance? I still have an open case with Epicor.

Carol

Haven’t tried it in a while, seems to be working for me on 2023.2.2


image

I works fine for us as well. 2023.1.9

Thanks for testing! That helps. We are 2023.2.4. I wonder if it is something in how my app server is set up. I did a complete wipe of the app server before I applied 2023.2. Still spit-balling…

Carol

We had tried it at 2023.1.13 as well with no luck. Must be something more specific to us. Thanks for the input!
Carol

Also works on 2023.2.3, so yeah, I would guess it’s a setup issue on your end.

I was afraid of that - or maybe hopeful that it was something I could fix…

One last question - the logging of the error on the server shows this:

Is the act=“unknown” a clue perhaps?

Thanks.

Carol

what does the test function do? Send a screenshot of the overview tab? Maybe create a code only function that just does “Ice.Diagnostic.Log.WriteEntry(“MyTest”);” and nothing else

Got pulled away on other issues…
The original function (test/function-1) was a completely blank function.

I created another library (test2/function-1) as you suggested and the outcome was exactly the same - same server error log. Following are screen shots of the second function.





Thanks!

For those that might be interested - it appears that the issue is specific to a 2 character company ID. It’s been referred to development. Thanks to everyone who took the time to provide input!

2 Likes