Fody/PropertyChanged

Fody loads different version of PropertyChanged.Fody

Closed this issue · 5 comments

Describe the bug

I have different solutions that have Fody and PropertyChanged.Fody one using Fody 3.0.3 with PropertyChanged.Fody 2.5.6 and the other with Fody 3.2.4 with PropertyChanged.Fody 2.5.11

The issue I'm seeing is that Fody tries always to load the last version of PropertyChanged.Fody instead of the one set on the project so in the project that has Fody 3.0.3 with PropertyChanged.Fody 2.5.6 throws the next error when compiling:

Error: Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver /Users/user/.nuget/packages/propertychanged.fody/2.5.11/netclassicweaver/PropertyChanged.Fody.dll
Type:
System.Exception
StackTrace:
  at InnerWeaver.ExecuteWeavers () [0x0007a] in C:\projects\fody\FodyIsolated\InnerWeaver.cs:208 
  at InnerWeaver.Execute () [0x0004d] in C:\projects\fody\FodyIsolated\InnerWeaver.cs:103 
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Could not resolve type with token 01000041 (from typeref, class/assembly Fody.TypeSystem, FodyHelpers, Version=3.2.3.0, Culture=neutral, PublicKeyToken=1ca091877d12ca03)
Type:
System.TypeLoadException
StackTrace:
  at ModuleWeaver.WeaveEvent (Mono.Cecil.TypeDefinition type) [0x00029] in C:\projects\propertychanged\PropertyChanged.Fody\InterfaceInjector.cs:19 
  at ModuleWeaver.InjectINotifyPropertyChangedInterface (Mono.Cecil.TypeDefinition targetType) [0x00016] in C:\projects\propertychanged\PropertyChanged.Fody\InterfaceInjector.cs:10 
  at ModuleWeaver.PopulateInjectedINotifyNodes (System.Collections.Generic.List`1[T] typeNodes) [0x00081] in C:\projects\propertychanged\PropertyChanged.Fody\TypeNodeBuilder.cs:68 
  at ModuleWeaver.BuildTypeNodes () [0x000c4] in C:\projects\propertychanged\PropertyChanged.Fody\TypeNodeBuilder.cs:38 
  at ModuleWeaver.Execute () [0x00030] in C:\projects\propertychanged\PropertyChanged.Fody\ModuleWeaver.cs:15 
  at InnerWeaver.ExecuteWeavers () [0x0006b] in C:\projects\fody\FodyIsolated\InnerWeaver.cs:204 
Source:
PropertyChanged.Fody
TargetSite:
Void WeaveEvent(Mono.Cecil.TypeDefinition)
 (DGenix.Mobile.Fwk.Core)

Which IMO is trying to load PropertyChanged 2.5.11 instead of PropertyChanged 2.5.6.

Minimal Repro

In order to reproduce it create a project that has Fody 3.0.3 and PropertyChanged 2.5.6and another project with Fody 3.2.4 and PropertyChanged 2.5.11. Restore nuget packages on both projects and then try to compile the project with Fody 3.0.3.

I haven't submitted a repo yet but I can do that if necessary.

Submit a PR that fixes the bug

Expected behavior

Fody should load the specified version of PropertyChanged.Fody set in the project.

Additional context

I'm using Visual Studio for Mac and IDK how to test if the issue is still present on the last version because of the issue itself, i.e. on the project where I have Fody 3.2.4 I have PropertyChanged.Fody 2.5.11 so when it gets the last PropertyChanged.Fody it is the version 2.5.11 so it works fine IMO but I'm now sure if it is because it is corrected of because of the version that tries to load.

Workaround

I've found that in order to workaround this situation I have to go to /Users/user/.nuget/packages and delete the Fody and PropertyChanged.Fody folders. Afterwards I restore the Nuget packages of my solution, rebuild and it works. Another way is to leave just one version in each folder, e.g. Fody/3.0.3and PropertyChanged/2.5.6 and then rebuild.

are you mixing the old .csproj format with new <PackageReference> nodes.

https://github.com/Fody/Fody#project-formats

No, in all the projects I'm using Net Standard, i.e. the .csproj starts with <Project Sdk="Microsoft.NET.Sdk"> and therefore they are using <PackageReference> nodes.

However, I'm currently mixing the .csproj format with <PackageReference> nodes but only in Xamarin.Android and Xamarin.iOS projects but I don´t have Fody added in these projects. IDK If this alter in some way to Fody.

i suspect this breaking change in MSbuild caused it dotnet/sdk#2342 can u try https://www.nuget.org/packages/Fody/3.2.5-beta.1

can u update to the newest fody and PropertyChanged

i suspect this breaking change in MSbuild caused it dotnet/sdk#2342 can u try https://www.nuget.org/packages/Fody/3.2.5-beta.1

This worked for me. Thanks !!!