ab_732
ab_732

Reputation: 3897

MSBuild hangs forever when Fody writes assembly

In my solution many project make use of Fody to inject the PropertyChanged weaver. Unfortunately at the end of the build, when Fody starts writing the final assembly, the process hangs and cannot be recovered.

This is the MSBuild command I am executing:

set msbuildemitsolution=1
msbuild MyCompany.App.sln /t:Build /fl /flp:logfile=buildoutput.txt;verbosity=diagnostic /p:Configuration=Debug /p:Platform="Any CPU" /p:UseSharedCompilation=false

This is the log of the build:

AfterCompile:
   Beginning transformation.   
   Transformation succeeded 
FodyTarget:
    Fody: Fody (version 3.0.3.0) Executing
    Fody: ProjectDirectory: 'C:\Dev\Client\MyCompany.App.Client.Shell\'.
    Fody: AssemblyPath: 'C:\Dev\Client\MyCompany.App.Client.Shell\obj\Debug\MyCompany.App.Client.Shell.exe'
    Fody: Found path to weavers file 'C:\Dev\Client\MyCompany.App.Client.Shell\FodyWeavers.xml'.
    Fody: SolutionDirectory path is 'C:\Dev\'
    Fody: Finding weavers
    Fody: FindAddinDirectories:
    Fody:   No PackageDefinitions
    Fody:   Scanning SolutionDir/Packages convention: C:\Dev\packages'.
    Fody:     Fody weaver file added 'C:\Dev\packages\PropertyChanged.Fody.2.5.4\netclassicweaver\PropertyChanged.Fody.dll'
    Fody:   Skipped directory from Nuget Config since it could not be derived.
    Fody:   Scanning the MsBuildThisFileDirectory parent: C:\Dev\'.
    Fody:   Skipped scanning 'C:\Dev\Tools' since it doesn't exist.
    Fody:   Skipped NuGetPackageRoot since it is not defined.
    Fody: No Weaver project file found.
    Fody: Finished finding weavers 25ms
    Fody: Creating a new AssemblyLoadContext
    Fody: Reference count=209
    Fody: References:   *follows long list of references...*
    Fody: Found debug symbols at 'C:\Dev\Client\MyCompany.App.Client.Shell\obj\Debug\MyCompany.App.Client.Shell.pdb'.
    Fody: Weaver 'C:\Dev\packages\PropertyChanged.Fody.2.5.4\netclassicweaver\PropertyChanged.Fody.dll'.
    Fody:   Initializing weaver
    Fody:   Loading 'C:\Dev\packages\PropertyChanged.Fody.2.5.4\netclassicweaver\PropertyChanged.Fody.dll' from disk.
    Fody: Can't find 'FSharp.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
    Fody: Can't find 'System.Diagnostics.Tracing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
    Fody: Can't find 'System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    Fody: Can't find 'System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    Fody: Can't find 'System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    Fody: Can't find 'System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
      Fody/PropertyChanged:   Executing Weaver
      Fody/PropertyChanged:     MyCompany.App.Client.Shell.ViewModels.SplashScreenViewModel
      Fody/PropertyChanged:             Model
      Fody/PropertyChanged:                     Model skipped since call already exists
      Fody/PropertyChanged:     MyCompany.App.Client.Shell.Model.ShellWindowModel
      Fody/PropertyChanged:             ProgramProvider
      Fody/PropertyChanged:                     ProgramProvider
      Fody/PropertyChanged:             UiEnabledContext
      Fody/PropertyChanged:                     UiEnabledContext
      Fody/PropertyChanged:             SizingContext
      Fody/PropertyChanged:                     SizingContext
      Fody/PropertyChanged:             ProgramHeaderRegionVisibility
      Fody/PropertyChanged:                     ProgramHeaderRegionVisibility
      Fody/PropertyChanged:             EnvironmentVersion
      Fody/PropertyChanged:                     EnvironmentVersion
      Fody/PropertyChanged:             EnvironmentVersionFontFamily
      Fody/PropertyChanged:                     EnvironmentVersionFontFamily
      Fody/PropertyChanged:             EnvironmentVersionFontColor
      Fody/PropertyChanged:                     EnvironmentVersionFontColor
      Fody/PropertyChanged:             EnvironmentVersionFontSize
      Fody/PropertyChanged:                     EnvironmentVersionFontSize
      Fody/PropertyChanged:             Title
      Fody/PropertyChanged:                     Title
      Fody/PropertyChanged:             RibbonSelectedIndex
      Fody/PropertyChanged:                     RibbonSelectedIndex
      Fody/PropertyChanged:             IsBusy
      Fody/PropertyChanged:                     IsBusy
      Fody/PropertyChanged:             IsTaskButtonsBusy
      Fody/PropertyChanged:                     IsTaskButtonsBusy
      Fody/PropertyChanged:             ShellContext
      Fody/PropertyChanged:                     ShellContext
      Fody/PropertyChanged:             ConsoleEditingContext
      Fody/PropertyChanged:                     ConsoleEditingContext
      Fody/PropertyChanged:             Icon
      Fody/PropertyChanged:                     Icon
      Fody/PropertyChanged:             IsOptionNavigationEnabled
      Fody/PropertyChanged:                     IsOptionNavigationEnabled
      Fody/PropertyChanged:     MyCompany.App.Client.Shell.Model.SplashScreenModel
      Fody/PropertyChanged:             LoadingMessages
      Fody/PropertyChanged:                     LoadingMessages
      Fody/PropertyChanged:             SelectedMessageIndex
      Fody/PropertyChanged:                     SelectedMessageIndex
      Fody/PropertyChanged:             NameVersion
      Fody/PropertyChanged:                     NameVersion
      Fody/PropertyChanged:             Environment
      Fody/PropertyChanged:                     Environment
      Fody/PropertyChanged:             EnvironmentColor
      Fody/PropertyChanged:                     EnvironmentColor
      Fody/PropertyChanged:     MyCompany.App.Client.Shell.ViewModels.ShellWindowViewModel
      Fody/PropertyChanged:             Model
      Fody/PropertyChanged:                     Model
      Fody/PropertyChanged:     MyCompany.App.Client.Shell.Model.ShellContext
      Fody/PropertyChanged:             IsInConsoleMode
      Fody/PropertyChanged:                     IsInConsoleMode
      Fody/PropertyChanged:   Finished 'PropertyChanged' in 162ms
      Fody/PropertyChanged:     Removing reference to 'PropertyChanged'.
    Fody:   Adding weaving info
    Fody:   Finished in 5ms
    Fody:   Writing assembly to 'C:\Dev\Client\MyCompany.App.Client.Shell\obj\Debug\MyCompany.App.Client.Shell.exe'.

It would hangs forever in this state, if I try to cancel the build with CTRL-C I get this message:

Attempting to cancel the build... 
warning MSB4220: Waiting for the currently executing task "Fody.WeavingTask" to cancel.

The process will keep trying to cancel the build every 10 secs or so, unsuccessfully. The MSBuild task becomes unkillable and I need to restart my machine in order to try kicking another build!

The project makes use of the following:

The msbuild version I am using is 16.4.0.56107

I tried to update to the latest Fody version, that did not help.

I know this might be a long shot; if anyone has any tip/idea on how to investigate this, please share it. Thank you.

-- EDIT -- If I remove PropertyChanged and Fody from the failing project then the Solution can complete the build. What can possibly cause Fody to hang?

Upvotes: 4

Views: 564

Answers (2)

tom-englert
tom-englert

Reputation: 261

It's very likely that using the latest compilers with a totally outdated version of Fody causes this - Fody (via Mono.Cecil) probably just can't cope with the generated IL.

Upvotes: 0

ab_732
ab_732

Reputation: 3897

Unfortunately I haven't been able to isolate the issue; considering that Fody wasn't working only on one of our projects, I ended up replacing Fody and PropertyChanged with the .Net implementation provided by the BindableBase class

    private string title;
    public string Title 
    { 
        get => title;
        set => SetProperty(ref title, value);
    }

Not sure if this can help, however we noticed that some interference can come from file without extension in the root of the hard drive. Look from something like c:\Progra~1 or c:\Program and rename it or remove it

Upvotes: 0

Related Questions