kiota icon indicating copy to clipboard operation
kiota copied to clipboard

kiota crashes with NullReferenceException after update

Open bkoelman opened this issue 11 months ago • 17 comments

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

After update from v1.21.0 to v1.22.3, kiota crashes with the following error on Ubuntu:

  crit: Kiota.Builder.KiotaBuilder[0]
        error generating the client: One or more errors occurred. (Object reference not set to an instance of an object.) (Object reference not set to an instance of an object.)

Expected behavior

No crash.

How to reproduce

Run the following command:

dotnet kiota generate --language CSharp --class-name RestrictedControllersClient --namespace-name OpenApiKiotaEndToEndTests.RestrictedControllers.GeneratedCode --output ./GeneratedCode --backing-store --exclude-backward-compatible --clean-output --clear-cache --log-level Error --openapi ./swagger.g.json

Open API description file

Contents of swagger.g.json:

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/2212fc2c685446bebf86c905814a014f1a521cbd/test/OpenApiTests/RestrictedControllers/GeneratedSwagger/swagger.g.json

Kiota Version

1.22.3

Latest Kiota version known to work for scenario above?(Not required)

1.21.0

Known Workarounds

None

Configuration

Ubuntu 24.04.1 LTS (GitHub Actions runner)

Debug output

No response

Other information

No response

bkoelman avatar Jan 17 '25 03:01 bkoelman

Thanks for raising this @bkoelman

Unfourtunately, I'm not able to replicate the error using the openApi description and the arguments you provided. Are you able to set the --log-level to Debug and share a trace to help us undestand better? Is the failure consistent or does the success of the generation here flaky?

andrueastman avatar Jan 17 '25 08:01 andrueastman

I'm unable to reproduce it anymore. I've tried 7x with debug switch on Windows/Ubuntu/macOS, then 6x without debug switch.

It would be helpful to dump the stack trace on the console in such cases.

bkoelman avatar Jan 18 '25 17:01 bkoelman

Stack traces are enabled by default when built in debug. But we don't distribute debug builds. We disabled it in release builds because we had received feedback a while ago that it was confusing for users.

Let us know if you have any additional comments or questions.

baywet avatar Jan 20 '25 15:01 baywet

Well, I agree that printing a stack trace for functional errors that are supposed to happen sometimes (for example: OAS file not found or invalid) is annoying for users.

But this one belongs to the class of errors that are never supposed to happen, and typically indicate an internal bug. I think they should always be printed with rich info, possibly asking to create an issue. Exceptions like NullReferenceException, TypeLoadException, DivideByZeroException, InvalidCastException, IndexOutOfRangeException, OverflowException etc. May also include FormatException and ArgumentException, depending on whether they could happen under normal circumstances.

bkoelman avatar Jan 20 '25 20:01 bkoelman

There's a chance this could be related to https://github.com/microsoft/OpenAPI.NET/issues/1202. So, once we resolve https://github.com/microsoft/kiota/pull/5936 and pull in a version with NRT information this may be resolved.

andrueastman avatar Jan 22 '25 07:01 andrueastman

Got another crash today (v1.24.1), same message:

crit: Kiota.Builder.KiotaBuilder[0] error generating the client: One or more errors occurred. (Object reference not set to an instance of an object.)

Is this issue blocked on the assumption that another issue might fix it? We can never know for sure that it does because diagnostic information is unavailable, and the error appears randomly. Please add exception details as requested in https://github.com/microsoft/kiota/issues/6035#issuecomment-2603189954 so the cause can be diagnosed.

bkoelman avatar Mar 30 '25 22:03 bkoelman

Thank you for the additional information.

are you able to reproduce it with 1.24.3?

baywet avatar Mar 31 '25 14:03 baywet

Don't know yet, it only happens once in a while. That's why we need diagnostics, including the stack trace and command-line parameters used.

bkoelman avatar Mar 31 '25 15:03 bkoelman

What's expected from me?

bkoelman avatar Apr 14 '25 06:04 bkoelman

are you able to reproduce it with 1.25.1?

baywet avatar Apr 14 '25 16:04 baywet

Yes, it happens randomly. But that's irrelevant. Kita needs to provide error details first, before the cause can be determined. There's no point in me reporting each time it happens until then.

This issue shouldn't auto-close because there's no recent activity. The work that needs to happen is clear: change kiota to report details on errors that should never occur.

bkoelman avatar Apr 14 '25 17:04 bkoelman

where should this information be emitted? console logs? file logs? somewhere else?

We've already considered console and files, and the decision was that for release builds, we should NOT show the complete stack trace from an experience point. An important aspect is that behaviour changes between release and debug builds, so you could run a debug build instead to get the full stack trace.

baywet avatar Apr 14 '25 18:04 baywet

See https://github.com/microsoft/kiota/issues/6035#issuecomment-2603189954, that's something different, right?

For example, write to the console:

kiota failed with an unexpected internal error, please open an issue at (GitHub link). Exception: { exception.ToString() } kiota command-line arguments: { Environment.GetCommandLine() } kiota version: ... dotnet version: { typeof(object).Assembly... }

We run kiota inside MSBuild, for multiple projects in parallel, on a build server. Printing to the console is most convenient, because that appears in GitHub Actions logs. Building our own kiota from source instead of a NuGet reference is impractical to diagnose for what happens only sporadically. We can't push that pipeline to production. Getting diagnostics should be convenient, not require a separate pipeline which has source code changes to many projects. Alternatively, the behavior could kick in only when verbose logging is activated.

Especially because behavior differs between Debug and Release builds, we need to capture info from a release build. The problem seems timing-related, possibly a race condition, and may never happen in debug builds due to differences in compiler optimizations.

bkoelman avatar Apr 14 '25 19:04 bkoelman

Thank you for the additional information.

@sebastienlevert to provide input. Should we do something like special casing "Verbose" logging level to throw the exceptions (and provide the stack trace) so people using release builds can access and provide the needed information.

baywet avatar Apr 14 '25 19:04 baywet

Ran into this issue as well trying to generate the clickup schema:

https://developer.clickup.com/docs/open-api-spec

I managed to get past the issue with this change #6815 but this does not report the invalid references.

The operation that failed is "/v2/list/{list_id}/task". I suspect its due to refs between the post and get inside the same operation

Full output

kiota generate --language CSharp --exclude-backward-compatible --additional-data false --class-name ClickUpClient --namespace-name Company.ClickUp --openapi ./openapi.json --log-level debug --output ./Client
dbug: Kiota.Builder.KiotaBuilder[0]
      kiota version 1.29.0
info: Kiota.Builder.KiotaBuilder[0]
      loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
      step 1 - reading the stream - took 00:00:00.0110998
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/paths/~1v2~1oauth~1token/post - The operation #/paths/~1v2~1oauth~1token/post has a request body which is not an object type. This is not supported by Kiota and serialization will fail.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/ChatChannel/properties/description - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/ChatMessage/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/CommentCreateChatMessage/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/CommentCreateChatMessageResponse/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/CommentPatchChatMessage/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/CommentPatchChatMessageResponse/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/ReplyMessage/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/CommentCreateReplyMessageResponse/properties/content - The format RichText is not supported by Kiota for the type String and the string type will be used.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: #/paths/~1v2~1task~1{task_id}~1field~1{field_id}/post/requestBody/content/application~1json/examples/URL Custom Field/Dropdown Custom Field/Email Custom Field/Phone Custom Field/Date Custom Field/Short or Long Text Custom Field/Number Custom Field/Money Custom Field/~1v2~1task~1{task_id}/get/responses/200/content/application~1json/schema/properties/attachments/items/properties/date/type - Invalid schema type identifier: bigint
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: #/paths/~1v2~1task~1{task_id}~1field~1{field_id}/post/requestBody/content/application~1json/examples/URL Custom Field/Dropdown Custom Field/Email Custom Field/Phone Custom Field/Date Custom Field/Short or Long Text Custom Field/Number Custom Field/Money Custom Field/~1v2~1task~1{task_id}/get/responses/200/content/application~1json/schema/properties/attachments/items/properties/size/type - Invalid schema type identifier: bigint
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: #/paths/~1v2~1task~1{task_id}~1field~1{field_id}/post/requestBody/content/application~1json/examples/URL Custom Field/Dropdown Custom Field/Email Custom Field/Phone Custom Field/Date Custom Field/Short or Long Text Custom Field/Number Custom Field/Money Custom Field/~1v3~1workspaces~1{workspace_id}~1auditlogs/post/requestBody/content/application~1json/schema/properties/filter/allOf/properties/workspaceId/required - Cannot create simple list from this type of node.
dbug: Kiota.Builder.KiotaBuilder[0]
      step 2 - parsing the document - took 00:00:00.2029718
dbug: Kiota.Builder.KiotaBuilder[0]
      step 3 - updating generation configuration from kiota extension - took 00:00:00.0001615
dbug: Kiota.Builder.KiotaBuilder[0]
      step 4 - filtering API paths with patterns - took 00:00:00.0036471
info: Kiota.Builder.KiotaBuilder[0]
      Client root URL set to https://api.clickup.com/api
dbug: Kiota.Builder.KiotaBuilder[0]
      step 5 - checking whether the output should be updated - took 00:00:00.0582503
dbug: Kiota.Builder.KiotaBuilder[0]
      step 6 - create uri space - took 00:00:00.0085964
dbug: Kiota.Builder.KiotaBuilder[0]
      InitializeInheritanceIndex 00:00:00.0029936
crit: Kiota.Builder.KiotaBuilder[0]
      error generating the client: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.))))
      System.AggregateException: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.))))
       ---> System.AggregateException: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.)))
       ---> System.AggregateException: One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.))
       ---> System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
       ---> System.NullReferenceException: Object reference not set to an instance of an object.
         at Kiota.Builder.KiotaBuilder.CreateModelDeclarations(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeElement parentElement, String suffixForInlineSchema, IOpenApiResponse response, String typeNameForInlineSchema, Boolean isRequestBody, Boolean isViaDiscriminator) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1923
         at Kiota.Builder.KiotaBuilder.<>c__DisplayClass129_0.<CreatePropertiesForModelClass>b__0(KeyValuePair`2 x) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 2360
         at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
         at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
         at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
         at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
         at Kiota.Builder.KiotaBuilder.CreatePropertiesForModelClass(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, CodeNamespace ns, CodeClass model) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 2352
         at Kiota.Builder.KiotaBuilder.AddModelClass(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, String declarationName, CodeNamespace currentNamespace, OpenApiOperation currentOperation, CodeClass inheritsFrom) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 2114
         at Kiota.Builder.KiotaBuilder.AddModelDeclarationIfDoesntExist(OpenApiUrlTreeNode currentNode, OpenApiOperation currentOperation, IOpenApiSchema schema, String declarationName, CodeNamespace currentNamespace, CodeClass inheritsFrom) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1995
         at Kiota.Builder.KiotaBuilder.CreateModelDeclarationAndType(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeNamespace codeNamespace, String classNameSuffix, IOpenApiResponse response, String typeNameForInlineSchema, Boolean isRequestBody) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1693
         at Kiota.Builder.KiotaBuilder.CreateModelDeclarations(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeElement parentElement, String suffixForInlineSchema, IOpenApiResponse response, String typeNameForInlineSchema, Boolean isRequestBody, Boolean isViaDiscriminator) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1926
         at Kiota.Builder.KiotaBuilder.GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeClass parentClass, HttpMethod operationType) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1306
         at Kiota.Builder.KiotaBuilder.CreateOperationMethods(OpenApiUrlTreeNode currentNode, HttpMethod operationType, OpenApiOperation operation, CodeClass parentClass) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1391
         at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 755
         at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
         at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
         at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
         at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
         at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
         at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
         at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
         at System.Threading.Tasks.TaskReplicator.Replica.Execute()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
         at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
         at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
         at Kiota.Builder.KiotaBuilder.CreateSourceModel(OpenApiUrlTreeNode root) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 583
         at Kiota.Builder.KiotaBuilder.<>c__DisplayClass21_0.<<GenerateClientAsync>b__0>d.MoveNext() in /_/src/Kiota.Builder/KiotaBuilder.cs:line 287
      --- End of stack trace from previous location ---
         at Kiota.Builder.KiotaBuilder.GenerateConsumerAsync(Func`5 innerGenerationSteps, CancellationToken cancellationToken) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 346
         at Kiota.Builder.KiotaBuilder.GenerateConsumerAsync(Func`5 innerGenerationSteps, CancellationToken cancellationToken) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 366
         at Kiota.Builder.KiotaBuilder.GenerateClientAsync(CancellationToken cancellationToken) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 283
         at kiota.Handlers.KiotaGenerateCommandHandler.InvokeAsync(InvocationContext context) in /github.com/microsoft/kiota/src/kiota/Handlers/KiotaGenerateCommandHandler.cs:line 171
Unhandled exception: System.AggregateException: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.))))
 ---> System.AggregateException: One or more errors occurred. (One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.)))
 ---> System.AggregateException: One or more errors occurred. (One or more errors occurred. (Object reference not set to an instance of an object.))
 ---> System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Kiota.Builder.KiotaBuilder.CreateModelDeclarations(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeElement parentElement, String suffixForInlineSchema, IOpenApiResponse response, String typeNameForInlineSchema, Boolean isRequestBody, Boolean isViaDiscriminator) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1923
   at Kiota.Builder.KiotaBuilder.<>c__DisplayClass129_0.<CreatePropertiesForModelClass>b__0(KeyValuePair`2 x) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 2360
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at Kiota.Builder.KiotaBuilder.CreatePropertiesForModelClass(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, CodeNamespace ns, CodeClass model) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 2352
   at Kiota.Builder.KiotaBuilder.AddModelClass(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, String declarationName, CodeNamespace currentNamespace, OpenApiOperation currentOperation, CodeClass inheritsFrom) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 2114
   at Kiota.Builder.KiotaBuilder.AddModelDeclarationIfDoesntExist(OpenApiUrlTreeNode currentNode, OpenApiOperation currentOperation, IOpenApiSchema schema, String declarationName, CodeNamespace currentNamespace, CodeClass inheritsFrom) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1995
   at Kiota.Builder.KiotaBuilder.CreateModelDeclarationAndType(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeNamespace codeNamespace, String classNameSuffix, IOpenApiResponse response, String typeNameForInlineSchema, Boolean isRequestBody) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1693
   at Kiota.Builder.KiotaBuilder.CreateModelDeclarations(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeElement parentElement, String suffixForInlineSchema, IOpenApiResponse response, String typeNameForInlineSchema, Boolean isRequestBody, Boolean isViaDiscriminator) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1926
   at Kiota.Builder.KiotaBuilder.GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, IOpenApiSchema schema, OpenApiOperation operation, CodeClass parentClass, HttpMethod operationType) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1306
   at Kiota.Builder.KiotaBuilder.CreateOperationMethods(OpenApiUrlTreeNode currentNode, HttpMethod operationType, OpenApiOperation operation, CodeClass parentClass) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 1391
   at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 755
   at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
   at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
   at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
   at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
   at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
   at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
   at Kiota.Builder.KiotaBuilder.<>c__DisplayClass57_0.<CreateRequestBuilderClass>b__0(OpenApiUrlTreeNode childNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 771
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass43_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
   at Kiota.Builder.KiotaBuilder.CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUrlTreeNode currentNode, OpenApiUrlTreeNode rootNode) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 765
   at Kiota.Builder.KiotaBuilder.CreateSourceModel(OpenApiUrlTreeNode root) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 583
   at Kiota.Builder.KiotaBuilder.<>c__DisplayClass21_0.<<GenerateClientAsync>b__0>d.MoveNext() in /_/src/Kiota.Builder/KiotaBuilder.cs:line 287
--- End of stack trace from previous location ---
   at Kiota.Builder.KiotaBuilder.GenerateConsumerAsync(Func`5 innerGenerationSteps, CancellationToken cancellationToken) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 346
   at Kiota.Builder.KiotaBuilder.GenerateConsumerAsync(Func`5 innerGenerationSteps, CancellationToken cancellationToken) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 366
   at Kiota.Builder.KiotaBuilder.GenerateClientAsync(CancellationToken cancellationToken) in /_/src/Kiota.Builder/KiotaBuilder.cs:line 283
   at kiota.Handlers.KiotaGenerateCommandHandler.InvokeAsync(InvocationContext context) in /github.com/microsoft/kiota/src/kiota/Handlers/KiotaGenerateCommandHandler.cs:line 171
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Hosting.HostingExtensions.<>c__DisplayClass1_0.<<UseHost>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

Process finished with exit code 1.

Ciaran

cliedeman avatar Aug 06 '25 10:08 cliedeman

Thank you for the additional information.

This is most likely caused because those references are failing to resolve.

 "custom_fields": {
                            "$ref": "#/paths/~1v2~1task~1%7Btask_id%7D/get/responses/200/content/application~1json/schema/properties/custom_fields/items"
                          },
                          "list": {
                            "$ref": "#/paths/~1v2~1task~1%7Btask_id%7D/get/responses/200/content/application~1json/schema/properties/list"
                          },
                          "folder": {
                            "$ref": "#/paths/~1v2~1task~1%7Btask_id%7D/get/responses/200/content/application~1json/schema/properties/folder"
                          },
                          "space": {
                            "$ref": "#/paths/~1v2~1task~1%7Btask_id%7D/get/responses/200/content/application~1json/schema/properties/space"
                          },
                          "url": {
                            "type": "string"
                          }

So having an early exit condition like you've done is probably the safest approach, especially since with OpenAPI.net v2 the references are lazily resolved. It'd be worth investigating further, and if any issue is found with the reference resolution, creating an issue at https://github.com/microsoft/openapi.net

I have transitioned to a new team and won't be replying to this issue/pull request moving forward. Thank you for your understanding.

baywet avatar Aug 06 '25 15:08 baywet

Possibly related to #6854 in that random failures might be as a result of the use of a Parallel.ForEach and unresolved references

gavinbarron avatar Nov 17 '25 20:11 gavinbarron