Dynamics NAV Web Service Error: “Index was outside the bounds of the array.”

Dynamics NAV Web Service Error: “Index was outside the bounds of the array.”

Are you having trouble with web services and seeing a message like: “Index was outside the bounds of the array” in the event viewer?

Are you using an Extension codeunit (I’ve also heard them called Helper Codeunits) with a published page in web services?

If so, there’s a chance that your extension codeunit contains a function where the first parameter isn’t the record type of the published page.

I ran into this when I added a function to the wrong codeunit (accidentally) and it took me some time to figure out why web services stopped working.

Extension codeunits are described on the MSDN site.

Web service setup looks like this: 

Web Services setup

Figure 1 – Web services setup

Since I’ve published the Customer Card page, I’ll add a function to codeunit 50,000 that uses a customer record as a parameter:

Adding codeunit 50000: Customer Helper

Figure 2 – Adding codeunit 50,000: Customer Helper

Looking at the Web Services Description Language (WSDL) of the published page, you’ll notice that the function in the codeunit is included in the Customer page description.

View of the WSDL of the published page showing the codeunit is included

Figure 3 – View of the WSDL of the published page showing the codeunit is included

Now add a function with a parameter that’s not a record type variable to the Extension codeunit or add a parameter before the Customer record parameter, save your changes and try to view the WDSL.

Adding another function to the codeunit

Figure 4 – Adding another function to the codeunit

This will result in an error. Depending on your version of NAV, the errors could be different, and in NAV 2015, it might crash your service tier. Since this is so catastrophic, it’s unlikely it would make it past testing or QA, but could lead to lost dev time trying to track it down.

Hope this saves someone some time!

Event Log

Server instance: DynamicsNAV80

Type: System.IndexOutOfRangeException

Message: Index was outside the bounds of the array.

StackTrace:

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceCodeunitAdapterBase.GetObjectId(ParameterInfo parameter)

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormWsdlAdapterCodeunit.TableType(ParameterInfo param)

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormWsdlAdapterCodeunit.VisitMethods(IEnumerable`1 methods)

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormWsdlAdapter.WriteMessageElements(XsdBuilder xsd)

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormWsdlAdapter.WriteWsdl(XmlTextWriter output, Uri url)

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceBroker.MetadataFor(WebServiceUrlInfo relivantURLPart, Uri orginal, TextWriter output)

  at Microsoft.Dynamics.Nav.Service.WebServices.ServiceBroker.Invoke(Boolean isSoapMessage, Uri url, XmlReader input, TextWriter output, NavUserAuthentication navUserAuth)

Source: Microsoft.Dynamics.Nav.Service.WebServices

HResult: -2146233080

If you have any further questions about this or any other development issues, please contact one of our development experts at ArcherPoint. If you liked this blog, check out our collection of other Development Blogs.

Trending Posts

Stay Informed

Choose Your Preferences
First Name
*required
Last Name
*required
Email
*required
Subscription Options
Your Privacy is Guaranteed