SS License error

Getting following error on startup, our license is valid till 2019. I added binding redirect for System.Runtime as well.

ServiceStack.LicenseException: This license is invalid. Please see or contact for more details. The id for this license is '6253' ---> System.BadImageFormatException: Could not load file or assembly 'System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
   --- End of inner exception stack trace ---
   at System.MemoryExtensions.AsSpan(String text)
   at ServiceStack.Text.Jsv.JsvReader`1.Parse(String value)
   at ServiceStack.Text.TypeSerializer.DeserializeFromString[T](String value)
   at ServiceStack.LicenseUtils.ToLicenseKeyFallback(String licenseKeyText)
   at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText)
   --- End of inner exception stack trace ---
   at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText)

The issue is not with the license key but with an invalid project configuration where it’s unable to load the System.Runtime dependency, if this is a .NET Core project can you try manually adding a reference to System.Runtime in your .csproj:

<Reference Include="System.Runtime"/>

Although the BadImageFormatException usually means an invalid bitness error, e.g. you’re trying to load 64-bit native dll into a 32-bit process.

Otherwise please upload a small project with the error on GitHub (don’t include your License Key) and send me a link to it and I’ll check it out.

I think I figured out the issue. SS is asking for .net core version of System.Runtime instead of .net framework. Is there a way to force add the reference to .net core version of the System.Rutime?

.NET Framework Apps automatically try to use the .NET Framework builds in each ServiceStack NuGet package. Are you trying to run ASP.NET Core Apps on the .NET Framework? If you are you need to reference the *.Core packages instead.

No, not using core, my project is .net 4.5.7. Not sure why SS is looking for .net core references instead. It used to work just fine before v5.2.

ServiceStack doesn’t look for .NET Core references for .NET Framework projects if you’re using the main NuGet packages.

If you can put together a small, stand-alone project on GitHub that shows the issue I can take a look.

Could it be due to using a specific app host as a base class to AppHost? I am using AppSelfHostBase, do you have any recommendations?

No, it’s got nothing to do with ServiceStack’s classes dependencies. If anything it can be caused by invalid binding redirects, so you can try removing all binding redirects, uninstalling packages and try installing from a clean slate to see if that helps.

But unless you send me a repro I won’t be able to help any further.

I understand, I am trying to create a repro but not able to. It only occurs in release build on a non dev environment.