Can Fody and its plugins be used with .NET Core (3.0)?

1

As the title says, I'm having trouble getting Fody, and the plugin Fody.PropertyChanged, to work in .NET Core 3.0, or any .NET Core version. Reading the issues on the respective GitHub pages doesn't answer my question, nor am I able to find any relevant answers.

Once installed I cannot run my WPF project anymore and I am given the following error:

The target process exited without raising a CoreCLR started event.
Ensure that the target process is configured to use .NET Core.
This may be expected if the target process did not run on .NET Core.
The program '[21820] CalculationToolsApp.exe' has exited with code -2147450749 (0x80008083).

Any suggestions?

EDIT: I found out that I (maybe) cant use "Fody.Costura" with "Fody.PropertyChanged" like this in the FodyWeavers.xml file:

<Weavers>
  <PropertyChanged />
  <Costura />
</Weavers>

Which shouldn't be a problem because with .NET Core I can create a single file application anyway. Removing the Costura reference from the FodyWeavers.xml solved my problem!

wpf
.net-core
.net-core-3.0
fody
fody-propertychanged
asked on Stack Overflow Sep 24, 2019 by JasonLandbridge • edited Sep 26, 2019 by JasonLandbridge

2 Answers

3

It should work. Fody is compatible with .NET Standard.

  • Create a new WPF app using the WPF App (.NET Core) template in Visual Studio 2019 or using the dotnet new wpf command
  • Install the Fody and PropertyChanged.Fody NuGet packages
  • Add a file named "FodyWeavers.xml" with the following contents to the project:

    <Weavers>
        <PropertyChanged />
    </Weavers>
    
  • Build

If you then decompile the assembly using a decompiler such as for example dotPeek, you should see the injected code as expected, e.g.:

public string GivenNames
{
    // Method get_GivenNames with token 06000009
    get
    {
        return this.<GivenNames>k__BackingField;
    }
    // Method set_GivenNames with token 0600000A
    set
    {
        if (string.Equals(this.<GivenNames>k__BackingField, value, StringComparison.Ordinal))
            return;
        this.<GivenNames>k__BackingField = value;
        this.<>OnPropertyChanged(<>PropertyChangedEventArgs.FullName);
        this.<>OnPropertyChanged(<>PropertyChangedEventArgs.GivenNames);
    }
}
answered on Stack Overflow Sep 25, 2019 by mm8
0

Costura didnt work in wpf with .net core 3.1 for me either. In .net core 3.1 you can use this instead:

  • Build -> publish -> create profile -> Edit "Configuration"
  • Target Runtime = win-x64 (or what ever target system you want, but NOT "portable")
  • expand "File Publish Options"
  • check: Produce single file
  • save

When you now choose build -> publish -> publish button it will create the single file.

It seems to be that they stopped the costura project because of the "Single-file executables" feature of .net core. Though this feature is still behind costura because you have to set a target runtime.

https://github.com/Fody/Costura/issues/442

In dotnet core 3 there are two new features

Single-file executables
Assembly linking

With these features included in the dotnet tool set, the value proposition of Costura is greatly diminished. With that in mind I think long term Costura should cease to be used as people transition over.

Please comment with any input.

Plan:

disable issues
PR will still be accepted but only for bug fixes
add note to readme
add note to nuget description
write a warning in 
answered on Stack Overflow Feb 9, 2020 by Blechdose • edited Feb 13, 2020 by Blechdose

User contributions licensed under CC BY-SA 3.0