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

[dotnet-sdk-9.0.100-rc.2.24474.11] paint.netcore build with errors about elements from Microsoft.Windows.SDK.NET are not found #43707

Closed
Junjun-zhao opened this issue Sep 26, 2024 · 22 comments
Labels
Area-WindowsSDK Issues related to the Windows SDK and how it is included and managed in the .NET SDK untriaged Request triage from a team member

Comments

@Junjun-zhao
Copy link
Member

Application Name: paint.netcore
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-9.0.100-rc.2.24474.11
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2261861

Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.300: Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.1.24452.12: Pass
3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.2.24470.13: Fail
4). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.2.24474.11: Fail

Description :
When build the 3rd party application paint.net with the latest .NET 9 sdk, it failed with errors:

CS0103  The name 'DispatcherQueueController' does not exist in the current context
CS0103  The name 'DispatcherQueue' does not exist in the current context
CS0103  The name 'DispatcherQueuePriority' does not exist in the current context
CS0103  The name 'DisplayInformationInterop' does not exist in the current context
CS0234  The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
CS0234  The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
CS0234  The type or namespace name 'Foundation' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
CS0246  The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
CS0246  The type or namespace name 'DispatcherQueue' could not be found (are you missing a using directive or an assembly reference?)
CS0246  The type or namespace name 'TypedEventHandler<,>' could not be found (are you missing a using directive or an assembly reference?)
CS0246  The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
CS1660  Cannot convert anonymous method to type 'TypedEventHandler<Graphics.Display.DisplayInformation, object>?' because it is not a delegate type

Minimal Repro Steps: (Demo attached:ConsoleDemo.zip)
The machine has dotnet-sdk-9.0.100-rc.2.24474.11 installed.
1.Create a .NET 8 Console application.
2. Update the csproj file with following changes:

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<WindowsSdkPackageVersion>10.0.26100.1</WindowsSdkPackageVersion>
</PropertyGroup>

  1. Add a AdvancedColorKind.cs file with following code:
using System;
using Windows.System;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.Media.Miracast;
 
namespace ConsoleApp1
{
    using DisplayInformationWinRT = global::Windows.Graphics.Display.DisplayInformation;
    public class Test
    {
        private readonly DispatcherQueue dispatcherQueue;
        DispatcherQueuePriority dqp = DispatcherQueuePriority.Low;
        private static readonly ThreadLocal<DispatcherQueueController> perThreadController;
        public void TestMethod()
        {
            TypedEventHandler<DisplayInformationWinRT, object>? advancedColorInfoChangedHandler = null;
            advancedColorInfoChangedHandler =
                delegate (DisplayInformationWinRT displayInformation, object _)
                {  };
        }
    }

    internal enum AdvancedColorKind
    {
        HighDynamicRange = global::Windows.Graphics.Display.AdvancedColorKind.HighDynamicRange,
        StandardDynamicRange = global::Windows.Graphics.Display.AdvancedColorKind.StandardDynamicRange,
        WideColorGamut = global::Windows.Graphics.Display.AdvancedColorKind.WideColorGamut
    }
}

  1. Open command prompt window and navigate to .sln file folder.
  2. Run "dotnet new globaljson" and make sure the SDK version assigned in global.json file is 9.0.100-rc.2.24474.11.
{
  "sdk": {
"version": "9.0.100-rc.2.24474.11"
  }
}
  1. Build the project.

Expected Result:
Build Successful.

Actual Result:
Build with following errors:

Please refer to Binlog and Compiler log from msbuild_binlog complog.zip

CS0246 

The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
CS0103 The name 'DispatcherQueuePriority' does not exist in the current context
CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'DispatcherQueue' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'DispatcherQueuePriority' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'TypedEventHandler<,>' could not be found (are you missing a using directive or an assembly reference?)
CS0400 The type or namespace name 'Windows' could not be found in the global namespace (are you missing an assembly reference?)
CS0400 The type or namespace name 'Windows' could not be found in the global namespace (are you missing an assembly reference?)
CS0400 The type or namespace name 'Windows' could not be found in the global namespace (are you missing an assembly reference?)
CS0400 The type or namespace name 'Windows' could not be found in the global namespace (are you missing an assembly reference?)
CS1660 Cannot convert anonymous method to type 'TypedEventHandler<Windows.Graphics.Display.DisplayInformation, object>?' because it is not a delegate type

Findings:
We found all the namespaces/types in errors come from Microsoft.Windows.SDK.NET. When using dotnet-sdk-9.0.100-rc.2.24474.11 to build the app, the "Windows" namespace is not be recognized by compiler and the elements from "Windows" namespaces are also cannot be recognized.

App Repro Steps on repro machine:(dotnet-sdk-9.0.100-rc.2.24474.11 installed)

Please get the repro machine information from DevDiv bug:

  1. Run command "dotnet build" in C:\Users\Test01\Desktop\paint.net\PaintDotNet.

Expected Result:
Build successfully.

Actual Result:
Build failed with errors:

The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The name 'DispatcherQueue' does not exist in the current context
The name 'DispatcherQueuePriority' does not exist in the current context
The name 'DisplayInformationInterop' does not exist in the current context
The name 'DispatcherQueueController' does not exist in the current context
The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'Foundation' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'Graphics' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'System' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueue' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'TypedEventHandler<,>' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'TypedEventHandler<,>' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DispatcherQueueController' could not be found (are you missing a using directive or an assembly reference?)
Cannot convert anonymous method to type 'TypedEventHandler<Graphics.Display.DisplayInformation, object>?' because it is not a delegate type

Dotnet Info:

.NET SDK:
 Version:           9.0.100-rc.2.24474.11
 Commit:            315e1305db
 Workload version:  9.0.100-manifests.82e6a096
 MSBuild version:   17.12.0-preview-24473-03+fea15fbd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0-rc.2.24473.5
  Architecture: x64
  Commit:       990ebf52fc

.NET SDKs installed:
  10.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
 Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Sep 26, 2024
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

1 similar comment
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Junjun-zhao
Copy link
Member Author

Hi @jaredpar and @arkalyanms, this issue was also found during source compat testing, could you please take a look at it and confirm if this RC2 blocker? Thanks.

CC: @marcpopMSFT

@jaredpar
Copy link
Member

This is similar to the other issue. Can you grab a compiler log for this too?

Again though, this is very very unlikely to be a compiler bug. It's much more likely to be either a codegen bug in the generator or a bug in the SDK for including the generator. We should be getting the owner of that generator into the conversation so we can figure out what is happening here.

@baronfel

@baronfel
Copy link
Member

@merriemcgaw do you know anything about the source generators that are part of the Windows SDK, and/or who we could pull in to take a look here?

@baronfel
Copy link
Member

and maybe @Sergio0694 knows if there's something we should be looking at

@Sergio0694
Copy link
Contributor

Does that source explicitly have <WindowsSdkPackageVersion> set to an old version (ie. < .39) by any chance?

@baronfel
Copy link
Member

@Sergio0694 the repro sample has <WindowsSdkPackageVersion>10.0.26100.1</WindowsSdkPackageVersion>.

@Sergio0694
Copy link
Contributor

Sergio0694 commented Sep 26, 2024

Then that's the problem. That version is uber outdated and won't work correctly by design. You should be able to just remove it. The new .NET 9 SDK will already set the right one for the profile in use. Alternatively, bump that to .45 and try again. Either way the fact you were getting those errors when using that package version with the .NET 9 SDK is by design 🙂

@baronfel
Copy link
Member

@Sergio0694 Did this requirement change between rc1 and rc2? Is there a breaking change notice to track the behavior different in .NET 8 and .NET 9? Basically how to we help users either not get broken or guide them through the upgrade. This kind of hard-to-diagnose error is something we really try to avoid in the SDK because it harms adoption of new versions.

@Sergio0694
Copy link
Contributor

"Did this requirement change between rc1 and rc2?"

Yeah, I merged #41936 which added support for profiles. We needed this for UWP on .NET 9.

"Is there a breaking change notice to track the behavior different in .NET 8 and .NET 9?"

I believe we might not have diagnostics in the specific scenario where you're not using UWP nor WinAppSDK. Worth noting though that manually setting that property is explicitly not recommended and only meant to be used in advanced scenarios by users wanting to test preview bits. If they explicitly set an old version and forget to update it, that's kinda on them. If you don't set that and just let the .NET SDK select the right package version for you, things will just work as expected. Not saying we can't or shouldn't potentially improve the diagnostics here, but worth pointing out that this is not the normal scenario.

cc. @manodasanW thoughts on this?

@jaredpar
Copy link
Member

Is there a way to raise a diagnostic here? It seems reasonable, given this example, that customers will get into this problem. Can we proactively add a diagnostic here to warn them? Diagnostics are easy to attach to README, FAQ, etc ... compilation errors are not.

Basically how do we give customers an easy path forward.

@baronfel
Copy link
Member

I'm imagining something like a 'known minimum version bound' property in the Windows SDK or something that the targets could use to warn the user if they are using a version of the WindowsSdkPackageVersion that is not supported by the targets. Something as simple as that linking to documentation about how to properly set up your project can go a very long way towards helping users upgrade and reducing user frustration with cheese-moving.

@manodasanW
Copy link
Contributor

I agree it would make sense to provide a warning where we detect that they are explicitly using an older version of the Windows SDK projection package with the .NET 9 SDK that is expecting a version that has profiles. The check should have an opt-out in case they are intentionally doing it while trying to fix other dependencies.

@Redth
Copy link
Member

Redth commented Sep 26, 2024

In the case of .NET MAUI, not setting the WindowsSdkPackageVersion is a problem for us if we are using newer .NET SDK versions which update the projections here but an older version of WindowsAppSDK.

We observed a similar issue with .NET 9 RC2 builds where MAUI apps started failing building with a 1.5 version of WindowsAppSDK suggesting setting an explicit WindowsSdkPackageVersion to fix the issue. This does seem to 'work around' the issue for us, but implies that having no explicit version set isn't always 'safe'.

Our choices seem to be explicitly setting WindowsSdkPackageVersion (and risking incompatibilities the longer we leave that set), or upgrading to WindowsAppSDK 1.6 which we are still in the process of validating against and carries its own set of risks (our work in progress PR highlights some of the fixes we're making to work around unexpected changes to WindowsAppSDK behaviours: dotnet/maui#24266 )

@Junjun-zhao
Copy link
Member Author

Thanks all for helping look into this issue.

After setting WindowsSdkPackageVersion to the latest version 10.0.26100.45,the errors mentioned in this bug are all gone.

But a new issue occurs during build with error "Missing partial modifier on declaration of type 'AffineTransform2DEffect3'; another partial declaration of this type exists, possibly codegen issue in the generator same as #43680. We filed a new issue #43746. Could you please also take look at that one? Thanks.

@baronfel baronfel added the Area-WindowsSDK Issues related to the Windows SDK and how it is included and managed in the .NET SDK label Sep 27, 2024
@arunchndr
Copy link
Member

@Junjun-zhao That one seems a valid error with two declarations, one in source code and one in the generated from the SDK. Is it not a test setup issue?

@PriyaPurkayastha
Copy link

We have repro machines available. My team(Junjun) is based in China and it is already weekend there, so it might be better to look at the repro machines to further investigate. Repro machine details are in the DevDiv bug(https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2261861) and VPN is needed to connect to the VMs.

@Junjun-zhao
Copy link
Member Author

@Junjun-zhao That one seems a valid error with two declarations, one in source code and one in the generated from the SDK. Is it not a test setup issue?

It is not a test setup issue,@jaredpar and @manodasanW have investigated and #43746 is an issue with the WinRT source generator microsoft/CsWinRT#1799

@Junjun-zhao
Copy link
Member Author

@jaredpar Any decision solution made for this issue? As we are going to sign off RC validation, could you help confirm if it is a RC2 blocker?

@PriyaPurkayastha
Copy link

@Junjun-zhao Jared's team doesn't own these fixes. There are discussions going on about these fixes and associated timelines in Teams. Richa and others are aware of these issues. We need to wait for decision/update. I will let you know once an update is available in the RC2 Teams chat.

@Junjun-zhao
Copy link
Member Author

@manodasanW We verified this issue with the latest build dotnet-sdk-9.0.100-rtm.24515.15, it has been fixed. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-WindowsSDK Issues related to the Windows SDK and how it is included and managed in the .NET SDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

9 participants