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 type conflicts when targeting frameworks without nullability attributes #460

Merged
merged 1 commit into from Jan 18, 2020
Merged

Fix type conflicts when targeting frameworks without nullability attributes #460

merged 1 commit into from Jan 18, 2020

Conversation

Nihlus
Copy link
Contributor

@Nihlus Nihlus commented Dec 21, 2019

In its current form, YamlDotNet produces type conflicts with other projects that target frameworks which do not include nullability attributes, but add them in other ways to allow full nullability support in the compiler. The issue typically displays as a warning during compilation that one or the other type was selected.

Appearance.cs(255, 14): [CS0436] The type 'NotNullWhenAttribute' in '/[PROJECT]/obj/Debug/netstandard2.0/NuGet/16700ED22EA87F787941E08E0F8DABDD3F92ADDC/Nullable/1.1.1/Nullable/NullableAttributes.cs' conflicts with the imported type 'NotNullWhenAttribute' in 'YamlDotNet, Version=8.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e'. Using the type defined in '[PROJECT]/obj/Debug/netstandard2.0/NuGet/16700ED22EA87F787941E08E0F8DABDD3F92ADDC/Nullable/1.1.1/Nullable/NullableAttributes.cs'.

The issue is caused by YamlDotNet declaring the polyfill attributes in Portability.cs as public, and not covering all frameworks in the preprocessor directives that guard them.

This pull request removes YamlDotNet's own polyfill attributes, and references a compile-time NuGet packages which defines all nullability attributes and compiles them as internal attributes into targets which require them, preventing any conflicts with other projects. The package used (Nullable) is completely transparent to the end user, and does not incur any additional dependencies for consumers.

Fixes #456.

@Nihlus
Copy link
Contributor Author

Nihlus commented Dec 21, 2019

I'm unsure why the build failed. It does not appear to have anything to do with my changes.

@aaubry aaubry merged commit aaac633 into aaubry:master Jan 18, 2020
@aaubry
Copy link
Owner

aaubry commented Jan 18, 2020

Thanks for this. I will do a release today that includes this.

@Nihlus
Copy link
Contributor Author

Nihlus commented Jan 18, 2020

Great!

@aaubry
Copy link
Owner

aaubry commented Jan 18, 2020

YamlDotNet 8.1.0 has just been uploaded to NuGet.org. It should be available in a few minutes.

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.

YamlDotNet shouldn't export NRT attributes.
2 participants