question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[dotnet-sdk-8.0.100-preview.1.23107.4] Build with warnings after retargeting to .NET 8.0 for paint.net app

See original GitHub issue

Application Name: paint.net OS: Windows10 21h2 CPU: x64 App Source checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1745300

Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23107.4 + app (default 7.0): Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23107.4 + app (retarget 8.0): Fail 3). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.100-preview.1.23108.10-win-x64 + app (retarget 8.0): Fail

Repro steps: The machine has Visual Studio 2022 Preview installed because this app needs to build with Visual Studio and need to retarget .NET 8.0. 1.Copy app source paint.net to local machine. 2. Follow the steps in paintnet_Readme.txt file to configure the build environment. (File attached https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1745300) 3. Build the solution in Visual Studio Expected Result: Build successful. Actual Result: Build with following warnings (There are some other errors related to arm64 projects and build platform 143, please ignore them):

image

Minimal Repro sample: Minimal repro sample attached. paint.net demo.zip

Repro steps:

  1. Create a default .net 7.0 WinForm app.
  2. Add a new Class1.cs.
  3. Add following code in Class1.cs
internal class Class1: Class2
    {
        private void Method1(object? sender, EventArgs e)
        {
            Class2 c2 = (Class2)sender!;
            Class3 c3 = (Class3)c2!.Tag;
            Method2(c3);
        }

        public void Method2(Class3 c3)
        {    }
    }

    internal class Class2: ToolStripMenuItem
    { 
        protected override void OnParentChanged(ToolStrip oldParent, ToolStrip newParent)
        {
            base.OnParentChanged(oldParent, newParent);
        }
    }

    internal class Class3
    {   }
  1. Build the project, there is no warning in Error List windows of Visual Studio.
  2. Retarget the project to .net8.0-windows.
  3. Rebuild the project.

Expected Result: Build successful.

Actual Result:

Build with warning:

Warning CS8604 Possible null reference argument for parameter 'c3' in 'void Class1.Method2(Class3 c3)'.
Warning CS8765 Nullability of type of parameter 'oldParent' doesn't match overridden member (possibly because of nullability attributes).
Warning CS8765 Nullability of type of parameter 'newParent' doesn't match overridden member (possibly because of nullability attributes).
Warning CS8600 Converting null literal or possible null value to non-nullable type.

Findings:

  1. When the custom class inherit from ToolStripMenuItem (come from System.Windows.Forms.dll), these warnings will appear in .NET 8.0, but not in .NET 7.0. The behavior changed in .NET 8.0.

  2. According to the document: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings There are some ways recommended to resolve these warnings in document. We can add ? or ! to let the warnings disappear.

 internal class Class1 : Class2
    {
        private void Method1(object? sender, EventArgs e)
        {
            Class2 c2 = (Class2)sender!;
            Class3 c3 = (Class3)c2!.Tag!;
            Method2(c3);
        }

        public void Method2(Class3? c3)
        { }
    }

    internal class Class2 : ToolStripMenuItem
    {
        protected override void OnParentChanged(ToolStrip? oldParent, ToolStrip? newParent)
        {
            base.OnParentChanged(oldParent, newParent);
        }
    }

@dotnet-actwx-bot @dotnet/compat

Issue Analytics

  • State:open
  • Created 7 months ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
rickbrewcommented, Feb 15, 2023

This is currently by-design. There is no action item on WinForms at this point, the application has some work it could do while we’re going through the community led effort. (Thanks @elachlan!!) @rickbrew, wanted to get this on your radar early in .NET 8.

Saw this in .NET 7, glad to see more coming in .NET 8 😃

BinaryFormatter will be my biggest blocker moving forward, that’s a lot of work to migrate away from. Nullability annotations are no sweat.

1reaction
merriemcgawcommented, Feb 14, 2023

This is currently by-design. There is no action item on WinForms at this point, the application has some work it could do while we’re going through the community led effort. (Thanks @elachlan!!) @rickbrew, wanted to get this on your radar early in .NET 8.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[dotnet-sdk-8.0.100-preview.1.23107.4] ...
Application Name: paint.net OS: Windows10 21h2 CPU: x64 App Source checking at: ... Build with warnings after retargeting to .NET 8.0 for ......
Read more >
Installed the .NET 8 Preview, and Now Projects I Open With ...
I'm having the darndest issue. Whenever I try to build I get the error "The current .NET SDK does not support targeting .NET...
Read more >
(Solved) Paint.net installation not working
Everytime I try to install paint.net it never finishes, I give the installer access, it loads a few things then it shuts down...
Read more >
Fixing build warning NETSSDK1138 when ...
In this short post I describe how to get rid of the following build warning: C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.
Read more >
Unable to install / reinstall Paint.Net (DotNet error)
I'm having a real issue trying to install Paint.net from scratch again with the last installer. It happens that I couldn't update Paint.net...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found