question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with Microsoft.EntityFrameworkCore 5.0.1

See original GitHub issue

Describe the bug I created a new project using

dotnet new -i Audit.WebApi.Template
dotnet new webapiaudit -E -S

I updated the dependencies. Now the project is using Microsoft.EntityFrameworkCore 5.0.1. I ran the project and insert a new record. I created a repo on GtHub.

I received an error:

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at Audit.EntityFramework.DbContextHelper.IsRelational(DbContext dbContext)
   at Audit.EntityFramework.DbContextHelper.CreateAuditEvent(IAuditDbContext context)
   at Audit.EntityFramework.DbContextHelper.SaveChangesAsync(IAuditDbContext context, Func`1 baseSaveChanges)
   at Projects.Providers.ValuesProvider.InsertAsync(String value) in C:\Projects\AuditNetWebapi\Providers\ValuesProvider.cs:line 32
   at Projects.Controllers.ValuesController.Post(String value) in C:\Projects\AuditNetWebapi\Controllers\ValuesController.cs:line 40
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Audit.WebApi.AuditMiddleware.InvokeNextAsync(HttpContext context, Boolean includeResponseBody, Boolean includeResponseHeaders)
   at Audit.WebApi.AuditMiddleware.InvokeNextAsync(HttpContext context, Boolean includeResponseBody, Boolean includeResponseHeaders)
   at Audit.WebApi.AuditMiddleware.InvokeAsync(HttpContext context)
   at Projects.Startup.<>c.<<Configure>b__5_0>d.MoveNext() in C:\Projects\AuditNetWebapi\Startup.cs:line 53
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)


Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An exception was thrown attempting to display the error page.

System.ObjectDisposedException: Cannot access a closed Stream.
   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.MemoryStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.IO.Pipelines.StreamPipeWriter.FlushAsyncInternal(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Error: Connection ID "18374686502757072929", Request ID "80000024-0005-ff00-b63f-84710c7967bb": An unhandled exception was thrown by the application.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at Audit.EntityFramework.DbContextHelper.IsRelational(DbContext dbContext)
   at Audit.EntityFramework.DbContextHelper.CreateAuditEvent(IAuditDbContext context)
   at Audit.EntityFramework.DbContextHelper.SaveChangesAsync(IAuditDbContext context, Func`1 baseSaveChanges)
   at Projects.Providers.ValuesProvider.InsertAsync(String value) in C:\Projects\AuditNetWebapi\Providers\ValuesProvider.cs:line 32
   at Projects.Controllers.ValuesController.Post(String value) in C:\Projects\AuditNetWebapi\Controllers\ValuesController.cs:line 40
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Audit.WebApi.AuditMiddleware.InvokeNextAsync(HttpContext context, Boolean includeResponseBody, Boolean includeResponseHeaders)
   at Audit.WebApi.AuditMiddleware.InvokeNextAsync(HttpContext context, Boolean includeResponseBody, Boolean includeResponseHeaders)
   at Audit.WebApi.AuditMiddleware.InvokeAsync(HttpContext context)
   at Projects.Startup.<>c.<<Configure>b__5_0>d.MoveNext() in C:\Projects\AuditNetWebapi\Startup.cs:line 53
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()


Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Error: Connection ID "18374686502757072929", Request ID "80000024-0005-ff00-b63f-84710c7967bb": An unhandled exception was thrown by the application.

System.ObjectDisposedException: Cannot access a closed Stream.
   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.MemoryStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.IO.Pipelines.StreamPipeWriter.FlushAsyncInternal(CancellationToken cancellationToken)
   at System.IO.Pipelines.StreamPipeWriter.CompleteAsync(Exception exception)
   at Microsoft.AspNetCore.Http.StreamResponseBodyFeature.CompleteAsync()
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.FireOnCompleted()

To Reproduce I created a repo on GtHub. Look also to Stackoverflow.

Libraries (specify the Audit.NET extensions being used including version): For example:

  • Audit.WebApi: 16.2.1
  • Audit.EntityFramework: 16.2.1

Target .NET framework:

  • .NET Core 3.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
erossinicommented, Jan 4, 2021

I created a post where I implement an audit system with Audit.NET step-by-step https://www.puresourcecode.com/dotnet/net-core/audit-with-entity-framework-core/

1reaction
erossinicommented, Dec 31, 2020

Thank you, it is working now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuget error: Package Microsoft.EntityFrameworkCore 5.0.1 ...
I'd start by checking which .NET SDK is installed on the machines where this failure occurs. Try cleaning/removing all SDKs and installing the ......
Read more >
Microsoft.EntityFrameworkCore 5.0.1
Version Downloads Last updated 8.0.0‑preview.7.23375.4 8,798 12 days ago 8.0.0‑preview.6.23329.4 33,243 a month ago 8.0.0‑preview.5.23280.1 45,568 2 months ago
Read more >
'EntityFramework.Core.Tools' nuget package installation error
While installing the package Microsoft.EntityFrameworkCore.Tools for using EF in my project using Nuget, I'm persistently running into the ...
Read more >
Unable to install a few NuGets on .net 5 in a new vanilla ...
these install fine with my new vanilla 5.0 project.. dotnet add %1 package Microsoft.AspNetCore.Identity.EntityFrameworkCore -v 5.0.9 dotnet add ...
Read more >
Type Load Exception in EF Core Project
I had this issue in a .NET Core 3.1 project. I fixed it by installing the package Microsoft.EntityFrameworkCore.Design in the startup ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found