Skip to content

Conversation

@corngood
Copy link
Contributor

FileInfo.Length will return the size of a symlink, rather than the file itself. On a source-built dotnet SDK, a trivial test project will bundle files like:

packs/Microsoft.NETCore.App.Runtime.linux-x64/10.0.0-preview.7.25380.108/runtimes/linux-x64/lib/net10.0/Microsoft.CSharp.dll

Which is a symlink to:

../../../../../../../shared/Microsoft.NETCore.App/10.0.0-preview.7.25380.108/Microsoft.CSharp.dll

This can result in:

[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [/build/test/test.fsproj]
[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: System.NotSupportedException: Unable to expand length of this stream beyond its capacity. [/build/test/test.fsproj]
[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at System.IO.UnmanagedMemoryStream.WriteCore(ReadOnlySpan1 buffer) [/build/test/test.fsproj] [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize) [/build/test/test.fsproj] [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.AddToBundle(Stream bundle, FileStream file, FileType type) [/build/test/test.fsproj] [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList1 fileSpecs) [/build/test/test.fsproj]
[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() [/build/test/test.fsproj]
[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/build/test/test.fsproj]
[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/build/test/test.fsproj]
[...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMo

Fixes: b79c4fb

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 14, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 14, 2025
@vcsjones vcsjones added area-HostModel Microsoft.NET.HostModel issues and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 15, 2025
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also use this helper here

long appHostSourceLength = new FileInfo(appHostSourceFilePath).Length;

and here
var hostLength = new FileInfo(hostSource).Length;

@corngood
Copy link
Contributor Author

Could we also use this helper here

I moved it to HostModelUtils. I believe everything existing in there is actually unused, but it seems like the best spot in the project. Let me know if you have a better idea.

@corngood corngood force-pushed the bundler-fix branch 2 times, most recently from 1e5ebea to 3ccfafa Compare August 18, 2025 23:45
@corngood
Copy link
Contributor Author

corngood commented Aug 18, 2025

##[error].dotnet/sdk/10.0.100-rc.1.25411.109/Microsoft.Common.CurrentVersion.targets(2437,5): error MSB3106: (NETCORE_ENGINEERING_TELEMETRY=Build) Assembly strong name "/__w/1/s/.packages/microsoft.io.redist/6.1.3/lib/net462/Microsoft.IO.Redist.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).

I switched the reference to net472, since that's all that's available even in the oldest versions on nuget.org. Based on some other dependencies I think that's probably okay, but I'm not sure.

@corngood corngood force-pushed the bundler-fix branch 4 times, most recently from 8a2dff8 to 4f71141 Compare August 19, 2025 02:57
@corngood corngood force-pushed the bundler-fix branch 2 times, most recently from be693dc to 7a503a7 Compare August 19, 2025 12:41
@jkotas
Copy link
Member

jkotas commented Aug 19, 2025

@corngood To fix the build breaks, try changing Microsoft.IO.Redist version to 6.0.1

FileInfo.Length will return the size of a symlink, rather than the file
itself. On a source-built dotnet SDK, a trivial test project will bundle
files like:

packs/Microsoft.NETCore.App.Runtime.linux-x64/10.0.0-preview.7.25380.108/runtimes/linux-x64/lib/net10.0/Microsoft.CSharp.dll

Which is a symlink to:

../../../../../../../shared/Microsoft.NETCore.App/10.0.0-preview.7.25380.108/Microsoft.CSharp.dll

This can result in:

> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018: System.NotSupportedException: Unable to expand length of this stream beyond its capacity. [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at System.IO.UnmanagedMemoryStream.WriteCore(ReadOnlySpan`1 buffer) [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize) [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at Microsoft.NET.HostModel.Bundle.Bundler.AddToBundle(Stream bundle, FileStream file, FileType type) [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/build/test/test.fsproj]
> [...]/Microsoft.NET.Publish.targets(1132,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMo

Fixes: b79c4fb
Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jtschuster jtschuster enabled auto-merge (squash) September 3, 2025 23:15
@jtschuster jtschuster merged commit 30700fb into dotnet:main Sep 4, 2025
158 of 160 checks passed
@elinor-fung
Copy link
Member

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17501524581

@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-HostModel Microsoft.NET.HostModel issues community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants