Search code examples
c#wcf.net-standard-2.0wcf-hosting

Hosting a WCF service in NetStandard 2.0 Class Library


I recently migrated a dotnet framework v4.7.2 WCF service with the upgrade-assisstant tool to NetStandard 2.0. the project successfully migrated and compiled, BUT I couldnt start the service either from visual studio nor dotnet cli. the Error I get from dotnet cli tool is :

A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found.

AND the error I get trying to start the service from visual studio, solution explorer -> right click on wcf project -> debug -> start new instance is:

A project with an output type of class library couldnt start directly.

P.S when the WCF service was still dotnet framework v4.7.2 I could easily start the service doing the above mentioned procedure in visual studio.


Solution

  • WCF server APIs are not supported on .NET Standard or .NET Core/.NET 5+, so there's no good way to migrate such an app forward.

    Upgrade Assistant tries to figure out whether a project should upgrade to a library or an exe based on the previous project type. For this project, Upgrade Assistant guessed it was a library since there was no traditional main method and it wasn't a web app or some other project type that the tool understood as executable. Regardless of whether it upgraded it as a .NET Standard library or as a .NET 5 exe, though, it wouldn't work because WCF server APIs are only supported on .NET Framework.

    It might be nice if Upgrade Assistant alerted you to that early in the process so you knew upgrading wouldn't work for this type of project. I thought it had a feature like that, but it must have missed for this specific project. You could provide feedback on the tool's GitHub page (https://github.com/dotnet/upgrade-assistant/issues).

    As far as how you can actually upgrade WCF server stuff, you'll need to re-architect using a different technology like ASP.NET Core, gRPC, or CoreWCF.