TypeLoadException after upgrade to 6.3.0

Hello,
After upgrading my .NET 6.0 project from using ServiceStack 6.1.0 to 6.3.0 (from nuget.org), I am encountering the following exception when debugging my project:

System.TypeLoadException: ‘Could not load type ‘ServiceStack.MetadataFeatureExtensions’ from assembly ‘ServiceStack, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null’.’

The stack trace is:
at ServiceStack.ServiceStackHost.OnStartupException(Exception ex)
at ServiceStack.ServiceStackHost.OnStartupException(Exception ex, String target, String method)
at ServiceStack.ServiceStackHost.LoadPluginsInternal(IPlugin[] plugins)
at ServiceStack.ServiceStackHost.OnAfterInit()
at ServiceStack.ServiceStackHost.Init()
at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost)
at [MyService].Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in [MyService]\Startup.cs:line 51
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)

Seeing other similar issues in this forum, I have already tried several steps to fix this problem, including:

  • Deleting all /bin and /obj folders in all project folders in the solution
  • Deleting my global /packages folder
  • Running from the command line: nuget locals all -clear
    Nothing I try fixes this problem. Can you recommend any other steps to try? I am at a loss for why this is occurring. Thanks in advance.

Hi @sharding,

The MetadataFeatureExtensions class was refactored out between 6.1 and 6.3 so it sounds like there might still be a mix of dependencies or bad cache. Couple of things to check.

  • Make sure all ServiceStack references are using the same version, eg 6.3 or 6.* in your .csproj files.
  • When clearing your local nuget cache, use the command dotnet nuget locals all --clear from the same environment you are developing from with, eg WSL2 will clear different a different cache than a terminal from the Windows command prompt.
  • Check if you have a NuGet.config file in your repository and if it is using any other NuGet sources

Thanks for the reply @layoric.

This code is in my AppHost.cs Configure override method:

Plugins.Add(new AdminFeature());

AdminFeature class is part of the ServiceStack.Admin namespace and the highest version of ServiceStack.Admin is 6.0.2.

If I comment out the above line, then my service starts up in the debugger just fine, without the exception. However, I am not sure what that line is supposed to do or whether my service needs it. I inherited responsibility for this service after it was implemented, so I don’t know everything about it yet. I am currently trying to verify if it passes integration tests without the above line.

Right, it’s because the AdminFeature from ServiceStack.Admin NuGet package has been deprecated and replaced with the new Admin UI and Locode that’s now built into ServiceStack, it’s last supported release was v6.0.2.

1 Like

Thanks for the reply @mythz, this helps. I resolved the problem by removing the AdminFeature plugin and removing the reference to ServiceStack.Admin.

1 Like