Could not load type 'ServiceStack.UseSystemJson'

I updated from ServiceStack 8.0.0 to 8.0.1 and my application now throws an exception:

System.TypeLoadException: Could not load type 'ServiceStack.UseSystemJson' from assembly 'ServiceStack.Interfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at ServiceStack.AppHostBase..ctor(String serviceName, Assembly[] assembliesWithServices)
   at Server.ConfigurationNs.AppHost..ctor() in C:\XXX\code\src\Server\ConfigurationNs\Configure.AppHost.cs:line 47
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Any ideas why 6.0.0.0 is shown above?

Do you have a mix of .NET 6 and .NET 8 projects?

UseSystemJson is only available in .NET 8 builds, so something must referencing .NET 6 dlls.

Everything should be NET 8, but I will double-check. Thank you.

All projects have TargetFramework as Net8.0

.NET 8.0 projects should be referencing the net8.0 .dll’s, but you have something referencing the 6.0.0 version of ServiceStack.Interfaces.

Can you check that all package references to ServiceStack.Interfaces reference 8.* version, i.e:

<PackageReference Include="ServiceStack.Interfaces" Version="8.*" />

Something must still be referencing the older 6.* version, try doing a clean rebuild, deleting bin/ and obj/ folders then doing a full restore if you believe that all projects (including any client projects) are referencing only 8.* packages.

It is strange, because all ServiceStack package references in the projects are equivalent to below:

<PackageReference Include="ServiceStack.Interfaces" Version="8.0.1" />

Previously, when all ServiceStack package references were 8.0.0 and there were no issues running the applications.

The ServiceStack packages fetched from feedz.

You can try downloading the pre-release packages on MyGet incase feedz is returning stale packages:

https://docs.servicestack.net/myget

I repeated the clearing of the nuget packages and I no longer have the error.

For reference, nuget commands documented here:

Thank you for your support.

1 Like

I have had to revert back to ServiceStack 8.0.0, because the 8.0.1 version caused the following error:

System.NotSupportedException: Could not resolve type 'Comment'
   at ServiceStack.GenerateCrudServices.ThrowCouldNotResolveType(String name) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/GenerateCrudServices.cs:line 319
   at ServiceStack.GenerateCrudServices.CreateOrGetType(ModuleBuilder dynModule, String typeName, List`1 metadataTypes, Dictionary`2 existingMetaTypesMap, Dictionary`2 generatedTypes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/GenerateCrudServices.cs:line 314
   at ServiceStack.GenerateCrudServices.CreateOrGetType(ModuleBuilder dynModule, MetadataType metaType, List`1 metadataTypes, Dictionary`2 existingMetaTypesMap, Dictionary`2 generatedTypes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/GenerateCrudServices.cs:line 508
   at ServiceStack.GenerateCrudServices.GenerateMissingServices(AutoQueryFeature feature, HashSet`1 requestTypes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/GenerateCrudServices.cs:line 271
   at ServiceStack.AutoQueryFeature.AfterConfigure(IServiceCollection services) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 191
   at ServiceStack.ServiceStackServicesOptions.ConfigurePlugins(IServiceCollection services) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/AppHostBase.Options.cs:line 39
   at ServiceStack.ServiceStackHost.LoadPluginsInternal(IPlugin[] plugins) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.cs:line 1700
   at ServiceStack.ServiceStackHost.OnAfterInit() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.cs:line 1226
   at ServiceStack.ServiceStackHost.Init() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.cs:line 323
   at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost, Action`1 configure) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/AppHostBase.NetCore.cs:line 730
   at Program.<Main>$(String[] args) in C:\XXX\code\src\Server\Program.cs:line 43

Reverting the version removed the error.

We’ve had to refactor all ServiceStack Plugins to support our latest .NET 8 integration features. Sounds like the new behavior introduced this issue, which unfortunately we wont be able to identify and resolve without a repro.

If you have time to create a stand-alone repro I can look at fixing it before next release.