3
votes

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?

1
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

1 Answers

2
votes

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.