YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

fix #1031

Open dogdie233 opened this issue 10 months ago • 0 comments
trafficstars

What cause the issue

In line 94

https://github.com/aaubry/YamlDotNet/blob/b8ac2a98ffcc12434eff6c6abb75b38ad1b1ab04/YamlDotNet.Analyzers.StaticGenerator/TypeFactoryGenerator.cs#L92-L98

When the StaticContext to be generated is in the global namespace, syntaxReceiver.YamlStaticContextType?.GetNamespace() returns an empty string instead of null. As a result, the ?? operator does not take effect.

So, the generated code in YamlDotNetAutoGraph.g.cs ends up as follows:

...
namespace 
{
    ...

Since there is no identifier following namespace, the compilation fails.

About unit test case

Due to the stringent conditions required to trigger this issue, I am unsure how to write a unit test. Should I create a new console project to reproduce the issue?

A potential problem

When the auto-generated StaticContext is in the global namespace, other classes, such as StaticObjectFactory, will also be created in the global namespace. This could potentially conflict with other classes.

dogdie233 avatar Jan 16 '25 21:01 dogdie233