Disable of auto tracking in .net core app causes exception

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
dgxhubbard
Posts: 47
Joined: Fri 14 Aug 2015 20:58

Disable of auto tracking in .net core app causes exception

Post by dgxhubbard » Mon 09 Apr 2018 23:39

We have a .net core app which uses a .netstandard 2.0 library for the model. We have been using the model to create a database for .net core like so:

using ( var context = MyContextFactory.Create () )
{
context.Database.EnsureCreated ();
context.SaveChanges ();
}


and in the factory method (shown below) when we hit the line disable auto tracking we get an exception (shown below) about cannot load type performance counter. We are only using .net core libs and of course the devart linq and postgresql dotConnect libs. Why is the Devart code referencing the .net full library 4.0.0 system.diagnostics library? Again all of this was working for sql server the only things added are the relevant devart dotConnect for postgresql and the call to UsePostgreSql.


Factory
public static MyContext Create ()
{
var optionsBuilder = new DbContextOptionsBuilder<GtContext> ();
if ( optionsBuilder == null )
throw new NullReferenceException ( "Failed to create db context options builder" );


optionsBuilder.UsePostgreSql ( PostgreSqlConnectionString );
//optionsBuilder.UseSQLite ( SqliteConnectionString );
//optionsBuilder.UseSqlServer ( MsSqlConnectionString );

var context = new MyContext ( optionsBuilder.Options );
if ( context == null )
throw new NullReferenceException ( "Failed to create context" );

// disable change tracking
context.ChangeTracker.AutoDetectChangesEnabled = false;
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

return context;
}





Exception

System.TypeLoadException
HResult=0x80131522
Message=Could not load type 'System.Diagnostics.PerformanceCounterType' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Source=Devart.Data.SQLite
StackTrace:
at Devart.Common.DbConnectionPoolGroup.a(q A_0)
at Devart.Common.DbConnectionFactory.a(String A_0, q& A_1)
at Devart.Common.DbConnectionBase.set_ConnectionString(String value)
at Devart.Data.SQLite.Entity.m.b(RelationalOptionsExtension A_0)
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Devart.Data.SQLite.Entity.p..ctor(RelationalTypeMapperDependencies A_0, cu A_1)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker()
at Gt.Model.GtContextFactory.Create(Boolean useLogger) in C:\Repository\GtNext\Source\Base\Next\GtModel\GtContextFactory.cs:line 75
at Gt.WebApi.Startup.CreateDatabase() in C:\Repository\GtNext\Source\Web\GtWebApi\Startup.cs:line 119
at Gt.WebApi.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in C:\Repository\GtNext\Source\Web\GtWebApi\Startup.cs:line 72

dgxhubbard
Posts: 47
Joined: Fri 14 Aug 2015 20:58

Re: Disable of auto tracking in .net core app causes exception

Post by dgxhubbard » Mon 09 Apr 2018 23:45

Also I saw this related question and the answer you should not use full framework but the user does not mention using the full framework.

viewtopic.php?t=35882


Is this related. Again this is a pure .net core app with model in .net standard 2.0 using only .net standard 2.0 libs and those are entity framework core 2.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Disable of auto tracking in .net core app causes exception

Post by Shalex » Wed 11 Apr 2018 18:32

We cannot reproduce the issue with https://www.nuget.org/packages/Devart.D ... /5.10.1115 in the "Target framework=.NET Core 2.0" project in our environment at the moment.

Please provide the additional information we have asked by email.

Post Reply