Fody/PropertyChanged

PropertyChanged.Fody missing when deploying WPF .net core 3.1 app

Closed this issue · 7 comments

Hi. Currently working on desktop application build with WPF using .net core 3.1. The application works great so far. Right now I'm in need to deploy the current version so the client is asking for .exe or .msi file in order to test it. I wanted something fast so I'm using Advanced Installer Architect 16.8.

Anyway, I won't go into details, basically, you switch from Debug to Release mode in Visual Studio 2019, and then use bin/Release file content where main .exe file and dependencies live. I don't see PropertiesChanged.Fody package there, even though I'm using it as the nuget package.

After running the installer and starting the app from a desktop, nothing happens because the app crashes silently. Upon verifying error in Event Viewer this is the output:

Description: A .NET Core application failed.
Application: Main.exe
Path: C:\Program Files (x86)\CompanyName\ProjectName\Main.exe
Message: Error:
An assembly specified in the application dependencies manifest (Main.deps.json) was not found:
package: 'PropertyChanged.Fody', version: '3.2.4'
path: 'lib/netstandard1.0/PropertyChanged.dll'

What I tried so far:

  • I added PropertyChanged.Fody manually as "Add Reference" option and I can confirm that dll was inside bin/Debug after rebuild, then recreated installer and got the same error once deployed
  • I added CopyLocalLockFileAssemblies "true" CopyLocalLockFileAssemblies to the csproj file, still no change
  • I added PrivateAssets="All" to the PackageReference Include="PropertyChanged.Fody" Version="3.2.4" to the csproj file but, still no change

I need to finish this ASAP so any help would be appreciated. Thanks

Hi, if I understand correctly, you're trying to package the build output, but that doesn't work this way anymore in .NET Core. You need to publish the app and package the result of the publish command (see dotnet publish, there are various deployment choices you need to make at this stage).

If you put PrivateAssets="All" on PropertyChanged.Fody and Fody itself, that should produce a correct redistributable application when you publish it (the build output is not designed to be redistributable in .NET Core).

Hi. You are right, I forgot to run that command. I didn't say that build output should be redistributable, I just didn't notice PropertyChanged as dependency there and thought that was strange. Anyway, I managed to deploy a correct redistributable application, thanks to your help.

All the best.

i am experiencing the same issue but even after i do a dotnet publish and set PrivateAssets="All" on Fody and PropertyChanged.Fody, the PropertyChanged.dll which PropertyChanged.Fody depends on does NOT get published to my application target folder.
Is there some kind of issue in the PropertyChanged.Fody nuget the way it is created?

If i manually copy the PropertyChanged.dll to my app target folder then issue goes away. Could you please show a working example where PropertyChanged.dll physically gets copied to the target folder of a .net core 3.1 app?

PropertyChanged.dll is not supposed to be published. PropertyChanged.Fody removes the reference to it during weaving, and removes all attributes from the assembly as it processes them.

If your application needs to reference PropertyChanged.dll in order to work, then I suppose you're doing something wrong.

ok that makes sense. any idea on what i am doing wrong?

That's hard to tell. Maybe you used an attribute in an unexpected place, but that's only a guess.

You can try to decompile the processed assembly and look for references to types in PropertyChanged.dll. That should point you in the right direction.

so i finally found what seems to be a solution. In my csproj Package Reference for PropertyChanged.Fody i had to includeAssets=All and ExcludeAssets=runtime in addition to PrivateAssets=all.

<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" PrivateAssets="All"> <ExcludeAssets>runtime</ExcludeAssets> <IncludeAssets>All</IncludeAssets> </PackageReference>

Upon build this now generated the correct output in AppName.deps.json
"PropertyChanged.Fody/3.4.0": { "dependencies": { "Fody": "6.5.1" } }

As opposed to what it did without these changes:
"PropertyChanged.Fody/3.4.0": { "dependencies": { "Fody": "6.5.1" }, "runtime": { "lib/netstandard2.1/PropertyChanged.dll": { "assemblyVersion": "3.4.0", "fileVersion": "3.4.0" } } }

Which is why it crashed at runtime looking for PropertyChanged.dll in the app target folder. It would be nice if going forward one could reference PropertyChanged.Fody nuget without having to do all this csproj hacking. Would be nice if it did the right thing out of the box.