1

I'm just starting using Audit.NET. I download the template from

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

Unfortunately, the project doesn't work. When I post a value, I have an internal server error. The description is quite long but basically the error is

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request. System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.EnumerableExtensions' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.FindSharedTable. RootPrimaryKeyProperty(IProperty property) at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetDefaultColumnName(IProperty property) at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnName(IProperty property) at Audit.EntityFramework.DbContextHelper.GetColumnName(IProperty prop) at Audit.EntityFramework.DbContextHelper.GetColumnValues(IAuditDbContext context, EntityEntry entry) 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

Do you have any ideas? Are there templates projects from ASP.NET or Console?

I have created a repo on GitHub with the project.

Enrico
  • 3,592
  • 6
  • 45
  • 102
  • Is the GITHUB code posted the client or server? The GITHUB code looks like the client with a Controller. Then you said "I have an internal server error". A controller is used to process a response and parse into Entity classes. Your curl code also looks like you are trying to connect to a server. So it looks like the server is no sending a good response and then you get an error in the client processing the bad response. Please ignore the client response error until you first fix the server internal error. – jdweng Dec 29 '20 at 22:15
  • If you run the project, you have Swagger. When you `POST` a new value, the application invoke `Audit.NET` and generate this error. The code is a boilerplate for `Audit.NET`; I only added Swagger – Enrico Dec 29 '20 at 22:35
  • We know nothing about your server nor the response you are getting. The best we can recommend is to handle the exception that occurs when an unexpected response is returned from the server. We cannot fix the root causer of the issue which is the internal server error since we know nothing about the server. All you posted was an exception that occurred when the server return an unexpected response. Not the correct response since the server got an error after you sent the request and before the a good response was returned. – jdweng Dec 30 '20 at 02:15
  • @Enrico the template includes the option `-S` you can use to include Swagger automatically. I was unable to reproduce, did you changed anything on the generated project before building? – thepirat000 Dec 30 '20 at 03:26

1 Answers1

1

I think this is because you are targetting a newer version of EF.Core than the current supported by Audit.EntityFramework.Core which is 3.1.0.

Could you open an issue here?

Update

This was fixed on version 16.3.0, now the library Audit.EntityFramework.Core is compatible with EF Core 5.0.1

thepirat000
  • 12,362
  • 4
  • 46
  • 72
  • 1
    Done https://github.com/thepirat000/Audit.NET/issues/352 – Enrico Dec 30 '20 at 10:55
  • 1
    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/ – Enrico Jan 04 '21 at 14:12