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

Fail to build a WPF app with PublishTrimmed = true #674

Closed
Symbai opened this issue Jul 25, 2019 · 9 comments
Closed

Fail to build a WPF app with PublishTrimmed = true #674

Symbai opened this issue Jul 25, 2019 · 9 comments

Comments

@Symbai
Copy link

Symbai commented Jul 25, 2019

I'm using a daily SDK downloaded yesterday with version 3.0.0-preview8-27919-09. Using dotnet publish to build a WPF app with PublishTrimmed = true fails

dotnet publish -c Release -v q --self-contained -r win-x64 -f netcoreapp3.0

with exception

 error MSB4018: Unexpected error with ComputeManagedAssemblies Task.
 error MSB4018: System.ArgumentOutOfRangeException: Non- negative number required. (Parameter 'count')
 error MSB4018: at System.IO.BinaryReader .ReadBytes (Int32 count)
 error MSB4018: at Mono.Cecil.PE .ImageReader.ReadDebugHeader ()
 error MSB4018: at Mono.Cecil.PE .ImageReader.ReadImage ()
 error MSB4018: at Mono.Cecil.PE .ImageReader.ReadImage (Disposable`1 stream, String file_name)
 error MSB4018: at Mono.Cecil.ModuleDefinition .ReadModule (Disposable`1 stream, String fileName, ReaderParameters parameters)
 error MSB4018: at Mono.Cecil.ModuleDefinition .ReadModule (String fileName, ReaderParameters parameters)
 error MSB4018: at Mono.Cecil.ModuleDefinition .ReadModule (String fileName)
 error MSB4018: at Utils.IsManagedAssembly (String filename)
 error MSB4018: at ILLink.Tasks.ComputeManagedAssemblies <> c. <Execute> b__8_0 (ITaskItem f)
 error MSB4018: at System.Linq.Enumerable .WhereArrayIterator`1.ToArray ()
 error MSB4018: at System.Linq.Enumerable .ToArray [TSource] (IEnumerable`1 source)
 error MSB4018: at ILLink.Tasks.ComputeManagedAssemblies .Execute ()
 error MSB4018: at Microsoft.Build.BackEnd .TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute ()

dotnet --info

 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview8-013401\

Host (useful for support):
  Version: 3.0.0-preview8-27919-09
  Commit:  3fcf1dac55

.NET Core SDKs installed:
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.701 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
  2.1.800 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]
  3.0.100-preview8-013401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview8.19372.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview6-27717-02 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview7-27912-14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview8-27919-09 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview8-27919-09 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
@sbomer
Copy link
Member

sbomer commented Jul 26, 2019

@Symbai are you able to share a repro?

@Symbai
Copy link
Author

Symbai commented Jul 26, 2019

@sbomer Yes, it only happens when referencing third party controls. I'm using VS Preview 16.3.0

WpfApp6.zip

@sbomer
Copy link
Member

sbomer commented Jul 29, 2019

Cecil is tripping over an obfuscated PE file that has an invalid debug directory:

> dumpbin /headers Controls\ActiproSoftware.Grids.Wpf.dll
...
  Debug Directories

        Time Type        Size      RVA  Pointer
    -------- ------- -------- -------- --------
    00000000 cv            66 0005B0AC    592AC    Format: RSDS, {2B1D6821-7665-410F-B02C-BEA7AC54E2AC}, 1, S:\Agent\_work\21\s\Source\bin\Obfuscated\net40\ActiproSoftware.Grids.Wpf.pdb
    2B1D6821 (A7BE2CB0)  ACE254AC 00000001 415C3A53ActiproSoftware.Grids.Wpf.dll : fatal error LNK1106: invalid file or disk full: cannot seek to 0x415C3A53

@Symbai
Copy link
Author

Symbai commented Jul 29, 2019

Is there a way to exclude it from trimming?

@sbomer
Copy link
Member

sbomer commented Jul 29, 2019

@Symbai as a workaround you can do the following (we will make this easier in the future):

  <Target Name="ExcludeAssembliesFromLinking"
          BeforeTargets="_ComputeManagedAssembliesToLink">
    <ItemGroup>
      <_RemovedPublishFiles Include="@(ResolvedFileToPublish)" Condition="'%(Filename)' == 'ActiproSoftware.Grids.Wpf'" />
      <ResolvedFileToPublish Remove="@(_RemovedPublishFiles)" />
    </ItemGroup>
  </Target>

  <Target Name="IncludeUnlinkedAssemblies"
          AfterTargets="ILLink">
    <ItemGroup>
      <ResolvedFileToPublish Include="@(_RemovedPublishFiles)" />
    </ItemGroup>
  </Target>

With this you will hit an issue with R2R, because the skipped assembly references mscorlib which is removed by the linker. To fix this, do:

<ItemGroup>
  <TrimmerRootAssembly Include="mscorlib" />
</ItemGroup>

That gets around the issues. You'll also need to add a similar root for System.Diagnostics.Debug until dotnet/wpf#1385 is fixed.

@Symbai
Copy link
Author

Symbai commented Jul 30, 2019

@sbomer Ok thank you, I'll go with it. I also think that making it easier is a great idea because its a third party control I have no control over the obfuscation. Something like this may happen quite often for other developers as well.

I think this can be closed or should I leave this open?

@Symbai Symbai closed this as completed Jul 31, 2019
@gojanpaolo
Copy link

gojanpaolo commented Oct 30, 2019

We're also running into this issue.

C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018: The "ComputeManagedAssemblies" task failed unexpectedly. [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018: System.IO.FileLoadException: Could not load file or assembly 'Mono.Cecil, Version=0.11.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e'. Could not find or load a specific file. (0x80131621) [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018: File name: 'Mono.Cecil, Version=0.11.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e' [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Utils.IsManagedAssembly(String fileName) [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at ILLink.Tasks.ComputeManagedAssemblies.<>c.<Execute>b__8_0(ITaskItem f) [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.Linq.Enumerable.WhereArrayIterator`1.ToArray() [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at ILLink.Tasks.ComputeManagedAssemblies.Execute() [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:  [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]
C:\Program Files\dotnet\sdk\3.1.100-preview1-014459\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(136,5): error MSB4018:  [C:\git\PostDredge\src\Gldd.PostDredge\Gldd.PostDredge.csproj]

It looks like it's because of the following reference:

<PackageReference Include="PropertyChanged.Fody" Version="2.6.0"/>

I tried the workaround posted above, changing the ActiproSoftware.Grids.Wpf to PropertyChanged.Fody but it still doesn't work.

also I'm using dotnet Gldd.PostDredge.csproj publish -r win-x64 /p:PublishTrimmed=true

@sbomer
Copy link
Member

sbomer commented Nov 1, 2019

@gojanpaolo that looks like a separate issue - would you be able to file a new issue for this?

@Skleni
Copy link

Skleni commented Dec 3, 2019

I just had the same error message as @gojanpaolo when using Fody. I couldn't find another issue so I'm posting this here in case someone has the same problem. Updating Fody to at least 6.0.4 as described
here solved it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants