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

net7 - Build freezes when publishing trimmed app with net6+ class libraries #87220

Closed
michaldobrodenka opened this issue Dec 15, 2022 · 26 comments
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Milestone

Comments

@michaldobrodenka
Copy link

michaldobrodenka commented Dec 15, 2022

I have a sln which contains several class libraries and one executable cmdline csproj. I'm modernizing whole solution, removing mono/net461 executable, upgrading class libraries from netstandard20 to net7.
When publishing my app with parameters:

dotnet publish my.csproj -r linux-arm -p:PublishTrimmed=True -p:TrimMode=partial --self-contained true -c Release -f net7.0

and one specific csproj of my class libraries is set to net7.0 build freezes. on line
C:\Program Files\dotnet\dotnet.exe exec "C:\Program Files\dotnet\sdk\7.0.101\Roslyn\bincore\csc.dll" ...
Freezing means than NET host process takes almost all cpu, a several Gigs of RAM.

To "unfreeze" build I have to:

  • remove trimming ( -p:PublishTrimmed=True -p:TrimMode=partial ) - without trimming build is completed in 20sec
  • set this one library to netstandard20 and build with net7 SDK
  • set all csproj files in solution to net6 and build in net6 SDK - net6 build completes in about a minute without problems

Building it on Windows 10,11 and in linux docker.

What I've tried and didn't help:

  • build with MS net7 SDK docker
  • build for different runtimes - linux-x64, win-x64, linux-arm...
  • SDK 7.0.100 and 7.0.101

Unfortunately project is closed source. But I can run some test, access my desktop remotely or something like that.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Dec 15, 2022
@ghost
Copy link

ghost commented Dec 15, 2022

@dotnet/linker-contrib a new issue has been filed in the ILLink area, please triage

@matheusavi
Copy link

matheusavi commented Jan 3, 2023

Same issue building on al2! I needed to set an 8gb machine to build a small project using AOT.

@michaldobrodenka
Copy link
Author

I couldn't finish build even after several hours.

@biste5
Copy link

biste5 commented Jan 4, 2023

for us, our Blazor WASM project builds in about 4 minutes with .NET 6 or without trimming, 1+ hour with .NET 7 and trimming

@michaldobrodenka
Copy link
Author

Maybe I could try to wait more than 6 hours. In net6 it is build within 100seconds.

@michaldobrodenka
Copy link
Author

Waiting 10hours didn't help.
I've attached to running csc.

2 tasks are blocked here:
image

@michaldobrodenka
Copy link
Author

image

@michaldobrodenka
Copy link
Author

The same issue with sdk 7.0.200. Last version I was able to build my project with was something like net7 Preview7

@michaldobrodenka
Copy link
Author

image

@michaldobrodenka
Copy link
Author

still hangs up in net8 preview1

@michaldobrodenka
Copy link
Author

I have a strong suspicion it's somehow connected to using netstanrard2.1 libraries in solution

@michaldobrodenka
Copy link
Author

I have a strong suspicion it's somehow connected to using netstanrard2.1 libraries in solution

it's not about netstandard2.1. It was just that net8 Preview 1 could not trim netstd2.1 libs.

Still reproducible in latest 7.0.4 & 8P2

@michaldobrodenka michaldobrodenka changed the title net7 - Build freezes when publishing trimmed app net7 - Build freezes when publishing trimmed app with net6+ class libraries Apr 25, 2023
@michaldobrodenka
Copy link
Author

Ok, I found a little workaround - when all referenced csprojs are net5 or lower, main project (net6.0, net7.0) builds normally with net7 SDK. So I can use features later than netstandard2.1, just not latest one - 6/7.

@sbomer
Copy link
Member

sbomer commented Jun 7, 2023

@michaldobrodenka this is likely the same issue as #86379. Are you able to try building your project with the latest nightly 8.0 SDK available at https://github.com/dotnet/installer/? We are also planning to backport the fix into an upcoming 7.0 servicing release.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 7, 2023
@sbomer sbomer transferred this issue from dotnet/sdk Jun 7, 2023
@vitek-karas vitek-karas added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jun 7, 2023
@ghost
Copy link

ghost commented Jun 7, 2023

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

Issue Details

I have a sln which contains several class libraries and one executable cmdline csproj. I'm modernizing whole solution, removing mono/net461 executable, upgrading class libraries from netstandard20 to net7.
When publishing my app with parameters:

dotnet publish my.csproj -r linux-arm -p:PublishTrimmed=True -p:TrimMode=partial --self-contained true -c Release -f net7.0

and one specific csproj of my class libraries is set to net7.0 build freezes. on line
C:\Program Files\dotnet\dotnet.exe exec "C:\Program Files\dotnet\sdk\7.0.101\Roslyn\bincore\csc.dll" ...
Freezing means than NET host process takes almost all cpu, a several Gigs of RAM.

To "unfreeze" build I have to:

  • remove trimming ( -p:PublishTrimmed=True -p:TrimMode=partial ) - without trimming build is completed in 20sec
  • set this one library to netstandard20 and build with net7 SDK
  • set all csproj files in solution to net6 and build in net6 SDK - net6 build completes in about a minute without problems

Building it on Windows 10,11 and in linux docker.

What I've tried and didn't help:

  • build with MS net7 SDK docker
  • build for different runtimes - linux-x64, win-x64, linux-arm...
  • SDK 7.0.100 and 7.0.101

Unfortunately project is closed source. But I can run some test, access my desktop remotely or something like that.

Author: michaldobrodenka
Assignees: -
Labels:

untriaged, area-Tools-ILLink, needs-area-label

Milestone: -

@vitek-karas vitek-karas removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 7, 2023
@vitek-karas vitek-karas added this to the 7.0.x milestone Jun 7, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 7, 2023
@michaldobrodenka
Copy link
Author

@sbomer I've tried to build it with latest nighly, but seems that I can't get versions or something right:
image

Maybe I'll wait for next official net8 Preview/net7 and retest it.

@michaldobrodenka
Copy link
Author

 Version:   8.0.100-preview.6.23307.25
 Commit:    f98e016a22

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-preview.6.23307.25\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-preview.6.23307.4
  Architecture: x64
  Commit:       54dab738de

.NET SDKs installed:
  2.1.800 [C:\Program Files\dotnet\sdk]
  6.0.402 [C:\Program Files\dotnet\sdk]
  7.0.200 [C:\Program Files\dotnet\sdk]
  7.0.400-preview.23225.8 [C:\Program Files\dotnet\sdk]
  8.0.100-preview.6.23307.25 [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 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-preview.6.23307.4 [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 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-preview.6.23307.4 [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 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0-preview.6.23307.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

@michaldobrodenka
Copy link
Author

michaldobrodenka commented Jun 8, 2023

Ok, after clearing nuget local cache, I'm able to start build, still freezes, but there is a problem with ILLink task version

image

warning NU1603: TapHome.Core.Translations depends on Microsoft.NET.ILLink.Tasks (>= 7.0.100-1.23211.1) but Microsoft.NET.ILLink.Tasks 7.0.100-1.23211.1 was no t found. An approximate best match of Microsoft.NET.ILLink.Tasks 8.0.0-preview.2.23128.3 was resolved.

Maybe I should add ILLink task nuget?

@sbomer
Copy link
Member

sbomer commented Jun 8, 2023

@michaldobrodenka thanks for giving it a try. For the nightly SDKs you'll need to add nuget feeds mentioned under https://github.com/dotnet/installer#installers-and-binaries. For projects using the illink analyzer targeting net7.0 you will need the dotnet7 feed specifically.

@michaldobrodenka
Copy link
Author

I tried targeting net8 & latest net8 nightly (Preview6), build is still freezing. I'll retest it within a few weeks

@sbomer
Copy link
Member

sbomer commented Jun 9, 2023

@michaldobrodenka sorry, I forgot to mention that your project needs to target net8.0 to get the analyzer fix, at least until we make the servicing fix (dotnet/linker#3217). And note that you should be able to work around this by setting <EnableTrimAnalyzer>false</EnableTrimAnalyzer>. Then you won't see trim compatibility warnings at build time, but you can instead rely on the warnings produced when publishing.

@michaldobrodenka
Copy link
Author

7.0.9 - still freezes
<EnableTrimAnalyzer>false</EnableTrimAnalyzer> - to one of the libraries and it builds ok!

@sbomer
Copy link
Member

sbomer commented Jul 13, 2023

Thanks for checking! Looks like the servicing fix should ship with 7.0.10.

@agocke
Copy link
Member

agocke commented Aug 9, 2023

This should be fixed. Newly discovered problems are likely new issues.

@agocke agocke closed this as completed Aug 9, 2023
@michaldobrodenka
Copy link
Author

This should be fixed. Newly discovered problems are likely new issues.

Is the fix merged in 7.0.10? Because I tried it and build still hangs without <EnableTrimAnalyzer>false</EnableTrimAnalyzer> in one of the libraries

.NET SDK:
 Version:   7.0.400
 Commit:    73bf45718d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.400\

Host:
  Version:      7.0.10
  Architecture: x64
  Commit:       a6dbb800a4

.NET SDKs installed:
  6.0.400 [C:\Program Files\dotnet\sdk]
  7.0.400-preview.23330.10 [C:\Program Files\dotnet\sdk]
  7.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

@sbomer
Copy link
Member

sbomer commented Aug 10, 2023

@michaldobrodenka thank you for following up. I confirmed that the fix shipped in the 7.0.10 servicing release (7.0.400 SDK), so this sounds like a different bug. Is there any way you could provide us with a repro, perhaps a simplified bit of code from the library that exhibits the hang?

If you're unable to share due to the license, please contact me at svbomer at microsoft.com to discuss.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Projects
Archived in project
Development

No branches or pull requests

6 participants