Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

API Call Error ""An item with the same key has already been added."

Posted on by 11
Recently we have /refreshed/ data on our Development Environment/Database. After data refresh, ALL API calls fail with following Error:
 
Type: System.ArgumentException
Message: An item with the same key has already been added.
StackTrace:
     at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
     at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
     at System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem item)
     at System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, TItem item)
     at Microsoft.Dynamics.Nav.Service.OData.Modeling.NavEdmModel.AddComplexType(String name, IMetaComplexType metadata)
     at Microsoft.Dynamics.Nav.Service.OData.V4.MetaComplexTypesExtensions.AddToModel(IEnumerable`1 complexTypes, INavEdmModel model)
     at Microsoft.Dynamics.Nav.Service.Api.ApiBetaModelBuilder.Build(IEnumerable`1 complexTypes, IEnumerable`1 services)
     at Microsoft.Dynamics.Nav.Service.OData.NavService.Execute[TResult](HttpRequestMessage request, NavSession session, Func`2 operation, String companyName, Boolean isCompanyContext)
     at Microsoft.Dynamics.Nav.Service.OData.NavService.Execute[TResult](Func`2 operation)
     at Microsoft.Dynamics.Nav.Service.Api.CachedModelBuilder.Build(INavServiceEnvironment serviceEnvironment, String routeName)
     at lambda_method(Closure , ServiceProvider )
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
     at Microsoft.AspNet.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer, Boolean template)
     at Microsoft.AspNet.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)
     at Microsoft.Dynamics.Nav.Service.OData.V4.PathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)
     at Microsoft.Dynamics.Nav.Service.OData.V4.RouteConstraint.Match(HttpRequestMessage request, IHttpRoute route, String parameterName, IDictionary`2 values, HttpRouteDirection routeDirection)
     at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
     at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
     at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)
     at System.Web.Http.HttpRouteCollection.GetRouteData(HttpRequestMessage request)
     at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()
Source: mscorlib
HResult: -2147024809
StackTrace:
     at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
     at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
     at System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem item)
     at System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, TItem item)
     at Microsoft.Dynamics.Nav.Service.OData.Modeling.NavEdmModel.AddComplexType(String name, IMetaComplexType metadata)
     at Microsoft.Dynamics.Nav.Service.OData.V4.MetaComplexTypesExtensions.AddToModel(IEnumerable`1 complexTypes, INavEdmModel model)
     at Microsoft.Dynamics.Nav.Service.Api.ApiBetaModelBuilder.Build(IEnumerable`1 complexTypes, IEnumerable`1 services)
     at Microsoft.Dynamics.Nav.Service.OData.NavService.Execute[TResult](HttpRequestMessage request, NavSession session, Func`2 operation, String companyName, Boolean isCompanyContext)
     at Microsoft.Dynamics.Nav.Service.OData.NavService.Execute[TResult](Func`2 operation)
     at Microsoft.Dynamics.Nav.Service.Api.CachedModelBuilder.Build(INavServiceEnvironment serviceEnvironment, String routeName)
     at lambda_method(Closure , ServiceProvider )
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
     at Microsoft.AspNet.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer, Boolean template)
     at Microsoft.AspNet.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)
     at Microsoft.Dynamics.Nav.Service.OData.V4.PathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)
     at Microsoft.Dynamics.Nav.Service.OData.V4.RouteConstraint.Match(HttpRequestMessage request, IHttpRoute route, String parameterName, IDictionary`2 values, HttpRouteDirection routeDirection)
     at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
     at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
     at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)
     at System.Web.Http.HttpRouteCollection.GetRouteData(HttpRequestMessage request)
     at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()
 
Appreciate any help/insight with this issue. 
Categories:
  • Verified answer
    Community member Profile Picture
    Community member 11 on at
    API Call Error ""An item with the same key has already been added."
    ZHU,
     
    Found the culprit:
     
     
    Truncated this table and problem solved. But don't ask me how I found it........................... pfffffff
     
    RO
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    API Call Error ""An item with the same key has already been added."

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans