14

** This is an issue in Visual Studio 2013.

The error I'm getting is massive and mostly useless, but the crux of it is

Error   130 Fody: Could not load 'ModuleWeaver' from 'PropertyChanged.Fody, Version=1.50.3.0, Culture=neutral, PublicKeyToken=null' due to ReflectionTypeLoadException.
It is possible you need to update the package.
exception.LoaderExceptions:
System.IO.FileLoadException: Could not load file or assembly 'Mono.Cecil,     Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its     dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'

Again since there have been no changes, I have no idea what it's problem is in general. The DLL it is looking for is sitting in the same place it has always been sitting.

Edit: apparently at this point it got tired of spitting out that error so it fabricated a new one

Error   42  The "Fody.WeavingTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Cecil, Version=0.9.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
File name: 'Mono.Cecil, Version=0.9.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
   at ExceptionExtensions.LogException(ILogger logger, Exception exception)
   at Processor.Execute() in c:\TeamCity\buildAgent\work\7495521761d392b9\Fody\Processor.cs:line 56
   at Fody.WeavingTask.Execute() in c:\TeamCity\buildAgent\work\7495521761d392b9\Fody\WeavingTask.cs:line 44
   at     Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()

Edit 2:

Also, the error is allegedly taking place inside "Fody.targets" on line 50 which is

<Fody.WeavingTask
      AssemblyPath="@(IntermediateAssembly)"
      IntermediateDir="$(IntermediateDir)"
      KeyFilePath="$(FodyKeyFilePath)"
      ProjectDirectory="$(ProjectDir)"
      SolutionDir="$(FodySolutionDir)"
      References="@(ReferencePath)"
      SignAssembly="$(FodySignAssembly)"
      ReferenceCopyLocalPaths="@(ReferenceCopyLocalPaths)"
      DefineConstants="$(DefineConstants)"
  />

Edit 3:

I deleted all the files associated with Fody and Nuget redownloaded them during the build process. The error after that is the same as the 2nd error:

"Error   42  The "Fody.WeavingTask" task failed unexpectedly." 

Edit 4:

I really hope the dev of Fody sees this because we're at an absolute standstill until this is fixed. We can't "revert" back to when it was working because the current configuration IS when it was working.

Justin
  • 513
  • 1
  • 7
  • 17
  • could you check the version of Mono.Cecil.dll, right click in explorer, and go through the properties, you will find the version number. Check that it's 0.9.6.0, if not you may need a redirect. – Jim Oct 01 '15 at 18:02
  • It is pointing to the correct version. 0.9.6.0. – Justin Oct 01 '15 at 18:02
  • I found i got the "Mono.Cecil" issue you mentioned above if one of my projects in the solution referenced an older version of Fody and another project referenced a newer Fody that depended on a different version of Mono.Cecil. I cleared this up by updating all projects that use Fody to the latest from nuget and my build issues cleared up. – Chris Johnson Jan 06 '18 at 01:24
  • +1 for pointing out that Fody error messages contain no useful information. I have an inherited project that throws Fody compiler errors. There's no indication at all of which file is the problem. – user2023861 Mar 20 '18 at 19:30
  • raise an issue here and ensure you follow all the steps in the template https://github.com/Fody/Fody/issues/new?assignees=&labels=&template=bug_report.md – Simon Feb 04 '21 at 00:29

6 Answers6

16

It would seem that your error is actually in finding a class called ModuleWeaver. This class is part of the Fody package.

Just updating the package in nuget package manager with:

   update-package Fody -reinstall

Will probably fix it.

Failing that: make sure that your app.config file does not have incorrect redirects. Remove this section, remove all the redirects. Visual studio will typically add the necessary ones back.

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>

Try again, if that fails, try to find which dependent assembly is failing. You can write a one line command line app, or use LinqPad.

You can try LinqPad, if you don't use it already, paste this.

Assembly.LoadFile("path to Fody");
Assembly.LoadFile("path to Mono.Cecil");

You should get an exception detailing the missing library.

Jim
  • 11,197
  • 11
  • 66
  • 151
  • I've unfortunately now tried all this and when loading the assemblies in LinqPad I'm getting no output at all (so I'm assuming LinqPad is at least loading the assemblies properly). Mind you, now the error has changed to being unable to find "FodyIsolated" – Justin Oct 02 '15 at 13:26
  • Without more context it's going to be tricky. Your error does seem to be in getting mono.cecil loaded if it's loading correctly in linqpad from the same directory then the problem is possibly deeper. If you are using version control, I would try checking out to a clean directory and trying again. There's an assembly mismatch somewhere. We've all been there I will be keen to know what the resolution is. I will try and provide some more advice if I can think of something else to try. – Jim Oct 02 '15 at 16:32
  • Unfortunately trying previous builds hasn't helped. I may try it from a clean directory later. Like you say, something has gotten really out of sync, or mismatched, on my Windows install/VS install. I'm presently "Repairing" my VS install, and might attempt to restore Windows to a day or two ago, to see if that puts the assemblies back the way they should be. I'll be sure to post what the solution is. Thanks for your help in the meantime. – Justin Oct 02 '15 at 16:36
3

If you are using git, running this from the command line:

git clean -xdf
Paul Kiar
  • 176
  • 2
  • 3
  • After this, I did a "Clean solution" and "Rebuild solution" and then my project could compile and run. – rolandow Jul 23 '19 at 12:11
2

After trying all solutions I could find on the internet, the following worked for me:

  1. Close Visual Studio.
  2. Delete the Debug and Release folders in your PCL project and your {platform} project. For me these were located in something like MyPCLProjectName\bin\ and iOS\bin\iPhoneSimulator\.
  3. Edit your PCL and {platform} .csproj file and remove all <Import> tags, except for the one that starts <Import Project="$(MSBuildExtensionsPath32)\...
  4. Reopen Visual Studio.
  5. Restore the packages (this step may be done automatically when you reopen Visual Studio) - Solution Explorer > right-click solution > Restore NuGet Packages.
jbyrd
  • 4,357
  • 7
  • 39
  • 75
1

To debug such issues, you can use SysInternals Process Monitor.

The general approach is:

  1. run Process Monitor
  2. apply a filter to monitor you application only
  3. reproduce the issue
  4. look for missing DLLs. This part is a bit tricky, since

    1. a DLL might not be found several time ("Path not found")
    2. but finally be found ("Success")
    3. it might not be the DLL you're looking for but a dependency of that DLL

    So you need to find a DLL which was never found. And you don't want DLLs that were not found but then found in a subsequent attempt.

Well, that process can be quite time consuming, so I developed the tool Process Monitor Log Analyzer. With it, you should be able to find the culprit in less time.

  1. run Process Monitor
  2. apply a filter to monitor your application only
  3. reproduce the issue
  4. save the result as XML (keep all items, "Path not found" and "Success")
  5. open the XML in Log Analyzer
  6. from top to bottom, check the presence of DLLs. The tool will only show DLLs that are never found.

Disclaimer: I am the author of that free tool, if that didn't become clear from the text.

Thomas Weller
  • 43,638
  • 16
  • 101
  • 185
  • Thanks for the reply. I'm just a little confused what you mean exactly by monitoring my application. Are you referring to my compiler? (VS 2013). I can't compile my application at all anymore because of Fody. – Justin Oct 01 '15 at 20:12
  • @Justin. Yes, if it is VS2013 that cannot find the DLL, monitor VS2013 (devenv.exe). However, VS 2013 may use a separate exe as the compiler, then monitor that one. If you don't know, just monitor everything and filter later. – Thomas Weller Oct 01 '15 at 20:18
  • Alright I'll have to give that a shot tomorrow as I'm leaving work shortly. Thanks again. – Justin Oct 01 '15 at 20:48
  • Just so I'm clear, once I import the XML into your tool, I get a very large list of different things. Some of them are definitely referring to DLL's, but many are referring to exe's, '.cdf-ms' etc. But I'm looking for things that say 'Path not found', is that right? There are a few things referencing DLL's that also say "Name not found". – Justin Oct 02 '15 at 13:08
  • "Name not found" is also possible. The tool only lists potential candidates for missing DLLs. However, sometimes an application may gracefully degrade and a DLL might actually not be needed. – Thomas Weller Oct 02 '15 at 22:00
1

Some of you getting similar errors might benefit from this info, which states that projects with different Fody versions cannot use the same NuGet packages folder (if I understood correctly): Installing multiple versions of PropertyChanged breaks compilation

Reinstalling the Fody package in all projects also resolves the issue, but changing all to the same version might be easier.

wezzix
  • 1,444
  • 1
  • 13
  • 15
0

I had a project that encountered this: my machine had Visual Studio 2017 installed, but I had recently also installed the Build Tools for Visual Studio 2019 as well for an unrelated project. It looks like something became confused as to which build tools to use, since uninstalling the 2019 ones resolved this for me.

vee
  • 1,197
  • 14
  • 17