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

The JSON property 'item' is defined multiple times on type 'System.Collections.ObjectModel.Collection #755

Closed
aadhi7 opened this issue May 4, 2017 · 18 comments

Comments

@aadhi7
Copy link

aadhi7 commented May 4, 2017

Target: .Net Framework 4.5.2

  1. Create a C# class file as below
    namespace ClassLibrary1
    {
    public class StringCollection : System.Collections.ObjectModel.KeyedCollection<string, string>
    {
    protected override string GetKeyForItem(string item)
    {
    //return some value
    return item;
    }
    }
    }

  2. Compile and create the dll

  3. Run the NSwagStudio and load .Net Assembly (in Windows Machine) will get the exception as follows

The JSON property 'item' is defined multiple times on type 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.

Stack Trace

Server stack trace:

at NJsonSchema.Generation.JsonSchemaGenerator.d__24.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 491
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__16.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 297
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__19.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 344
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__16.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 302
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__19.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 344
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__16.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 302
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__151.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 268 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NJsonSchema.Generation.JsonSchemaGenerator.<GenerateAsync>d__101.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 139
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NJsonSchema.Generation.JsonSchemaGenerator.d__9`1.MoveNext() in C:\projects\njsonschema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs:line 100
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NSwag.SwaggerGeneration.AssemblyTypeToSwaggerGenerator.NetAssemblyLoader.d__1.MoveNext() in C:\projects\nswag\src\NSwag.AssemblyLoaderCore\SwaggerGenerators\AssemblyTypeToSwaggerGenerator.cs:line 119
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NSwag.SwaggerGeneration.AssemblyTypeToSwaggerGenerator.NetAssemblyLoader.FromAssemblyType(String[] classNames, String settingsData) in C:\projects\nswag\src\NSwag.AssemblyLoaderCore\SwaggerGenerators\AssemblyTypeToSwaggerGenerator.cs:line 91
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at NSwag.SwaggerGeneration.AssemblyTypeToSwaggerGenerator.NetAssemblyLoader.FromAssemblyType(String[] classNames, String settingsData)
at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.SwaggerGeneration.AssemblyTypeToSwaggerGenerator.<GenerateAsync>d__2.MoveNext() in C:\projects\nswag\src\NSwag.AssemblyLoaderCore\SwaggerGenerators\AssemblyTypeToSwaggerGenerator.cs:line 68 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.Commands.AssemblyTypeToSwaggerCommandBase.<<RunAsync>b__34_0>d.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\AssemblyTypeToSwaggerCommandBase.cs:line 103 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.Commands.AssemblyTypeToSwaggerCommandBase.<RunAsync>d__34.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\AssemblyTypeToSwaggerCommandBase.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.Commands.AssemblyTypeToSwaggerCommandBase.<RunAsync>d__33.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\AssemblyTypeToSwaggerCommandBase.cs:line 93 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwagStudio.ViewModels.SwaggerGenerators.AssemblyTypeToSwaggerGeneratorViewModel.<<GenerateSwaggerAsync>b__34_1>d.MoveNext() in C:\projects\nswag\src\NSwagStudio\ViewModels\SwaggerGenerators\AssemblyTypeToSwaggerGeneratorViewModel.cs:line 150 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwagStudio.ViewModels.SwaggerGenerators.AssemblyTypeToSwaggerGeneratorViewModel.<<GenerateSwaggerAsync>b__34_0>d.MoveNext() in C:\projects\nswag\src\NSwagStudio\ViewModels\SwaggerGenerators\AssemblyTypeToSwaggerGeneratorViewModel.cs:line 148 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MyToolkit.Mvvm.ViewModelBase.<>c__DisplayClass15_01.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MyToolkit.Mvvm.ViewModelBase.d__12`1.MoveNext()

@bergziege
Copy link

Hi, is there a known workaround for this problem? I am getting the exact same thing on type 'System.IdentityModel.Tokens.SecurityTokenHandlerCollection'.

@RicoSuter
Copy link
Owner

I think this will be fixed with RicoSuter/NJsonSchema#321

@RicoSuter
Copy link
Owner

Can you try with nswag v11 ci artifacts?

@AHorak
Copy link

AHorak commented Dec 22, 2017

System.InvalidOperationException: The JSON property 'Item' is defined multiple times on type 'System.Web.HttpApplicationStateBase'.

Same Problem with NSwag 11.12.16.0 (NSwagStudio)
NJSonSchema 9.10.19.0

Runtime: WinX64
Server stack trace:
bei NJsonSchema.Generation.JsonSchemaGenerator.d__30.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel”st wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei NJsonSchema.Generation.JsonSchemaGenerator.d__22.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel”st wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei NJsonSchema.Generation.JsonSchemaGenerator.d__151.MoveNext() --- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel”st wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei NJsonSchema.Generation.JsonSchemaGenerator.<GenerateAsync>d__101.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel”st wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei NJsonSchema.Generation.JsonSchemaGenerator.d__91.MoveNext() --- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel”st wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei NJsonSchema.Generation.JsonSchemaGenerator.<GenerateWithReferenceAndNullability>d__131.MoveNext()
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel”st wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
...

@dotnetrules
Copy link

Hi all, having the same issue whenever our controllers return a JArray...
Error: The JSON property 'Item' is defined multiple times on type 'Newtonsoft.Json.Linq.JArray'.

@johlandabee
Copy link

I've got an similar issue with NSwag Studio v11.17.0.0, trying to generate from a .Net 4.6.1(ASP 4) assembly.

The JSON property 'Item' is defined multiple times on type 'System.Web.HttpApplicationStateBase'.

@RSuter The ticket is quite old. Any news on this?

@RicoSuter
Copy link
Owner

Somewhere in the public api you expose HttpApplicationStateBase. Either you hide that (make internal), configure it away (eg with SwaggerResponse attribute) or map it to any with a type mapper

@johlandabee
Copy link

Alright, thanks for the hint. I'll try it tomorrow.

@stevehurcombe
Copy link

I'm getting the same error as @johlandabee and I can't find any reference to HttpApplicationStateBase.

Is there likely to be a fix?

@RicoSuter
Copy link
Owner

Maybe a JArray? If the problem is JArray we should fix that (but its probably already fixed)

@stevehurcombe
Copy link

stevehurcombe commented Jun 1, 2018

It's a WebAPI controller, there will be collections that might well end up as a JArray once the serializer has finished with it. Trouble is it could be anywhere in the code and there could be multiple occurrences.

@statler
Copy link

statler commented Jun 14, 2018

Same issue in webAPI

    [HttpPut("UpdateControlLinePointSet")]
    public async Task<IActionResult> UpdateControlLinePointSet([FromBody] JArray pointSet)
    {
         ...
     } 

Causes "The JSON property 'Item' is defined multiple times on type 'Newtonsoft.Json.Linq.JArray'"

A fix or workaround would be greatly appreciated :)

@RicoSuter
Copy link
Owner

Just tested this and it's indeed because JArray is wrongly processed.

@abhishekgoenka
Copy link

I am still getting the same error
image

I am on version 11.18.7.0

@RicoSuter
Copy link
Owner

Can you create a new issue and provide a repro project?

@abhishekgoenka
Copy link

Moved to AutoRest. Works better then NSwag.

@abdelgrib
Copy link

If you have in your models (request or response) properties of type which inherits/implements types like System.ComponentModel (or other types) this will throw an error

"The JSON property 'item' is defined multiple times on type"...

Try to ignore this property using [JsonIgnore] attribute of Newtonsoft.Json

In my case i had a getter of type DataTable

@chrisjpryor
Copy link

If you have in your models (request or response) properties of type which inherits/implements types like System.ComponentModel (or other types) this will throw an error

"The JSON property 'item' is defined multiple times on type"...

Try to ignore this property using [JsonIgnore] attribute of Newtonsoft.Json

In my case i had a getter of type DataTable

@RicoSuter I am experiencing this exact same issue with a Datatable property on one of my DTO's. Unfortunately I cannot just use [JsonIgnore] because I need to reference this property.

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