Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An item with the same key has already been added (ElasticSearch.NET 1.6.0 vs Newtonsoft.Json 7.0.1) #1462

Closed
SalvatoreMeschini opened this issue Jun 23, 2015 · 11 comments

Comments

@SalvatoreMeschini
Copy link

I updated both Nest packages and ElasticSearch server to latest versions, but now the code is broken.

This line (I simply recompiled the project after updating the packages via NuGet, I'm using Newtonsoft.Json 7.0.1):

ISearchResponse response = _client.Search(s => s.From(0).Size(limit).QueryString(searchString));

Now is leading to:

ERROR 2015-06-23 10:47:14,675 [11 ] .Mvc.Controllers.AbpHandleErrorAttribute - System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.ObjectModel.KeyedCollection2.AddKey(TKey key, TItem item)
at System.Collections.ObjectModel.KeyedCollection2.InsertItem(Int32 index, TItem item) at System.Collections.ObjectModel.Collection1.Add(T item)
at Newtonsoft.Json.Utilities.CollectionUtils.AddRange[T](IList1 initial, IEnumerable1 collection)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
at Nest.Resolvers.ElasticContractResolver.CreateContract(Type objectType) in c:\code\elasticsearch-net\src\Nest\Resolvers\ElasticContractResolver.cs:line 29
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
at Nest.Resolvers.SettingsContractResolver.ResolveContract(Type type) in c:\code\elasticsearch-net\src\Nest\Resolvers\SettingsContractResolver.cs:line 34
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe(Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, Formatting formatting, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings)
at Nest.NestSerializer.Serialize(Object data, SerializationFormatting formatting) in c:\code\elasticsearch-net\src\Nest\ExposedInternals\NestSerializer.cs:line 30
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandlerBase.PostData(Object data) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandlerBase.cs:line 66
at Elasticsearch.Net.Connection.RequestHandlers.RequestHandler.Request[T](TransportRequestState1 requestState, Object data) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\RequestHandlers\RequestHandler.cs:line 31 at Elasticsearch.Net.Connection.Transport.DoRequest[T](String method, String path, Object data, IRequestParameters requestParameters) in c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 343 at Elasticsearch.Net.ElasticsearchClient.DoRequest[T](String method, String path, Object data, IRequestParameters requestParameters) in c:\code\elasticsearch-net\src\Elasticsearch.Net\ElasticsearchClient.cs:line 65 at Elasticsearch.Net.ElasticsearchClient.Search[T](String index, String type, Object body, Func2 requestParameters) in c:\code\elasticsearch-net\src\Elasticsearch.Net\ElasticsearchClient.Generated.cs:line 34635
at Nest.RawDispatch.SearchDispatch[T](ElasticsearchPathInfo1 pathInfo, Object body) in c:\code\elasticsearch-net\src\Nest\RawDispatch.generated.cs:line 3624 at Nest.ElasticClient.Search[T,TResult](Func2 searchSelector) in c:\code\elasticsearch-net\src\Nest\ElasticClient-Search.cs:line 32
at Nest.ElasticClient.Search[T](Func`2 searchSelector) in c:\code\elasticsearch-net\src\Nest\ElasticClient-Search.cs:line 16
at KB.FTS.FTSSearchProvider.SearchETKD(String searchString, Int32 limit) in c:\Projects\KnowledgeBase\KB\KB.Core\FTS\FTSSearchProvider.cs:line 62

@SalvatoreMeschini
Copy link
Author

It looks like reverting to Newtonsoft.Json 6.0.8 fixes this issue, is it something that you can reproduce?

@SalvatoreMeschini SalvatoreMeschini changed the title An item with the same key has already been added (1.6.0) An item with the same key has already been added (ElasticSearch.NET 1.6.0 vs Newtonsoft.Json 7.0.1) Jun 23, 2015
@gmarz
Copy link
Contributor

gmarz commented Jun 23, 2015

Hey @SalvatoreMeschini NEST is currently on Newtonsoft.Json 6.0.1, and we don't support or run any tests against 7.x yet, so there could very well be some issues.

Out of curiosity, how did you get 7.0.1? Did your application already contain a reference to it, or did it somehow get installed when you installed NEST?

@wbsimms
Copy link
Contributor

wbsimms commented Jun 23, 2015

I got the same issue. I think it's the same as #1464

This fails too with the same deserialization issues.

var request = new SearchRequest() {...};
elasticClient.Serializer.Serialize(request);

@gmarz
Copy link
Contributor

gmarz commented Jun 23, 2015

Hey @wbsimms in what way is this related to #1464? Are you running into an exception here?

@wbsimms
Copy link
Contributor

wbsimms commented Jun 23, 2015

@gmarz I guess I should be more careful... I didn't see #1464 until I upgraded my Json.NET to 7.0.1. I was getting the same duplicate key exception thrown in both cases.

@gmarz
Copy link
Contributor

gmarz commented Jun 23, 2015

@wbsimms Okay so just to be clear, this isn't the same issue as #1464.

So you also upgaded to Json.NET 7.x? NEST doesn't currently support Json.NET 7.x...you will certainly run into this issue if you upgrade. I've just tested this myself and hit this exception as well.

We'll add support for the latest Json.NET in a future release, but for now you'll have to stay on 6.0.1.

@wbsimms
Copy link
Contributor

wbsimms commented Jun 23, 2015

Got it. Thanks!

Keep up the awesome work!

@gmarz
Copy link
Contributor

gmarz commented Jun 23, 2015

FYI working on upgrading to Json.NET 7 here: https://github.com/elastic/elasticsearch-net/tree/fix/update-jsonnet

@SalvatoreMeschini
Copy link
Author

@gmarz I updated all packages, including NewtonSoft JSON as ElasticSearch.NET+NEST require JSON >= 6.0.1 (but not < 7.0.1 :) ). By the way, issues are actually solved by downgrading to 6.0.8

To answer your question: I already had the JSON package because of another dependency.

Thanks!

@gmarz
Copy link
Contributor

gmarz commented Jun 24, 2015

Thanks for the additional info @SalvatoreMeschini. NEST will be using the latest Json.NET 7.0.1 and this issue will be fixed once #1465 is merged.

@gmarz
Copy link
Contributor

gmarz commented Jun 25, 2015

Closed via #1465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants