ServiceStack License not found when using NUnit 3 through Console Runner in TeamCity - nunit

I am using a valid license key. But I keep getting this error:
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.
So far I have tried the following:
Storing my license key in app.config
Storing my license key in web.config
Adding my key as a System Environment Variable called "SERVICESTACK_LICENSE"
Adding my key as a System Property through TeamCity Build Parameters
Adding my key as a System Environment Variable through TeamCity Build Parameters
Adding my key by calling Licensing.RegisterLicense before running AppHost.Init
When adding my key as a System Environment Variable through TeamCity Build Parameters I instead get an exception from 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:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\AppHostHttpListenerPoolBase.cs:line 75
at ServiceStack.AppSelfHostBase..ctor(String serviceName, Assembly[] assembliesWithServices) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\AppSelfHostBase.cs:line 13
at Alstra.SG.Tests.AppSelfHost..ctor() in C:\TeamCity\buildAgent\work\a0903bf22b2d1e1c\Test\AppSelfHost.cs:line 31
at Alstra.SG.Tests.Private.BaseIntegrationTest..ctor() in C:\TeamCity\buildAgent\work\a0903bf22b2d1e1c\Test\Private\BaseIntegrationTest.cs:line 16
at Alstra.SG.Tests.Private.Integration.RespondentServiceTests..ctor()
--TypeInitializationException
at ServiceStack.LicenseUtils.Init()
at ServiceStack.Text.JsConfig..cctor() in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\JsConfig.cs:line 21
--FileLoadException
at System.MemoryExtensions.AsSpan(String text)
at ServiceStack.Text.Jsv.JsvReader`1.Parse(String value) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\Jsv\JsvReader.Generic.cs:line 81
at ServiceStack.Text.TypeSerializer.DeserializeFromString[T](String value) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\TypeSerializer.cs:line 67
at ServiceStack.LicenseUtils.ToLicenseKeyFallback(String licenseKeyText) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\LicenseUtils.cs:line 446
at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\LicenseUtils.cs:line 252
at ServiceStack.Net45PclExport.RegisterLicenseFromConfig() in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\PclExport.Net45.cs:line 140
at ServiceStack.LicenseUtils..cctor() in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\LicenseUtils.cs:line 135
When adding my key by calling Licensing.RegisterLicense before running AppHost.Init I get the following exception instead:
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:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\Jsv\JsvReader.Generic.cs:line 81
at ServiceStack.Text.TypeSerializer.DeserializeFromString[T](String value) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\TypeSerializer.cs:line 67
at ServiceStack.LicenseUtils.ToLicenseKeyFallback(String licenseKeyText) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\LicenseUtils.cs:line 446
at ServiceStack.LicenseUtils.RegisterLicense(String licenseKeyText) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\LicenseUtils.cs:line 252
at Alstra.SG.Tests.Private.BaseIntegrationTest..ctor() in C:\TeamCity\buildAgent\work\a0903bf22b2d1e1c\Test\Private\BaseIntegrationTest.cs:line 17
at Alstra.SG.Tests.Private.Integration.ActivityServiceTests..ctor()
Happy to get some help!

I believe the version of ServiceStack you are using was built with a different version of System.Runtime.CompilerServices.Unsafe than what you are using in your Test project and because bindingredirect are not working in this context.
See Does redirecting assembly binding work for unit testing with a test runner?
As a workaround, you can try changing System.Runtime.CompilerServices.Unsafe in Nuget Package Manager to 4.5.2.
This version matches the missing assembly, Version=4.0.4.1.
Edit: If you are using NUnit 3 in your NUnit build step, you can then specify "Path to application configuration file: " to point to your app.config.
This should solve the root problem and let you use the most current version of your Nuget packages (since the correct bindingRedirects will then be applied).

Related

Deploy Database Project with MSBuild with CommandLine Parameters fails

I am failing to deploy Database project using command line parameters with msbuild. I would like to:
use publish xml profile
define connection string as command line parameter
but this seems to be impossible for no reason. There is for sure some simple catch I am missing. I tried following variants:
msbuild /t:SqlDeploy /p:SqlPublishProfilePath="test.publish.xml" /p:TargetConnectionString="Data Source=..." Database.sqlproj
deploys database
values in test.pubhlish.xml are ignored
msbuild /t:Build /t:Deploy /p:SqlPublishProfilePath="test.publish.xml" /p:TargetConnectionString="Data Source=..." Database.sqlproj
deploys database
values in test.pubhlish.xml are ignored
msbuild /t:Build /t:Publish /p:SqlPublishProfilePath="test.publish.xml" /p:TargetConnectionString="Data Source=..." Database.sqlproj
fails with error: Deploy Error : The connection string is not valid
values in test.publish.xml file are used (when test.publish.xml contains TargetConnectionString, database is deployed correctly)
In all 3 cases I am using exactly the same ConnectionString, so it is not a typo or error in the connection string. I need to use the 3rd variant, but this just fails.. What am I missing?

Using BSON type provider in F# Script

I'm trying to use the Bson type provider to do some work with a MongoDB database. in an F# script.
I've taken the following steps.
I've created the Bson files by using:-
mongodump /host:starbug /db:Logger /out:data
I've built the type provider from the source from https://github.com/visemet/FSharp.Data.Bson
I've created the following F# script file:
#I "../../FSharp.Data.Bson/bin" // Location of Dll's created by step 1.
#r "FSharp.Data.Bson.Runtime.dll"
#r "FSharp.Data.Bson.dll"
#r "MongoDB.Bson.dll"
open BsonProvider
type AccessLogs = BsonProvider<"./data/EkmLogger/access_logs.bson">
type SQLiteLogs = BsonProvider<"./data/EkmLogger/sqlite_logs.bson">
let accessLogs = AccessLogs.GetSamples().[0]
But the last line is showing the following error in VS 2013
The type provider 'BsonProvider.ProviderImplementation.BsonProvider' reported an error in the context of provided type 'BsonProvider.BsonProvider,Path="./data/Logger/access_logs.bson"', member 'GetSamples'.
The error: Could not load file or assembly 'FSharp.Data.Bson.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified. C:\Development\fsharp-scripts\Logger\AccessSqliteStats.fsx
Any idea what's wrong?

ConfigurationType error when using Entity Framework migrate.exe with multiple migration configurations

In my solution, I have a Data project that contains multiple Entity Framework 6.1.3 migration configuration classes. My goal is to run Entity Framework migration steps - for one of them, against an existing database - from TeamCity (or, to simplify, from a command line).
The migration configuration class I am using is the following:
namespace MyProject.Data
{
public partial class MyCustomMigrationConfiguration :
DbMigrationsConfiguration<MyCustomContext>
{
public MyCustomMigrationConfiguration()
{
AutomaticMigrationsEnabled = false;
AutomaticMigrationDataLossAllowed = true;
MigrationsDirectory = #"Migrations\MyCustomContext\MigrationSteps";
}
}
}
I can successfully run the following command from Package Manager Console in Visual Studio:
Update-Database -Verbose -StartUpProject Web -ConnectionString '-my
connection string here-' -ConfigurationTypeName
MyCustomMigrationConfiguration -ConnectionProviderName
'System.Data.SqlClient'
I want to do the same thing from a command line, so I run this:
migrate.exe MyProject.Data.dll "MyCustomMigrationConfiguration"
/startUpConfigurationFile=MyProject.Web.dll.config
/connectionString="-my connection string here-;"
/connectionProviderName="System.Data.SqlClient" /verbose
However, I get the following error:
ERROR: The migrations configuration type
MyCustomMigrationConfiguration was not be found in the assembly
‘MyProject.Data'.
Any suggestions on how to fix this, please?
You can specify the directory where are all the dependencies (assemblies) needed to run your code. You can do that by using the /startUpDirectory option, as explained here:
Specify working directory
Migrate.exe MyApp.exe /startupConfigurationFile=”MyApp.exe.config” /startupDirectory=”c:\MyApp”
If you assembly has dependencies or reads files relative to the working directory then you will need to set startupDirectory.
Found the solution (I ended up downloading the Entity Framework source code from http://entityframework.codeplex.com/ and debugging the migrate console application).
Apparently, all the dependencies of MyProject.Data.dll need to be copied in the same folder with it and migrate.exe, otherwise the Entity Framework migrate.exe tool will throw the misleading error message above.
Entity Framework could really use better error handling and a clearer error message in this case.
As a reference to Entity Framework devs: the following code in TypeFinder.cs was returning a null type because the dependencies of MyProject.Data.dll were not copied in the folder of migrate.exe:
type = _assembly.GetType(typeName, false);

TypeLite fresh install doesn't work

I just installed TypeLite into my project via NuGet, but it doesn't work, and everything I've tried hasn't helped... This is the file that was created after installing:
<## template debug="false" hostspecific="True" language="C#" #>
<## assembly name="$(TargetDir)TypeLite.dll" #>
<## assembly name="$(TargetDir)TypeLite.Net4.dll" #>
<## assembly name="$(TargetDir)$(TargetFileName)" #>
<## import namespace="TypeLite" #>
<## import namespace="TypeLite.Net4" #>
<##output extension=".d.ts"#>
<##include file="Manager.ttinclude"#>
<# var manager = Manager.Create(Host, GenerationEnvironment); #>
<# var ts = TypeScript.Definitions()
.WithReference("Enums.ts")
.ForLoadedAssemblies();
#>
<#= ts.Generate(TsGeneratorOutput.Properties) #>
<# manager.StartNewFile("Enums.ts"); #>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<# manager.EndBlock(); #>
<# manager.Process(true); #>
This is the error I get:
Severity Code Description Project File Line
Error Running transformation: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at TypeLite.TsModelBuilder.Add(Assembly assembly)
at TypeLite.Net4.TypeScriptFluentExtensions.ForLoadedAssemblies(TypeScriptFluent ts)
at Microsoft.VisualStudio.TextTemplating097C215A707CB07DE5AACDA590F263DF8554A0CCA899B583BF1832F7C0C5D3E595312AE41D3DFD1BB9CA643458AA5D86FE3DBA281ED0000D4B4C1D87EA1DEFFB.GeneratedTextTransformation.TransformText() MyApp S:\MyApp\Scripts\TypeLite.Net4.tt 1
If I choose "Debug T4 template" this is what I get:
Severity Code Description Project File Line
Error Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at TypeLite.Extensions.TypeExtensions.GetCustomAttribute[TType](Type type, Boolean inherit)
at TypeLite.TsModelBuilder.<Add>b__4(Type t)
at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
at TypeLite.TsModelBuilder.Add(Assembly assembly)
at TypeLite.Net4.TypeScriptFluentExtensions.ForLoadedAssemblies(TypeScriptFluent ts)
at Microsoft.VisualStudio.TextTemplating097C215A707CB07DE5AACDA590F263DF8554A0CCA899B583BF1832F7C0C5D3E595312AE41D3DFD1BB9CA643458AA5D86FE3DBA281ED0000D4B4C1D87EA1DEFFB.GeneratedTextTransformation.TransformText() in s:\MyApp\Scripts\TypeLite.Net4.tt:line 13
=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : Breeze.WebApi2, Version=1.5.0.0, Culture=neutral, PublicKeyToken=f6085f1a45e2ac59.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http/System.Web.Http.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http/System.Web.Http.EXE.
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http/System.Web.Http.DLL.
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http.EXE.
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http/System.Web.Http.EXE. MyApp s:\MyApp\Scripts\TypeLite.Net4.tt 13
If I add this to the file:
<## assembly name="System.Web.Http.dll" #>
Then I get:
Error Compiling transformation: Assembly 'WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' MyApp S:\MyASpp\Scripts\TypeLite.Net4.tt 1
Unfortunately I haven't been able to figure out where that 5.2.2 reference is; everything in my projects is 5.2.3. If I take the file path to my 5.2.3 DLL and put that in (which is c:\packages... from nuget), it works.
I guess my question is why doesn't it find the DLL reference via the project, or is there a better way to do this? I won't want to have to hard-code paths in this file, ideally I wouldn't need to specify them at all, but I don't know how else to do it at this point.
Got the same error. In my case, all the files that I wanted to be handled by typeLite were in the same assembly so I soved the problem by restricting to the one assembly using the following (in the .tt file):
<# var ts = TypeScript.Definitions()
.For(Assembly.GetAssembly(typeof(MyWebProject.SomeClass)));
#>
T4 templates doesn't know anything about packages installed in your project, so it is necessary to add reference to used assemblies manually.
Obviously T4 is trying to load a wrong version of the library. I would check whether your bin folder contains the correct version of the assembly and I would try to reference the library from there.
<## assembly name="$(TargetDir)System.Web.Http.dll" #>

Errors with installing SNA packages

I've been trying to install SNA packages but i always get the next errors,
> install.packages("sna")
Installing package(s) into ‘/home/rvaca/R/i486-pc-linux-gnu-library/2.14’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/sna_2.2-0.tar.gz'
Content type 'application/x-gzip' length 273329 bytes (266 Kb)
opened URL
==================================================
downloaded 266 Kb
The downloaded packages are in
‘/tmp/Rtmp7iF3Qz/downloaded_packages’
> library(sna)
starting httpd help server ... done
Error in attr(helpObj, "call") <- this.call :
attempt to set an attribute on NULL
Error: package/namespace load failed for ‘sna’
> library("sna")
Error in attr(helpObj, "call") <- this.call :
attempt to set an attribute on NULL
Error: package/namespace load failed for ‘sna’
> library('sna')
Error in attr(helpObj, "call") <- this.call :
attempt to set an attribute on NULL
Error: package/namespace load failed for ‘sna’
What happened? Thanks in advance
vacing
When loading the sna package using library(sna) or require(sna), the function .First.lib() is (still) called. This function is now among the defunct functions in the base package (see ?.First.lib), but that's beside the point.
Looking at the source files for sna, .First.lib() is defined in the file zzz.R and contains the line
ehelp <- help(package="sna")$info[[1]].
This does not work well if getOption("help_type") is not "text". You could, therefore, try setting this option before loading the package to see if that works.
options(help_type="text")
library(sna)
Does this still produce an error?
EDIT
Since the above still gives an error, and since the package has properties that are being phased out (i.e., no namespace, and using .First.lib()), I would recommend contacting the package's maintainer (perhaps with a reference to this question on SO):
packageDescription("sna")$Maintainer
Again, my suspicion is that the problem lies in creating the object ehelp in the .First.lib() function, which is called since there is no package namespace specified.
Ok this is the result of sessionInfo(), (I forgot to comment that i runs it into Eclipse)
> sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: i486-pc-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8
[9] LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Cairo_1.5-1 igraph_0.5.5-4 rj_1.0.3-7
loaded via a namespace (and not attached):
[1] rj.gd_1.0.3-3 sna_2.2-0 tools_2.14.2