Skip to content

NullableContextOptions has no effect anymore (after upgrading to VS 16.2 Preview 1?) #3256

Closed

Description

@RayKoopa

I'm using 3.0.100-preview5-011568 in VS 16.2.0 Preview 1.0 and the following sample C# console application:

project.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <LangVersion>8.0</LangVersion>
    <NullableContextOptions>enable</NullableContextOptions>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>
</Project>

Program.cs

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            String? x = "Test";
            Console.WriteLine(x);
        }
    }
}

Despite having set NullableContextOptions to enable in the project file, I receive the warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' context. on the String? question mark character.

Similarly, another project cannot be compiled anymore due to CS8627: A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint. when using T? for a generic class type method parameter:

public void WriteOptional<T>(in T? value) where T : class, IWritable

When adding #nullabe enable to the top of the file(s) causing the warning, it is gone. It's like the project element lost its functionality after upgrading to VS 16.2.0? I did not change the SDK preview version and could compile the same sources correctly in 16.1.0.

I'm not sure if #3245 is relevant here.

Activity

  1. rainersigwald commented on May 22, 2019

    @rainersigwald
    Member

    NullableContextOptions was renamed to just Nullable in dotnet/roslyn#35516. @jcouv, am I reading dotnet/roslyn#35716 correctly that the task should currently accept both in 16.2.0-preview1, but only the new property is respected by CoreCompile?

    Do we have guidance for folks who are in this situation where they have dotnet on an older compiler/targets and VS on a newer one? Should it just be

        <Nullable>enable</Nullable>
        <NullableContextOptions>$(Nullable)</NullableContextOptions><!-- Remove after SDK 3.0-preview6 -->
  2. RayKoopa commented on May 22, 2019

    @RayKoopa
    Author

    Thanks for letting me now, it works now as expected with Nullable, I didn't find information that it was renamed (again), but kinda suspected it.
    I also wonder which project is responsible for adding those tags to auto completion in the csproj file, as all those new tags don't appear there in VS 2019 16.2 which I tried to check first?

  3. rainersigwald commented on May 22, 2019

    @rainersigwald
    Member

    I also wonder which project is responsible for adding those tags to auto completion in the csproj file

    That currently lives in an XSD file in MSBuild. I filed dotnet/msbuild#4391.

  4. added this to the Discussion milestone on May 23, 2019
  5. added a commit that references this issue on Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions