msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[Bug]: Container Build error on .NET 6.0.29 and .NET SDK 6.0.421

Open christian-eaton opened this issue 10 months ago • 2 comments

Issue Description

We are attempting to build with a self hosted agent. The Host OS for the Build Server is Windows Server 2022 Data Center - Azure Edition. We are using Docker CE on the build server. Our project does contain a resx file. we get the following: C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: The "GenerateResource" task failed unexpectedly. [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {7B8A2D94-0AC9-11D1-896C-00C04FB6BFC4} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)). [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.IsDangerous(String filename) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.Execute() [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj]

I checked the file system and urlmon.dll does exist. I checked the registry and it is registered.

The following is a simple test project that reproduces the issue. NID.TestDeploy.zip

Steps to Reproduce

Setup a Windows Server 2022 Datacenter Azure Edition as a self hosted agent for Azure DevOps. Install and Configure Docker CE. Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Prepare Windows operating system containers | Microsoft Learn Configure Docker in Windows | Microsoft Learn Be sure to add the user that the Azure Devops Agent service is running as to a local windows group and add the group to the 'group' section of the daemon.json at C:\ProgramData\docker\config. Install Visual Studio 2022 build tools. Create a pipeline in Azure Devops. Run the pipeline.

Expected Behavior

Expect for the container to be built.

Actual Behavior

Build fails with the following: C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: The "GenerateResource" task failed unexpectedly. [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {7B8A2D94-0AC9-11D1-896C-00C04FB6BFC4} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)). [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.IsDangerous(String filename) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.Execute() [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\NID.TestDeploy\NID.TestDeploy.csproj] C:\Program Files\dotnet\sdk\6.0.421\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\NID.TestDeploy\NID.TestDeploy.csproj]

Analysis

No response

Versions & Configurations

MSBuild version 17.9.8+b34f75857 for .NET Framework 17.9.8.16306

christian-eaton avatar Apr 24 '24 16:04 christian-eaton

team triage: @GangWang01 can you try to repro this?

AR-May avatar Apr 30 '24 13:04 AR-May

I have same problem. I am using Docker Desktop in Windows mode. At do "dotnet publish" (defined in dockerfile of service) using docker compose, the error happen. At do "dotnet build", where it succed a step back, not happen.

I am looking this file:

https://github.com/dotnet/msbuild/blob/main/src/Tasks/GenerateResource.cs

Maybe the question is how we can skip the calling to "IsDangerous" method.

esfernandez avatar May 01 '24 03:05 esfernandez

I could repro this issue using Docker Desktop with Windows container on Windows. Note that this issue could not be reproduced with Linux container. It may be duplicated with https://github.com/dotnet/msbuild/issues/7946 which was fixed in vs17.5. Referring to https://github.com/dotnet/msbuild/issues/7946#issuecomment-1238304681, we can work around by using Windows Server Core for the SDK tag as build FROM mcr.microsoft.com/dotnet/sdk:6.0.420-windowsservercore-ltsc2022 AS build. I verified the workaround and it worked.

Since SDK 6.0.421 has MSBuild version 17.3.2+561848881 for .NET which doesn't have the fix, the issue appears.

GangWang01 avatar Jun 18 '24 09:06 GangWang01

mcr.microsoft.com/dotnet/sdk:7.0 or later has the fix and works well as build.

GangWang01 avatar Jun 21 '24 05:06 GangWang01

@baronfel This issue was fixed in vs17.5 branch, which corresponds to sdk 7.0. Should we consider backporting it to sdk 6.0 as well?

AR-May avatar Jun 26 '24 13:06 AR-May

No, we are in the last 6 months of 6.0 support, which means we only do security fixes at this point.

baronfel avatar Jun 26 '24 13:06 baronfel

Closing this issue then. Please feel free to re-open it if @GangWang01 suggestions does not resolve your issue.

AR-May avatar Jun 26 '24 15:06 AR-May