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

"System.InvalidOperationException: Unhandled BinaryData example value type" when value is an array of objects #5171

Open
brrusino opened this issue Nov 20, 2024 · 3 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Mgmt This issue is related to a management-plane library. v3 Version 3 of AutoRest C# generator.

Comments

@brrusino
Copy link
Member

Seeing the following stack trace:

Unhandled exception. System.InvalidOperationException: Unhandled BinaryData example value type
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendFrameworkTypeValue(CodeWriter writer, CSharpType type, InputExampleValue exampleValue, Boolean includeCollectionInitialization) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 117
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendExampleValue(CodeWriter writer, InputExampleValue exampleValue, CSharpType type, Boolean includeCollectionInitialization) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 46
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendDictionaryValue(CodeWriter writer, CSharpType type, InputExampleObjectValue exampleValue, Boolean includeInitialization) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 209
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendFrameworkTypeValue(CodeWriter writer, CSharpType type, InputExampleValue exampleValue, Boolean includeCollectionInitialization) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 106
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendExampleValue(CodeWriter writer, InputExampleValue exampleValue, CSharpType type, Boolean includeCollectionInitialization) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 46
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendObjectTypeValue(CodeWriter writer, ObjectType objectType, IReadOnlyDictionary`2 valueDict) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 483
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendTypeProviderValue(CodeWriter writer, CSharpType type, InputExampleValue exampleValue) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 404
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendExampleValue(CodeWriter writer, InputExampleValue exampleValue, CSharpType type, Boolean includeCollectionInitialization) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 46
   at AutoRest.CSharp.MgmtTest.Extensions.CodeWriterExtensions.AppendExampleParameterValue(CodeWriter writer, ExampleParameterValue exampleParameterValue) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Extensions\CodeWriterExtensions.cs:line 95
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteOperationInvocationParameters(Sample sample) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 480
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteSampleLroOperation(CodeWriterDeclaration instanceVar, Sample sample) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 357
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteSampleOperation(CodeWriterVariableDeclaration collectionResult, Sample sample) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 342
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteSampleOperationForResource(CodeWriterVariableDeclaration clientVar, Resource resource, Sample sample) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 219
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteSampleSteps(Sample sample) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 94
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteSample(Sample sample) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 75
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.WriteImplementation() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 46
   at AutoRest.CSharp.MgmtTest.Generation.Samples.MgmtSampleWriter.Write() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\Generation\Samples\MgmtSampleWriter.cs:line 37
   at AutoRest.CSharp.AutoRest.Plugins.MgmtTestTarget.WriteSamples(GeneratedCodeWorkspace project, MgmtTestOutputLibrary library) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\AutoRest\MgmtTestTarget.cs:line 74
   at AutoRest.CSharp.AutoRest.Plugins.MgmtTestTarget.ExecuteAsync(GeneratedCodeWorkspace project, InputNamespace inputNamespace, SourceInputModel sourceInputModel) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\MgmtTest\AutoRest\MgmtTestTarget.cs:line 45
   at AutoRest.CSharp.AutoRest.Plugins.CSharpGen.ExecuteAsync(InputNamespace rootNamespace) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Plugins\CSharpGen.cs:line 92
   at AutoRest.CSharp.AutoRest.Communication.StandaloneGeneratorRunner.RunAsync(CommandLineOptions options) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Communication\StandaloneGeneratorRunner.cs:line 62
   at AutoRest.CSharp.Program.Run(CommandLineOptions options) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 47
   at AutoRest.CSharp.Program.<>c.<<Main>b__2_0>d.MoveNext() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 29
--- End of stack trace from previous location ---
   at AutoRest.CSharp.Program.Main(String[] args) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 26
   at AutoRest.CSharp.Program.<Main>(String[] args)

This seems to be when trying to process an example with object[] value when Record is the Proxy Resource's property model (legacy resource for our RP).

PR link to model definition in TypeSpec: https://github.com/Azure/azure-rest-api-specs/blob/792b94bd3d1e499882a4294fd345b2965684eed8/specification/chaos/Chaos.Management/Target.tsp#L20C1-L20C71

PR link to example property that seems to be causing failure: https://github.com/Azure/azure-rest-api-specs/blob/792b94bd3d1e499882a4294fd345b2965684eed8/specification/chaos/Chaos.Management/examples/2025-01-01/Targets_Get.json#L19

I would expect this model to be supported in the example, or otherwise the model definition for Target should be modified to another implementation that does support object[] as value.

@brrusino brrusino added bug This issue requires a change to an existing behavior in the product in order to be resolved. v3 Version 3 of AutoRest C# generator. labels Nov 20, 2024
@ArcturusZhang ArcturusZhang self-assigned this Nov 22, 2024
@ArcturusZhang ArcturusZhang added the Mgmt This issue is related to a management-plane library. label Nov 22, 2024
@ArcturusZhang
Copy link
Member

Hi @brrusino thank you for opening this issue
I am working on a refactor of sample related code: #5107
This is very likely to fix this issue - because the code in the stack trace is being refactored in above PR.

Could you also share where you saw this issue happens?

@brrusino
Copy link
Member Author

@ArcturusZhang I saw this issue when running dotnet build /t:GenerateCode locally against our RP's solution inside the Azure .NET SDK repo (Azure.ResourceManager.Chaos).

@ArcturusZhang
Copy link
Member

@ArcturusZhang I saw this issue when running dotnet build /t:GenerateCode locally against our RP's solution inside the Azure .NET SDK repo (Azure.ResourceManager.Chaos).

I see. the generator version has been updated - therefore could you update your PR with the latest main branch and try again and see if we still have this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Mgmt This issue is related to a management-plane library. v3 Version 3 of AutoRest C# generator.
Projects
None yet
Development

No branches or pull requests

2 participants