Why am I getting error “The type ‘IReturn’ is defined in an assembly that is not referenced” using ServiceStack in VIsualStudio 2017

You can’t share a .NET Framework .dll with .NET Framework dependencies in .NET Core or .NET Standard projects and vice-versa.

Most ServiceStack NuGet packages contain both .NET v4.5 and .NET Standard 2.0 builds:

  • net45 – Contains support for running ASP.NET Web or Self-Hosting HttpListener App Hosts
  • netstandard2.0 – Contains support for only running on ASP.NET Core App Hosts

Only the .NET v4.5 builds contains support for hosting on classic ASP.NET or SelfHost HttpListener Hosts (i.e. AspNetRequest/AspNetResponse). You cannot use .NET Standard builds on ServiceStack in classic ASP.NET Web projects as the builds do not physically contain the dependencies and functionality needed – which isn’t available in .NET Standard 2.0 (which only covers running ASP.NET Core Apps).

There are 2 solutions for being able to share the same project in .NET Framework v4.6.1+ and .NET Standard / .NET Core projects:

Only reference .Core .NET Standard packages

To be able to share the same .dll with .NET Framework projects you need to either reference the .NET Standard only .Core packages so that when NuGet packages are installed your .NET v4.6.1+ project is referencing the same .NET Standard 2.0 dlls as your .NET Standard or .NET Core projects are using.

Create Multi-targed .NET Framework and .NET Standard 2.0 projects

The alternative is to maintain multi-targeted projects which creates both .NET Framework and .NET Standard builds. This is the approach that the Hello Mobile Shared Gateway project uses to support both .NET Framework and Mobile .NET Standard clients and the ServiceStack Server.Common project uses for the same ServiceStack Server implementation to be used in:

Leave a Comment