Visitar URL original
Support dynamic-typed members in the source generator and analyzer by 1AbdullahButt · Pull Request #2319 · MessagePack-CSharp/MessagePack-CSharp · GitHub
Skip to content

Support dynamic-typed members in the source generator and analyzer - #2319

Open
1AbdullahButt wants to merge 1 commit into
MessagePack-CSharp:masterfrom
1AbdullahButt:fix/2318-dynamic-members
Open

1AbdullahButt wants to merge 1 commit into
MessagePack-CSharp:masterfrom
1AbdullahButt:fix/2318-dynamic-members

Conversation

@1AbdullahButt

Copy link
Copy Markdown

Fixes #2318

A member typed as dynamic made the analyzer throw AD0001 and the source generator fail with CS8785 (NotSupportedException: Specified method is not supported.). QualifiedTypeName.Create and the helpers in CodeAnalysisUtilities only handled array, named and type-parameter symbols, so an IDynamicTypeSymbol reached the throw.

This change treats dynamic the same as object, which is what it compiles to:

  • QualifiedTypeName.Create maps IDynamicTypeSymbol to System.Object, so List<dynamic> or Dictionary<string, dynamic> also work.
  • GetArity, GetTypeParameters and GetTypeArguments return 0 / empty for it, like for a type parameter.
  • dynamic and dynamic[] are added to the built-in type list next to object and object[], so no extra formatter is collected for them.

Test: MsgPack00xAnalyzerTests.DynamicTypedMembers covers a dynamic field, dynamic[], List<dynamic> and Dictionary<string, dynamic>. On master it fails with the AD0001 above; with this change the whole MessagePack.SourceGenerator.Tests project passes (161 passed, 9 skipped), run in the mcr.microsoft.com/dotnet/sdk:10.0 image.

🤖 Generated with Claude Code

A member typed as `dynamic` (or a collection of `dynamic`) made the
MessagePack analyzer and source generator throw NotSupportedException,
because QualifiedTypeName and CodeAnalysisUtilities had no case for
IDynamicTypeSymbol. Treat `dynamic` as `object`, which is what it is at
runtime, and list it with the other built-in types.

Fixes MessagePack-CSharp#2318

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1AbdullahButt

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

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

Successfully merging this pull request may close these issues.

dynamic type fails sourcegenerator CS8785 'MessagePackGenerator' failed to generate source.

1 participant