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

.NET 7 PublishReadyToRun causes crash when publishing, but it worked on .NET 6 #78278

Closed
alexandrehtrb opened this issue Nov 12, 2022 · 11 comments

Comments

@alexandrehtrb
Copy link

Description

Hello,

I am experimenting .NET 7 on my project and I am having a problem with PublishReadyToRun. It causes the dotnet publish process to crash.
The project is an Avalonia desktop GUI.

Reproduction Steps

My .csproj is as below. The referenced projects, Domain and Infrastructure, are vanilla, without any external dependencies, only pure .NET code.
This is the repo for the project: link.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AssemblyName>Pororoca.Desktop</AssemblyName>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <DebugType>embedded</DebugType>
    <EnableCompressionInSingleFile>True</EnableCompressionInSingleFile>
    <PublishReadyToRun>True</PublishReadyToRun>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\Pororoca.Domain\Pororoca.Domain.csproj"/>
    <ProjectReference Include="..\Pororoca.Infrastructure\Pororoca.Infrastructure.csproj"/>
  </ItemGroup>
  <ItemGroup>
    <Compile Update="**\*.xaml.cs">
      <DependentUpon>%(Filename)</DependentUpon>
    </Compile>
    <AvaloniaResource Include="**\*.xaml">
      <SubType>Designer</SubType>
    </AvaloniaResource>
    <AvaloniaResource Include="Assets\**" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.10.18" />
    <PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
    <PackageReference Include="Avalonia.ReactiveUI" Version="0.10.18" />
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.18" />
    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.18" />
  </ItemGroup>
</Project>

My dotnet publish full command is below; runtime is win-x64, PublishSingleFile is true:

dotnet publish ./src/Pororoca.Desktop/Pororoca.Desktop.csproj `
		--verbosity quiet `
		--nologo `
		--configuration Release `
		-p:PublishSingleFile=${publishSingleFileArg} `
		--self-contained true `
		--runtime $runtime `
		--output $outputFolder

Expected behavior

It should publish without problems.

Actual behavior

The following message shows up on console and an error dialog also appears:

C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(465,5):
error MSB6006: "C:\Users\Alexandre\.nuget\packages\microsoft.netcore.app.crossgen2.win-x64\7.0.0\tools\crossgen2.exe" exited with code -1073741511.
[C:\Projetos\Pororoca\src\Pororoca.Desktop\Pororoca.Desktop.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(353,5):
error NETSDK1096: Optimizing assemblies for performance failed. You can either exclude the failing assemblies from being optimized, or set the PublishReadyToRun property to false.
[C:\Projetos\Pororoca\src\Pororoca.Desktop\Pororoca.Desktop.csproj]

PublishReadyToRun_Error_NET7

crossgen2.exe - Entry Point Not Found
The procedure entry point EventSetInformation could not be located in the dynamic link library ADVAPI32.dll.

Regression?

It worked without problems on .NET SDK 6.0.402.

Known Workarounds

No response

Configuration

dotnet --info:

.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  6.0.402 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Other information

Running on Windows 7 x64.

@dotnet-issue-labeler
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.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 12, 2022
@EgorBo
Copy link
Member

EgorBo commented Nov 13, 2022

Presumably, the answer is the same as #78277 (comment)

@Symbai
Copy link

Symbai commented Nov 13, 2022

Here it says Windows 7 is still supported by .NET 7

@hez2010
Copy link
Contributor

hez2010 commented Nov 14, 2022

https://learn.microsoft.com/en-us/windows/win32/api/evntprov/nf-evntprov-eventsetinformation

EventSetInformation does not exisit on Windows 7. Seems that crossgen2 has dropped support for Windows 7.

@MichalStrehovsky
Copy link
Member

crossgen2 is compiled with NativeAOT and NativeAOT generates this import because WindowsAPIs.txt says it's safe to do so:

Without that entry, it would use LoadLibrary/GetProcAddress.

Apparently there's a try/catch that catches the EntryPointNotFoundException at runtime:

try
{
status = Interop.Advapi32.EventSetInformation(
m_regHandle,
eventInfoClass,
data,
dataSize);
}
catch (TypeLoadException)
{
m_setInformationMissing = true;
}

If Windows 7 is still supported, we'll probably have to go through the whole list and find APIs that don't exist on 7. The list was already supposed to do that, but looks like there was an issue seeding it:

# This list was seeded from mincore.lib in Windows SDK. Rarely used .libs, and APIs not available
# on all Windows editions (including Windows 7 and Windows Nano) were removed.

@ghost
Copy link

ghost commented Nov 14, 2022

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Hello,

I am experimenting .NET 7 on my project and I am having a problem with PublishReadyToRun. It causes the dotnet publish process to crash.
The project is an Avalonia desktop GUI.

Reproduction Steps

My .csproj is as below. The referenced projects, Domain and Infrastructure, are vanilla, without any external dependencies, only pure .NET code.
This is the repo for the project: link.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AssemblyName>Pororoca.Desktop</AssemblyName>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <DebugType>embedded</DebugType>
    <EnableCompressionInSingleFile>True</EnableCompressionInSingleFile>
    <PublishReadyToRun>True</PublishReadyToRun>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\Pororoca.Domain\Pororoca.Domain.csproj"/>
    <ProjectReference Include="..\Pororoca.Infrastructure\Pororoca.Infrastructure.csproj"/>
  </ItemGroup>
  <ItemGroup>
    <Compile Update="**\*.xaml.cs">
      <DependentUpon>%(Filename)</DependentUpon>
    </Compile>
    <AvaloniaResource Include="**\*.xaml">
      <SubType>Designer</SubType>
    </AvaloniaResource>
    <AvaloniaResource Include="Assets\**" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.10.18" />
    <PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
    <PackageReference Include="Avalonia.ReactiveUI" Version="0.10.18" />
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.18" />
    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.18" />
  </ItemGroup>
</Project>

My dotnet publish full command is below; runtime is win-x64, PublishSingleFile is true:

dotnet publish ./src/Pororoca.Desktop/Pororoca.Desktop.csproj `
		--verbosity quiet `
		--nologo `
		--configuration Release `
		-p:PublishSingleFile=${publishSingleFileArg} `
		--self-contained true `
		--runtime $runtime `
		--output $outputFolder

Expected behavior

It should publish without problems.

Actual behavior

The following message shows up on console and an error dialog also appears:

C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(465,5):
error MSB6006: "C:\Users\Alexandre\.nuget\packages\microsoft.netcore.app.crossgen2.win-x64\7.0.0\tools\crossgen2.exe" exited with code -1073741511.
[C:\Projetos\Pororoca\src\Pororoca.Desktop\Pororoca.Desktop.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(353,5):
error NETSDK1096: Optimizing assemblies for performance failed. You can either exclude the failing assemblies from being optimized, or set the PublishReadyToRun property to false.
[C:\Projetos\Pororoca\src\Pororoca.Desktop\Pororoca.Desktop.csproj]

PublishReadyToRun_Error_NET7

crossgen2.exe - Entry Point Not Found
The procedure entry point EventSetInformation could not be located in the dynamic link library ADVAPI32.dll.

Regression?

It worked without problems on .NET SDK 6.0.402.

Known Workarounds

No response

Configuration

dotnet --info:

.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  6.0.402 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Other information

Running on Windows 7 x64.

Author: alexandrehtrb
Assignees: -
Labels:

area-Tracing-coreclr, untriaged, area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky MichalStrehovsky removed area-Tracing-coreclr untriaged New issue has not been triaged by the area owner labels Nov 14, 2022
@MichalStrehovsky MichalStrehovsky added this to the 7.0.x milestone Nov 14, 2022
@MichalStrehovsky
Copy link
Member

Fortunately, we disable EventSource by default on NativeAOT so this is somewhat harder to hit for regular users. I made crossgen2 opt into EventSource because we actually wanted it to be enabled :/.

@jkotas
Copy link
Member

jkotas commented Nov 14, 2022

we'll probably have to go through the whole list and find APIs that don't exist on 7

When I have compiled this list, I have verified that all APIs in the list exist by running a script that did LoadLibrary+GetProcAddresses on Windows 7 test machine.

I think that the problem is that this API was backported to Windows 7 by KB3080149 and the Windows 7 test machines have this KB installed. One way to fix this problem is to add this KB to the list of Windows 7 prerequisites at https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net60#additional-deps

@sinePaul

This comment was marked as off-topic.

@MichalStrehovsky

This comment was marked as off-topic.

@agocke
Copy link
Member

agocke commented Jun 21, 2023

.NET 7 does not have Windows 7 support: https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md. If this were a fundamental API in the runtime itself, I would consider fixing this anyway, but because this is specifically for the SDK, crossgen in particular, I don't think Windows 7 support is necessary.

Users can publish on a Windows 10 machine and deploy to a Windows 7 machine. Development on Windows 7 itself is not a high priority.

@agocke agocke closed this as completed Jun 21, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

8 participants