dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

CS8632 - Nullable annotations context needs to be enabled manually #3878

Closed bddckr closed 4 years ago

bddckr commented 4 years ago

Steps to Reproduce

  1. Create a new Xamarin.Android project.
  2. Adjust any of the (non-generated) cs files to use a nullable reference type (a C# 8.0 feature).
  3. Attempt to build the project and notice that you're getting the compiler warning CS8632.

I did attempt to fix this by adding

<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>

to the csproj, but neither that, nor just using Nullable worked. Additionally using <NullableContextOptions>enable</NullableContextOptions> also didn't help.

XamarinAndroid-NullableReferenceTypeBug.zip

Expected Behavior

C# 8.0 should be enabled since #3807, therefore I expect nullable reference types in my own code to work without compiler errors or warnings.

Actual Behavior

Any usage of nullable reference types in a Xamarin.Android project results in CS8632.

Version Information

``` Microsoft Visual Studio Community 2019 Preview Version 16.4.0 Preview 3.0 VisualStudio.16.Preview/16.4.0-pre.3.0+29430.225 Microsoft .NET Framework Version 4.8.03752 Installed Version: Community Visual C++ 2019 00435-60000-00000-AA534 Microsoft Visual C++ 2019 .ignore 1.2.77 A language service that makes it painless to handle all types of .ignore files such as .gitignore, .tfignore, etc. Add New File 3.5.134 The fastest and easiest way to add new files to any project - including files that start with a dot ASP.NET and Web Tools 2019 16.4.440.60800 ASP.NET and Web Tools 2019 ASP.NET Web Frameworks and Tools 2019 16.4.440.60800 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.4.440.60800 Azure App Service Tools v3.0.0 C# Tools 3.4.0-beta3-19525-13+b8a5611e3db4f7ac3b5e1404b129304b5baf843e C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Child Process Debugging Power Tool 1.0 Power tool to add child process debugging to Visual Studio. Code Cleanup On Save 1.0.6 Automatically run one of the Code Clean profiles when saving the document. This ensures your code is always formatted correctly and follows your coding style conventions. CodeMaid 11.1.204 CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, R, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. CreateUnitTestBoilerplateCommand Extension 1.0 CreateUnitTestBoilerplateCommand Visual Studio Extension Detailed Info Disable No Source Available Tab 3.0 This small extension will prevent the tool window with title 'No Source Available' from appearing in Visual Studio, and preserve the focus on the currently active tab. Alas, along with brilliant improvements such as IntelliTrace, Visual Studio otherwise displays a tab stating that it cannot find source code where to step into. This is obvious when simply pausing an idle application, therefore it forces the developer to close this window before getting back to the code he wants to modify, which may be a productivity killer. Let's hope this extension will be short-term lived as the Visual Studio development team adds an option to better control this behavior! This extension should work with all locales of Visual Studio. EditorConfig Language Service 1.17.260 Language service for .editorconfig files. EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. Extensibility Message Bus 1.2.0 (d16-2@8b56e20) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. File Icons 2.7 Adds icons for files that are not recognized by Solution Explorer FormatCommand Extension 1.0 FormatCommand Visual Studio Extension Detailed Info GitHub.VisualStudio 2.10.8.8132 A Visual Studio Extension that brings the GitHub Flow into Visual Studio. GuidGenPackage 1.0 Offers the new GuidGen tool in the VS Tools menu. IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info JsonViewer 1.0 JSON viewer Markdown Editor 1.12.236 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown. Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 2.0.87+gbb515bf382 Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package Mono Debugging for Visual Studio 16.5.23 (1b51e8c) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 5.4.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Open in Visual Studio Code 1.4.46 Adds a menu command that lets you open any solution, project, folder and file in Visual Studio Code. PowerShell Pro Tools for Visual Studio 1.0 A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio. Project System Tools 1.0 Tools for working with C#, VisualBasic, and F# projects. ProjectConfigurationManager 1.9.2171.0 Information about my package ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Reference Conflict Analyser Extension 1.0 A tool for analysis of the "Could not load file or assembly or one of its dependencies" problem. ReviewsToolWindow Extension 1.0 ReviewsToolWindow Visual Studio Extension Detailed Info Rewrap Extension 1.0 Rewrap Extension Detailed Info Smart Command Line Arguments Extension 2.2.0 A Visual Studio Extension which aims to provide a better UI to manage your command line arguments. For additional information, visit https://github.com/MBulli/SmartCommandlineArgs SQL Server Data Tools 16.0.61910.21130 Microsoft SQL Server Data Tools SubwordNavigation 1.5.0 Provides subword navigation for Visual Studio. Syntax Highlighting Pack 2.8.134 Adds syntax highlighting and snippet support for a wide variety of programming languages such as Clojure, Go, Jade, Lua, Swift, Ruby and many more... TermWindow Extension 1.0 TermWindow Visual Studio Extension Detailed Info TypeScript Tools 16.0.11023.2001 TypeScript Tools for Microsoft Visual Studio Viasfora 4.2.188 Add color to your Visual Studio editor! Visual Basic Tools 3.4.0-beta3-19525-13+b8a5611e3db4f7ac3b5e1404b129304b5baf843e Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 10.4 for F# 4.6 16.4.0-beta.19504.1+e3676d75d501a2df6789ad0f5ebc310bc2cee6b5 Microsoft Visual F# Tools 10.4 for F# 4.6 Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Spell Check Everywhere VSSpellCheckEverywhere An extension that enables spell checking within any Visual Studio file editor or tool window that uses WPF text boxes. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Spell Checker VSSpellChecker An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with tool windows. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers Visual Studio Tools for Unity 4.4.1.0 Visual Studio Tools for Unity VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSColorOutput 2.6.7 Color output for build and debug windows - https://mike-ward.net/vscoloroutput Xamarin 16.4.000.295 (d16-4@7a8e02a) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.4.0.439 (remotes/origin/d16-4@e698759e2) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.4.24 (0222648) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 10.1.0.29 (d16-4/bbb5297) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 8946e49 Java.Interop: xamarin/java.interop/d16-4@c4e569f ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.28.0@46204c4 Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b Xamarin.iOS and Xamarin.Mac SDK 13.8.1.17 (84ee215) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```
jpobst commented 4 years ago

Looks like the dotnet team chose not to support Nullable for the legacy project file type. :(

https://github.com/dotnet/project-system/issues/5551

It sounds like it will work for the build, but not Intellisense.

jonathanpeppers commented 4 years ago

@bddckr for now does using MSBuild.Sdk.Extras work for TargetFramework=monoandroid?

It is not officially supported, but may be an option here.

bddckr commented 4 years ago

Ah that's too bad - I didn't know about Nullable not being a thing in legacy projects! It does indeed seem to be fine for builds... Just sucks adding #nullable enable to all our files' headers. We have to do so because we made the decision to make CS8632 an error instead of a warning (even then we're running with warnings as errors).


@jonathanpeppers I might be wrong here but that won't work for the actual app project of Xamarin.Android?

I would love to use new SDK style projects for the Xamarin app csproj if I can, but so far it looks like one basically gives up the whole IDE integration when doing so? I need my team to deploy from Visual Studio, while I'm fine with doing whatever MSBuild-compliant thing to just make the CI happy.

jonathanpeppers commented 4 years ago

Yeah, MSBuild.Sdk.Extras probably won't work for the main application project--just libraries.

bddckr commented 4 years ago

I'm closing this due to https://github.com/dotnet/project-system/issues/5551 then.

Thanks for the fast replies!