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

fix #1031 #1033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix #1031 #1033

wants to merge 1 commit into from

Conversation

dogdie233
Copy link

What cause the issue

In line 94

var namespaceName = syntaxReceiver.YamlStaticContextType?.ContainingNamespace.ContainingNamespace;
write($"namespace {syntaxReceiver.YamlStaticContextType?.GetNamespace() ?? "YamlDotNet.Static"}", true);
write("{", true); indent();
new StaticContextFile(write, indent, unindent, _context).Write(syntaxReceiver);
new StaticObjectFactoryFile(write, indent, unindent, _context).Write(syntaxReceiver);

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.

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.

1 participant