System.TypeLoadException: Method 'WriteFileAsync' in type 'ServiceStack.IO.MemoryVirtualFiles'

Getting this error on App startup when Azure DevOps builds my project. App works fine in Visual Studio.

   Unhandled exception. System.TypeLoadException: Method 'WriteFileAsync' in type 'ServiceStack.IO.MemoryVirtualFiles' from assembly 'ServiceStack.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
   at ServiceStack.ServiceStackHost..ctor(String serviceName, Assembly[] assembliesWithServices)
   at ServiceStack.AppHostBase..ctor(String serviceName, Assembly[] assembliesWithServices) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\AppHostBase.NetCore.cs:line 31
   at WebApp.AppHost..ctor() in D:\a\1\s\NCMSProgram\NCMSProgram\Startup.cs:line 340
   at MyCtor()
   at ServiceStack.ModularStartup.CreateStartupInstance(Type type)
   at ServiceStack.ModularStartup.GetPriorityInstances()
   at ServiceStack.ModularStartup.ConfigureServices(IServiceCollection services)
   at ServiceStack.ModularStartupActivator.ConfigureServices(IServiceCollection services)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] 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.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at WebApp.Program.Main(String[] args)

Solution 1:

Whenever you get Type or Missing method exceptions from using the pre-release packages which referenced in yours project NuGet.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="ServiceStack MyGet feed" value="https://www.myget.org/F/servicestack" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Typically it's due to downloading the same pre-release package version at different times which you can resolve by deleting your NuGet packages cache:

$ nuget locals all -clear

Then restoring your packages again which fetches the latest version of each package ensuring they're all built at the same time.

As an added precaution I've rebuilt and deployed all pre-release packages again, so just re-running the task again may also resolve it.