X throwing exception on creation of new seflhost project

I changed computer recently (and had to reinstall everything) and I just noticed that when I try to use x:

x new selfhost ProjectName

I’m getting this error:

The type initializer for ‘ServiceStack.Text.JsonSerializer’ threw an exception.

I tried with other templates and I also get the same error each time.

Any idea what might be causing this…?

Thanks.

Can’t reproduce this error, you can try uninstalling & reinstalling the x tool:

$ dotnet tool uninstall --global x
$ dotnet tool install --global x

Otherwise you can clone/download the template from: https://github.com/NetCoreTemplates/selfhost

Note: all .NET Core templates are self-hosting, the selfhost is the minimum configuration but if you’re unsure which template to install you should install the web i.e. https://github.com/NetCoreTemplates/web template as it’s an empty template with the recommended starting configuration for a .NET Core Web Project.

I tried that:

Tool ‘x’ (version ‘0.0.80’) was successfully uninstalled.
You can invoke the tool using the following command: x
Tool ‘x’ (version ‘0.0.80’) was successfully installed.

x new selfhost
The type initializer for ‘ServiceStack.Text.JsonSerializer’ threw an exception.

Noted for the web template. Are those working for web project running on linux using nginx and kestrel?

The command should include your project name, i.e:

$ x new web ProjectName

You can try -verbose switch to see a more detailed exception, e.g:

$ x -verbose new web ProjectName

As I can’t repro the issue I’m assuming it’s something related to your environment, in which case you can clone the GitHub Repo instead of using x new.

All .NET Core project templates are cross-platform can run on Windows & Linux, whether you choose to use nginx or another reverse proxy is an external concern independent from the template.

Very good to know.

I’m getting an error saying my license is invalid using the verbose flag:
System.TypeInitializationException: The type initializer for ‘ServiceStack.Text.TypeSerializer’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘ServiceStack.Text.JsConfig’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘ServiceStack.LicenseUtils’ threw an exception.
—> ServiceStack.LicenseException: This license is invalid. Please see servicestack.net or contact team@servicestack.net for more details. The id for this license is ‘7629’
—> ServiceStack.LicenseException: This license has expired on 01/01/0001 and is not valid for use with this release. Please see servicestack.net or contact team@servicestack.net for more details.
at ServiceStack.LicenseUtils.ValidateLicenseKey(LicenseKey key) in C:\Source\ServiceStack.Text\src\ServiceStack.Text\LicenseUtils.cs:line 271
at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText) in C:\Source\ServiceStack.Text\src\ServiceStack.Text\LicenseUtils.cs:line 244
— End of inner exception stack trace —
at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText) in C:\Source\ServiceStack.Text\src\ServiceStack.Text\LicenseUtils.cs:line 252
at ServiceStack.NetStandardPclExport.RegisterLicenseFromConfig() in C:\Source\ServiceStack.Text\src\ServiceStack.Text\PclExport.NetStandard.cs:line 114
at ServiceStack.LicenseUtils…cctor() in C:\Source\ServiceStack.Text\src\ServiceStack.Text\LicenseUtils.cs:line 135
— End of inner exception stack trace —
at ServiceStack.LicenseUtils.Init() in C:\Source\ServiceStack.Text\src\ServiceStack.Text\LicenseUtils.cs:line 140
at ServiceStack.Text.JsConfig…cctor() in C:\Source\ServiceStack.Text\src\ServiceStack.Text\JsConfig.cs:line 21
— End of inner exception stack trace —
at ServiceStack.Text.JsConfig.InitStatics() in C:\Source\ServiceStack.Text\src\ServiceStack.Text\JsConfig.cs:line 24
at ServiceStack.Text.TypeSerializer…cctor() in C:\Source\ServiceStack.Text\src\ServiceStack.Text\TypeSerializer.cs:line 36
— End of inner exception stack trace —
at ServiceStack.Text.TypeSerializer.Print(String text, Object[] args) in C:\Source\ServiceStack.Text\src\ServiceStack.Text\TypeSerializer.cs:line 295
at Web.Startup.CreateWebHost(String tool, String[] args, WebAppEvents events) in C:\src\dotnet-app\src\Web\Startup.cs:line 609
at Web.Program.Main(String[] cmdArgs) in C:\src\dotnet-app\src\X\Program.cs:line 33

Do I need to uninstall it from my old computer to fix this?

I’ve added the environment variable with the license key as per the instruction.

You don’t need a license for the dotnet tools, so it’s I’m assuming the LICENSE you have configured is causing it to fail. If you remove the SERVICESTACK_LICENSE environment variable and restart or relogin so the Environment variables are updated it should work.

It works perfectly.

Thanks.

And thanks for the suggestion to use the web project it took me a while to get their own my own starting with the selfhost template (but I did).