在 TeamCity 中使用 NUnit 3 通过控制台运行程序时找不到 ServiceStack 许可证



>我正在使用有效的许可证密钥。但是我不断收到此错误:

ServiceStack.LicenseException : The free-quota limit on '10 ServiceStack Operations' has been reached. Please see https://servicestack.net to upgrade to a commercial license or visit https://github.com/ServiceStackV3/ServiceStackV3 to revert back to the free ServiceStack v3.

到目前为止,我已经尝试了以下方法:

  • 将我的许可证密钥存储在 app.config 中
  • 将我的许可证密钥存储在 web.config 中
  • 将我的密钥添加为名为"SERVICESTACK_LICENSE"的系统环境变量
  • 通过 TeamCity 构建参数将我的密钥添加为系统属性
  • 通过 TeamCity 构建参数将我的密钥添加为系统环境变量
  • 在运行 AppHost.Init 之前通过调用 Licensing.RegisterLicense 添加我的密钥

当通过 TeamCity 构建参数将我的密钥添加为系统环境变量时,我反而从 JsConfig 中得到一个异常:

System.TypeInitializationException : The type initializer for 'ServiceStack.Text.JsConfig' threw an exception.
----> System.TypeInitializationException : The type initializer for 'ServiceStack.LicenseUtils' threw an exception.
----> System.IO.FileLoadException : Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at ServiceStack.Text.JsConfig.InitStatics()
at ServiceStack.AppHostHttpListenerPoolBase..ctor(String serviceName, Int32 poolSize, Assembly[] assembliesWithServices) in C:BuildAgentwork3481147c480f4a2fsrcServiceStackAppHostHttpListenerPoolBase.cs:line 75
at ServiceStack.AppSelfHostBase..ctor(String serviceName, Assembly[] assembliesWithServices) in C:BuildAgentwork3481147c480f4a2fsrcServiceStackAppSelfHostBase.cs:line 13
at Alstra.SG.Tests.AppSelfHost..ctor() in C:TeamCitybuildAgentworka0903bf22b2d1e1cTestAppSelfHost.cs:line 31
at Alstra.SG.Tests.Private.BaseIntegrationTest..ctor() in C:TeamCitybuildAgentworka0903bf22b2d1e1cTestPrivateBaseIntegrationTest.cs:line 16
at Alstra.SG.Tests.Private.Integration.RespondentServiceTests..ctor()
--TypeInitializationException
at ServiceStack.LicenseUtils.Init()
at ServiceStack.Text.JsConfig..cctor() in C:BuildAgentwork912418dcce86a188srcServiceStack.TextJsConfig.cs:line 21
--FileLoadException
at System.MemoryExtensions.AsSpan(String text)
at ServiceStack.Text.Jsv.JsvReader`1.Parse(String value) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextJsvJsvReader.Generic.cs:line 81
at ServiceStack.Text.TypeSerializer.DeserializeFromString[T](String value) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextTypeSerializer.cs:line 67
at ServiceStack.LicenseUtils.ToLicenseKeyFallback(String licenseKeyText) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextLicenseUtils.cs:line 446
at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextLicenseUtils.cs:line 252
at ServiceStack.Net45PclExport.RegisterLicenseFromConfig() in C:BuildAgentwork912418dcce86a188srcServiceStack.TextPclExport.Net45.cs:line 140
at ServiceStack.LicenseUtils..cctor() in C:BuildAgentwork912418dcce86a188srcServiceStack.TextLicenseUtils.cs:line 135

在运行AppHost.Init之前通过调用Licensing.RegisterLicense添加我的密钥时,我得到了以下异常:

System.IO.FileLoadException : Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at System.MemoryExtensions.AsSpan(String text)
at ServiceStack.Text.Jsv.JsvReader`1.Parse(String value) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextJsvJsvReader.Generic.cs:line 81
at ServiceStack.Text.TypeSerializer.DeserializeFromString[T](String value) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextTypeSerializer.cs:line 67
at ServiceStack.LicenseUtils.ToLicenseKeyFallback(String licenseKeyText) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextLicenseUtils.cs:line 446
at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText) in C:BuildAgentwork912418dcce86a188srcServiceStack.TextLicenseUtils.cs:line 252
at Alstra.SG.Tests.Private.BaseIntegrationTest..ctor() in C:TeamCitybuildAgentworka0903bf22b2d1e1cTestPrivateBaseIntegrationTest.cs:line 17
at Alstra.SG.Tests.Private.Integration.ActivityServiceTests..ctor()

很高兴得到一些帮助!

我相信您正在使用的ServiceStack版本是使用与您在测试项目中使用的版本不同的System.Runtime.CompilerServices.Unsafe构建的,并且因为绑定重定向在这种情况下不起作用。 请参阅重定向程序集绑定是否适用于使用测试运行程序进行单元测试?

作为解决方法,您可以尝试将 Nuget 包管理器中的 System.Runtime.CompilerServices.Unsafe 更改为 4.5.2。

此版本与缺少的程序集 Version=4.0.4.1 匹配。

编辑:如果在 NUnit 构建步骤中使用 NUnit 3,则可以指定"应用程序配置文件的路径:"以指向您的 app.config。 这应该可以解决根本问题,并允许您使用最新版本的 Nuget 包(因为随后将应用正确的绑定重定向(。

最新更新