I have a .NET Core console app with target netcoreapp2.1. It calls into an existing WCF service using the Windows Compatibility Pack.
When I run it through Visual Studio, or if I use dotnet run
to run it from the command line, it works fine.
However, I want to publish it to a .exe file so that I can run it by double-clicking it.
So, I ran the Publish which appears to succeed, but when I try to run the published .exe file it fails with the following exception:
System.IO.FileNotFoundException: Could not load file or assembly
'System.Private.ServiceModel, Version=4.1.2.1, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
This error happens on the machine that I ran the publish on, and also if I try copying the published folder to another machine. I believe that System.Private.ServiceModel
is some sort of deep dependency of the Microsoft.Windows.Compatibility
package, but why is this not working? Surely it should have been copied to the output folder automatically?
Is there additional configuration or setup required to get the publish to pull in dependencies automatically?
If it matters, the reference in the csproj file looks like this:
<ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
</ItemGroup>
I had the same problem and I've manually added from nuget the missing file by installing the System.Private.ServiceModel
package.
This is a hack though, because from the description of the package you can see that it's meant for .Net internal usage, but I didn't find any other options.