3

We have a Visual Studio C# solution with several projects including .NET Standard class libraries, .NET Framework applications (because they use 3rd party references that are written on Framework), and .NET Core applications.

Previously these projects used:

  • .NET Standard 2.0
  • .NET Core 2.0
  • .NET Framework 4.6.1
  • ServiceStack 5.1.0

We had to do something a bit odd. We had .NET Core apps that were hosting ServiceStack services, and we had .NET Framework application that were ServiceStack clients, and both applications were referencing a .NET Standard class library containing Request objects for ServiceStack. Unfortunately the Framework and Core versions of the ServiceStack modules were not compatible, particularly in the Interfaces component. So the Framework application had to reference the ServiceStack.*.Core DLLs (so mythz told us and it solved the problem).

Now we have upgraded our code to

  • .NET Standard 2.0
  • .NET Core 2.2
  • .NET Framework 4.7.2
  • ServiceStack 5.4.0

The code compiles just fine, but when we run it, we cannot instantiate a JsonServiceClient in a Framework application.

  using (var client = new JsonServiceClient(_config.PropagationUrl))
  {
     ...
  }

The first line of the above code throws the following exception:

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'ServiceStack.ServiceClientBase' threw an exception. Source=ServiceStack.Client StackTrace: at ServiceStack.ServiceClientBase..ctor() at ServiceStack.JsonServiceClient..ctor(String baseUri) at Stitch.Logic.Coverage.ExtentsActor.PostCellExtentRequest(CellExtentsRequest request) in C:\Work\TMobile\stitch\src\Stitch.Logic\Coverage\Actors\ExtentsActor.cs:line 75

Inner Exception 1: TypeInitializationException: The type initializer for 'ServiceStack.Text.Env' threw an exception.

Inner Exception 2: FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Inner Exception 3: FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Can anyone tell me why and, more importantly, how to fix this?

  • Check your bindings. Post them if you don't see the problem. Also verify you're using an appropriate version of JSON. In fact, focus on your JSON binding. – jwdonahue Oct 03 '18 at 22:57

1 Answers1

2

It's a binding issue, try first either adding or removing the Assembly binding information for System.Runtime.InteropServices.RuntimeInformation:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>

If that doesn't resolve it try removing all the ServiceStack NuGet Packages and assembly bindings, delete the /packages, /bin and /obj folders and add the ServiceStack NuGet packages again.

mythz
  • 134,801
  • 25
  • 234
  • 373
  • Yes, that fixed it. I had to REMOVE dependentAssembly references for both System.Runtime.InteropServices.RuntimeInformation AND for System.Runtime. Is this because I had NuGet upgrade my app to latest version of both (4.0.2.0), both ServiceStack is still referencing older versions (4.0.0.0)? – Phoeniceus Agelaius Oct 04 '18 at 13:50
  • 1
    @PhoeniceusAgelaius NuGet tried to automatically generate binding redirects it thinks it needs when you install/upgrade packages, sometimes it gets them wrong. – mythz Oct 04 '18 at 16:46