dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.76k stars 3.18k forks source link

System.ExecutionEngineException or System.NullReferenceException in DetectChanges #33763

Closed popcatalin81 closed 5 months ago

popcatalin81 commented 5 months ago

File a bug

I've getting very strange and completely random System.ExecutionEngineException or System.InvalidCastException or System.NullReferenceException

The frequency of these exceptions is extremly high in debug mode and significanly lower in release mode.

Include stack traces

Use triple-tick fences for stack traces. For example:

System.ExecutionEngineException
  HResult=0x80131506
  Message=Exception of type 'System.ExecutionEngineException' was thrown.

Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.GetOriginalValueIndex(Microsoft.EntityFrameworkCore.Metadata.IPropertyBase propertyBase) Line 48   C#
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry entry) Line 231 C#
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager stateManager) Line 143 C#
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges() Line 271   C#
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Internal.InternalDbSet<[redacted].Tenant.Models.Pathway>.Local.get() Line 151   C#
System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'Microsoft.EntityFrameworkCore.Metadata.RuntimeNavigation' to type 'Microsoft.EntityFrameworkCore.Metadata.IProperty'.
  Source=Microsoft.EntityFrameworkCore
  StackTrace:
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.get_Item(IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.CanOverrideCurrentValue(InternalEntityEntry entry, INavigationBase navigation, InternalEntityEntry value, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixup(InternalEntityEntry entry, InternalEntityEntry duplicateEntry, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.TrackedFromQuery(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.TrackedFromQuery(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.MarkUnchangedFromQuery()
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTrackingFromQuery(IEntityType baseEntityType, Object entity, ValueBuffer& valueBuffer)
   at Microsoft.EntityFrameworkCore.Query.QueryContext.StartTracking(IEntityType entityType, Object entity, ValueBuffer valueBuffer)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<PopulateSplitIncludeCollectionAsync>d__26`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<TaskAwaiter>d__36.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.<MoveNextAsync>d__21.MoveNext()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__67`1.MoveNext()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__67`1.MoveNext()
   at [redacted].Services.Batch.BatchProcessors.BatchEventOrderProcessor.<>c__DisplayClass11_0.<<PrepareBatch>b__17>d.MoveNext() in C:\Work\[redacted]\[redacted].Services\Event\Batch\BatchProcessors\04.BatchEventOrderProcessor.cs:line 81

  This exception was originally thrown at this call stack:
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.this[Microsoft.EntityFrameworkCore.Metadata.IPropertyBase].get(Microsoft.EntityFrameworkCore.Metadata.IPropertyBase)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.CanOverrideCurrentValue(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.Metadata.INavigationBase, Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixup(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.TrackedFromQuery(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.TrackedFromQuery(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.MarkUnchangedFromQuery()
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTrackingFromQuery(Microsoft.EntityFrameworkCore.Metadata.IEntityType, object, Microsoft.EntityFrameworkCore.Storage.ValueBuffer)
    Microsoft.EntityFrameworkCore.Query.QueryContext.StartTracking(Microsoft.EntityFrameworkCore.Metadata.IEntityType, object, Microsoft.EntityFrameworkCore.Storage.ValueBuffer)
    Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.PopulateSplitIncludeCollectionAsync<TIncludingEntity, TIncludedEntity>(int, Microsoft.EntityFrameworkCore.Query.RelationalQueryContext, Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy, Microsoft.EntityFrameworkCore.Query.Internal.RelationalCommandCache, System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Storage.ReaderColumn>, bool, Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryResultCoordinator, System.Func<Microsoft.EntityFrameworkCore.Query.QueryContext, System.Data.Common.DbDataReader, object[]>, System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer>, System.Func<Microsoft.EntityFrameworkCore.Query.QueryContext, System.Data.Common.DbDataReader, Microsoft.EntityFrameworkCore.Query.Internal.ResultContext, Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryResultCoordinator, TIncludedEntity>, System.Func<Microsoft.EntityFrameworkCore.Query.QueryContext, Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy, Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryResultCoordinator, System.Threading.Tasks.Task>, Microsoft.EntityFrameworkCore.Metadata.INavigationBase, System.Action<TIncludingEntity, TIncludedEntity>, bool)
    Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.TaskAwaiter(System.Func<System.Threading.Tasks.Task>[])
    ...
    [Call Stack Truncated]
System.AccessViolationException
  HResult=0x80004003
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.EntityFrameworkCore
  StackTrace:
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals(T left, T right)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals(Object left, Object right)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectValueChange(InternalEntityEntry entry, IProperty property)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry, HashSet`1 visited)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry, HashSet`1 visited)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry, HashSet`1 visited)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry, HashSet`1 visited)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.CascadeDelete(InternalEntityEntry entry, Boolean force, IEnumerable`1 foreignKeys)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry.set_State(EntityState value)
   at Microsoft.EntityFrameworkCore.DbContext.Remove[TEntity](TEntity entity)
   at [redacted].DataAccess.Repository.Delete[T](T entity) in C:\Work\[redacted]\DA\[redacted].DataAccess\Repository.cs:line 134
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.EntityFrameworkCore
  StackTrace:
   at Microsoft.EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.GetStoreGeneratedIndex(IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.get_Item(IPropertyBase propertyBase)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.SetForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey, Boolean setModified, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.FixupToPrincipal(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey, Boolean setModified, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixup(InternalEntityEntry entry, InternalEntityEntry duplicateEntry, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.StateChanged(InternalEntityEntry entry, EntityState oldState, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.StateChanged(InternalEntityEntry entry, EntityState oldState, Boolean fromQuery)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.FireStateChanged(EntityState oldState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.SetEntityState(InternalEntityEntry entry, EntityState entityState)
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)
   at [redacted].DataAccess.Repository.Add[T](T entity, Boolean assignTempId) in C:\Work\[redacted]\DA\[redated].DataAccess\Repository.cs:line 80

  This exception was originally thrown at this call stack:
    Microsoft.EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.GetStoreGeneratedIndex(Microsoft.EntityFrameworkCore.Metadata.IPropertyBase)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.this[Microsoft.EntityFrameworkCore.Metadata.IPropertyBase].get(Microsoft.EntityFrameworkCore.Metadata.IPropertyBase)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.SetForeignKeyProperties(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.Metadata.IForeignKey, bool, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.FixupToPrincipal(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.Metadata.IForeignKey, bool, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixup(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.StateChanged(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.EntityState, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.StateChanged(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.EntityState, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.FireStateChanged(Microsoft.EntityFrameworkCore.EntityState)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(Microsoft.EntityFrameworkCore.EntityState, Microsoft.EntityFrameworkCore.EntityState, bool, bool)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(Microsoft.EntityFrameworkCore.EntityState, bool, bool, Microsoft.EntityFrameworkCore.EntityState?, Microsoft.EntityFrameworkCore.EntityState?)
    ...
    [Call Stack Truncated]

Another trace from the logger:

info: [redacted].Services.Batch.BatchEventLoader[0]
      Starting Batch: 8 Loaded Records: 250, Events: 250
Fatal error. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.Metadata.INavigationBase)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager)
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Local()
   at [redacted].Services.Batch.BatchEventProcessor.<CreateConsumer>g__UpdateCache|12_0[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IDictionary`2<System.__Canon,Int32>, Microsoft.EntityFrameworkCore.DbContext, System.Func`2<System.__Canon,System.__Canon>)
   at [redacted].Services.Batch.BatchEventProcessor+<CreateConsumer>d__12.MoveNext()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext(System.Threading.Thread)
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean)
   at System.Threading.Tasks.Task.RunContinuations(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetExistingTaskResult(System.Threading.Tasks.Task`1<System.Threading.Tasks.VoidTaskResult>, System.Threading.Tasks.VoidTaskResult)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
   at [redacted].Infrastructure.LambdaHost.Notification.JobNotificationsService+<NotifyConsole>d__6.MoveNext()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext(System.Threading.Thread)
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean)
   at System.Threading.Tasks.Task.RunContinuations(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetResult(System.__Canon)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsync>d__57.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsync>d__57, Microsoft.AspNetCore.SignalR.Client.Core, Version=8.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ExecutionContextCallback(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsync>d__57, Microsoft.AspNetCore.SignalR.Client.Core, Version=8.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext(System.Threading.Thread)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsync>d__57, Microsoft.AspNetCore.SignalR.Client.Core, Version=8.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean)
   at System.Threading.Tasks.Task.RunContinuations(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetResult(System.__Canon)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsyncCore>d__70.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsyncCore>d__70, Microsoft.AspNetCore.SignalR.Client.Core, Version=8.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ExecutionContextCallback(System.Object)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsyncCore>d__70, Microsoft.AspNetCore.SignalR.Client.Core, Version=8.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext(System.Threading.Thread)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.AspNetCore.SignalR.Client.HubConnection+<InvokeCoreAsyncCore>d__70, Microsoft.AspNetCore.SignalR.Client.Core, Version=8.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ExecuteFromThreadPool(System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

C:\Work\[redacted]\Lambdas\[redacted].Worker.Lambda\bin\Debug\net8.0\[redacted].Worker.Lambda.exe (process 15516) exited with code -1073741795.
Press any key to close this window . . **.**

Include verbose output

Using project directory 'C:\Work[redacted]\DA[redacted]Tenant.DataAccess\'. Remaining arguments: . Finding DbContext classes... Finding IDesignTimeDbContextFactory implementations... Finding application service provider in assembly [redacted].Tenant.DataAccess'... Finding Microsoft.Extensions.Hosting service provider... No static method 'CreateHostBuilder(string[])' was found on class 'Program'. No application service provider was found. Finding DbContext classes in the project... Found DbContext '[redacted]Context'. [redacted].Tenant.DataAccess.[redacted]Context

Include provider and version information

EF Core version: Database provider: Microsoft.EntityFrameworkCore.SqlServer 8.0.5 Target framework: .NET 8.0 Operating system: Windows 10 (Hyper-V VM, Host Windows 11 Pro) IDE: Visual Studio 2022 17.8.3

popcatalin81 commented 5 months ago

Sometimes I get even more nonsensical errors:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type '[redacted].Tenant.Models.EntityPropertyMilestone' to type 'System.Int32'.
  Source=Microsoft.EntityFrameworkCore
  StackTrace:
   at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer`1.Equals(Object left, Object right)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectValueChange(InternalEntityEntry entry, IProperty property)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
   at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
   at Chassi.Services.Batch.QueryProfiler.ProfileProcess(QueryProfilerContext context, Action processingTask, String step) in C:\Work\acsap-connect\Chassi\Chassi.Services\Event\Batch\Profiler\QueryProfiler.cs:line 54

  This exception was originally thrown at this call stack:
    Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer<T>.Equals(object, object)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectValueChange(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry, Microsoft.EntityFrameworkCore.Metadata.IProperty)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry)
    Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager)
    Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
    Chassi.Services.Batch.QueryProfiler.ProfileProcess(Chassi.Services.Batch.QueryProfilerContext, System.Action, string) in QueryProfiler.cs

This makes absolutely no sense to me.

cincuranet commented 5 months ago

Especially the ExecutionEngineException or AccessViolationException suggest problem somewhere deeper than just EF.

But otherwise this issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

popcatalin81 commented 5 months ago

OK, this is was 2 weeks o ordeal just to find out all these was happening from a combination of not having the latest Bios fixes for i9-14900KS and some corrupted system files ... Luckily Intel stepped up with a bios fix.

cincuranet commented 5 months ago

Glad to hear that.