Disable of auto tracking in .net core app causes exception

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
dgxhubbard
Posts: 45
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:35

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.PostgreSql
StackTrace:
at Devart.Common.DbConnectionPoolGroup.a(a2 A_0)
at Devart.Common.DbConnectionFactory.a(String A_0, a2& A_1)
at Devart.Common.DbConnectionBase.set_ConnectionString(String value)
at Devart.Data.PostgreSql.Entity.s.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.PostgreSql.Entity.x..ctor(RelationalTypeMapperDependencies A_0, c1 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: 45
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: 8420
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Wed 18 Apr 2018 11:32

We are processing your request.

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

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

Post by Shalex » Wed 18 Apr 2018 16:24

Current implementation of dotConnect for PostgreSQL includes two versions of assemblies:
  • the .NET Framework Devart.* assemblies shipped with installation (by default, C:\Program Files (x86)\Devart\dotConnect\PostgreSQL\)
  • the .NET Standard (.NET Core) Devart.* assemblies which are available via NuGet ( https://www.nuget.org/packages/devart.d ... sql.efcore )
Please make sure that you are using .NET STANDARD Devart.* assemblies with the "Target Framework=.NET Standard 2.0" project.

Post Reply