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

NotSupportedException thrown by SA1602EnumerationItemsMustBeDocumented #1359

Closed
oatkins opened this issue Sep 1, 2015 · 5 comments
Closed
Assignees
Milestone

Comments

@oatkins
Copy link
Contributor

oatkins commented Sep 1, 2015

I suspect that this is because of trying to use an ImmutableDictionary<> in a type that's used with the JSON serializer. I'm sure it will try to call IDictionary<T>.Add() when populating a dictionary property if it isn't null initially.

My brand new settings file uses the variables property.

Severity    Code    Description Project File    Line    Detail Description
Message AD0001  The User Diagnostic Analyzer 'StyleCop.Analyzers.DocumentationRules.SA1602EnumerationItemsMustBeDocumented' threw an exception of type 'System.NotSupportedException' with message 'Specified method is not supported.'.    JW.Admin.ServiceInterface       1   Analyzer 'StyleCop.Analyzers.DocumentationRules.SA1602EnumerationItemsMustBeDocumented' threw the following exception:
'System.NotSupportedException: Specified method is not supported.
   at System.Collections.Immutable.ImmutableDictionary`2.System.Collections.IDictionary.set_Item(Object key, Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at StyleCop.Analyzers.SettingsHelper.GetStyleCopSettings(ImmutableArray`1 additionalFiles)
   at StyleCop.Analyzers.SettingsHelper.GetStyleCopSettings(AnalyzerOptions options)
   at StyleCop.Analyzers.DocumentationRules.SA1602EnumerationItemsMustBeDocumented.Analyzer..ctor(AnalyzerOptions options)
   at StyleCop.Analyzers.DocumentationRules.SA1602EnumerationItemsMustBeDocumented.HandleCompilationStart(CompilationStartAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass25_0.<ExecuteCompilationStartActions>b__0()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze)'.
@sharwell
Copy link
Member

sharwell commented Sep 1, 2015

Interesting. It works here in the tests. Wonder what's different.

@oatkins
Copy link
Contributor Author

oatkins commented Sep 1, 2015

I just found that out too! Could something else be loading a different version of the Newtonsoft serializer into the AppDomain?

@pdelvo
Copy link
Member

pdelvo commented Sep 1, 2015

visual studio could have loaded json.net

@oatkins
Copy link
Contributor Author

oatkins commented Sep 2, 2015

Even if I downgrade json.net all the way back to a version from 2013 I still can't get the test to fail. Maybe it could be related to the version of System.Collections.Immutable used at runtime.

Anyway, the workaround is easy: don't use variables.

@sharwell
Copy link
Member

I found the underlying problem (see link ⬆️). Grabbing this to implement a workaround.

@sharwell sharwell modified the milestones: 1.0.0 Beta 13, 1.0.0 RC 1 Sep 18, 2015
@sharwell sharwell self-assigned this Sep 18, 2015
sharwell added a commit to sharwell/StyleCopAnalyzers that referenced this issue Sep 19, 2015
This works around JamesNK/Newtonsoft.Json#652 by avoiding the direct use
of immutable types in the serialization process. The result remains
efficient because the builder class caches the last returned immutable
instance, and will continue returning the same instance as long as no
changes are made to the builder.

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

No branches or pull requests

3 participants