Skip to content

Conversation

DeagleGross
Copy link
Member

@DeagleGross DeagleGross commented May 22, 2025

We suspect inability to serialize private fields because of the ref assembly. Therefore I am adding a check on code generator, which will emit a diagnostic if the target model is coming from the ref assembly.

Also moved ruleIds to separate file to easily nagivate accross different existing diagnosticIds.

Example:
image

Fixes #9265

Microsoft Reviewers: Open in CodeFlow

@DeagleGross DeagleGross self-assigned this May 22, 2025
public const string Category = "Usage";

private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
RuleId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should make this an error, since it is most likely going to break something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to error

{
public const string RuleId = DiagnosticRuleId.ReferenceAssemblyWithGenerateSerializer;
public const string Title = "[GenerateSerializer] used in a reference assembly";
public const string MessageFormat = """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps MessageFormat & Description need to be swapped, essentially, so that the description includes the detail and message format only includes the top line "The type {0} is marked with [GenerateSerializer] in a reference assembly"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swapped. let me know if you think this is fine

@ReubenBond ReubenBond changed the title fix: report warning if generating serializer for model from ref assembly Report error when generating serializer for model from ref assembly May 22, 2025
@DeagleGross DeagleGross merged commit c32ff97 into main May 23, 2025
108 of 113 checks passed
@DeagleGross DeagleGross deleted the dmkorolev/warn-serializer branch May 23, 2025 08:34
@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orleans serializer is unable to handle correctly private fields of classes defined in some specific assemblies
2 participants