Reputation: 4004
We have a small application that uses ServiceStack OrmLite for database access. I am currently investigating a broken feature that worked previously.
There are two relevant entities:
[Alias("MyOrder")]
public class OrderEntity
{
[AutoIncrement]
public int Id { get; set; }
...
// Saved as JSV blob in the table
public AppEntity Processor { get; set; }
}
[Alias("MyApp")]
public class AppEntity
{
[AutoIncrement]
public int Id { get; set; }
...
[StringLength(64)]
public string UserName { get; set; }
public Guid? InternalUserId { get; set; }
}
Not sure if that matters but AppEntity
is located in another DLL/assembly.
Now there is a strange behavior. Processor
s are correctly saved in the table. I can also retrieve them in integration tests. However, in production code, when a list of OrderEntity
objects is fetched, Processor
property is null in every instance.
I digged a little bit into ServiceStack code in the debugger and saw that the JSV string is fetched correctly in the first place but it seems to get lost on the way.
This is the unit test that works:
var connectionString = @"Server=...";
var connectionFactory = new OrmLiteConnectionFactory(connectionString, new SqlServerOrmLiteDialectProvider());
var orderRepository = new OrderRepository(connectionFactory);
var orders = orderRepository.FindBySomeFilter();
// entries have not-null .Processor property
This is a small application that doesn't work:
var connectionString = @"Server=...";
var connectionFactory = new OrmLiteConnectionFactory(connectionString, new SqlServerOrmLiteDialectProvider());
var orderRepository = new OrderRepository(connectionFactory);
var orders = orderRepository.FindBySomeFilter();
// .Processor is not retrieved / null for all entries
Versions:
Upvotes: 2
Views: 160
Reputation: 143374
Some things you can try for resolving runtime dependency loading issues like this where it's unable to load the System.Runtime.CompilerServices.Unsafe
dependency:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
to your projectAs this is is a .NET Framework project you can try adding a binding redirect:
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
Or if you already have a binding redirect for this configured, try removing it.
Otherwise upgrading to the latest .NET Framework v4.7+ can also resolve loading runtime system dependencies like this.
Upvotes: 1