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.

I tried the latest 8.3.1 release, and the above error still occurs.

Unfortunately, until this is fixed, my applications are frozen on the 8.0.0 release.

I will try to find the time to create a standalone repository proving the problem.

Whilst I am trying to get a demo working, could it be related to the an internal ServiceStack OpenApiSpecification request?

From the console error,

I only find PatchComment I can find in the log files for OpenApiSpecification .

What makes this an OpenApiSpecification request? It looks like it can’t create an API because the underlying type can’t be found.

After a little further digging, you are correct that ServiceStack exception indicates unresolved types:

GenerateCrudServices.ThrowCouldNotResolveType() line 319.

However, the so-called unresolved types are defined in a separate ServiceModel project that is an application dependency. There are no compilation errors using those referenced types. This is my standard solution structure and has been working without issue until ServiceStack 8.0.1. Downgrading ServiceStack from 8.3.1 to 8.0.0. resolves the runtime issues.

image

I am still trying to create a demo solution, but in the meantime any thoughts?

Is this a standard project reference? what’s the XML in .csproj for this reference?

ServiceModel.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <WarningsAsErrors>true</WarningsAsErrors>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ServiceStack.Interfaces" Version="8.3.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\Framework\Framework.ServiceModel\Framework.ServiceModel.csproj" />
  </ItemGroup>

</Project>

ok so just a normal project reference.

Maybe try registering both assemblies when registering ServiceStack dependencies:

services.AddServiceStack([
    typeof(MyServices1).Assembly, 
    typeof(MyServices2).Assembly]);

I already register the service assembly where the types are defined in the ServiceModel, so unfortunately your suggestion did not work.

In my case ReferenceService below;

[assembly: HostingStartup(typeof(AppHost))]

namespace Server.ConfigurationNs;

public class AppHost : AppHostBase, IHostingStartup

    public AppHost() : base("Demo",
        typeof(GlobalSecurityService).Assembly,
        typeof(ReferenceService).Assembly,  // Comment is defined in Reference
        typeof(HedgeService).Assembly)
    {
        // code omitted
    }
    
    // code omitted
}

If all referenced project assemblies are registered then we’ll need a standalone repro to identify the issue.

Unfortunately, it has been difficult to create a standalone repo, because of the complexity of my code base.

However, I have discovered that the issue can be resolved by removing the GenerateCrudServices from the Configure.Autoquery, as shown below:

//public class ConfigureAutoQuery : IHostingStartup

            .ConfigureAppHost(appHost =>
            {
                appHost.Plugins.Add(new AutoQueryDataFeature());

                appHost.Plugins.Add(new AutoQueryFeature
                {
                    MaxLimit = 0, // needed to suppress SQL Server query limit of 5000 rows
                    IncludeTotal = true,
                    AutoCrudMetadataFilters =
                        new List<Action<AutoCrudMetadata>>
                        {
                            MyDatabaseAuditBehavior.MyAuditFilter
                        },

                    // ### Uncommenting below will cause runtime errors when > ServiceStack 8.0.0 ###
                    // GenerateCrudServices =
                    //     new GenerateCrudServices
                    //     {
                    //         AutoRegister = true,
                    //         CreateServices = new List<CreateCrudServices>
                    //         {
                    //             // read-only schemas explicitly defined
                    //             new() { Schema = "Security", IncludeCrudOperations = new List<string> { "Query" } },
                    //             new() { Schema = "Config", IncludeCrudOperations = new List<string> { "Query" } },
                    //             new() { Schema = "Master", IncludeCrudOperations = new List<string> { "Query" } },
                    //             // framework crud schemas
                    //             new()
                    //             {
                    //                 Schema = "Log", IncludeCrudOperations = new List<string> { "Query", "Create" }
                    //             },
                    //             new()
                    //             {
                    //                 Schema = "App",
                    //                 IncludeCrudOperations = new List<string>
                    //                     { "Query", "Create", "Update", "Patch", "Delete" }
                    //             },
                    //             new()
                    //             {
                    //                 Schema = "Attachment",
                    //                 IncludeCrudOperations = new List<string>
                    //                     { "Query", "Create", "Update", "Patch", "Delete" }
                    //             },
                    //             // application specific crud schemas
                    //         },
                    //         ExcludeTables = new List<string>
                    //         {
                    //             "Setting_History", "Translation_History",  "UserSetting_History",
                    //             "DocumentType_History", "Document_History", "Document_History",
                    //             "Note_History", "FileStore_History", "Comment_History",
                    //             "ResourceType_History", "Resource_History"
                    //         }
                    //     }
                });
            })

With ServiceStack 8.0.0, the above code may be uncommented without causing runtime errors.

Luckily, I do not need the AutoCrud feature, so for me the above would be a sufficient solution.

Thank you for your support.

1 Like