I get a missing method Exception when saving
See original GitHub issueDescribe the bug When I save a new record with Entity Framework I get an exception:
Message = “Method not found: ‘System.Threading.Tasks.Task`1<Audit.Core.IAuditScope> Audit.Core.IAuditScopeFactory.CreateAsync(Audit.Core.AuditScopeOptions)’.”
StackTrace =
" at Audit.EntityFramework.DbContextHelper.<CreateAuditScopeAsync>d__17.MoveNext()\r\n at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.Start[TStateMachine](TStateMachine& stateMachine)\r\n at Audit.EntityFramework.DbContextHelper.CreateAuditScopeAsync(IAuditDbContext context, EntityFrameworkEvent efEvent)\r\n at Audit.EntityFramework.DbContextHelper.<SaveChangesGetAuditAsyncImpl>d__26.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Audit.EntityFramework.DbContextHelper.<SaveChangesAsync>d__23.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()\r\n at Cwm.DataLayer.CoreDbContext.<SaveChangesAsync>d__364.MoveNext() in C:\SelfProjects\cw\src\Cwm.DataLayer\CoreDbContext.cs:line 238\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at Cwm.Controllers.ApiV2.UserAuditsV2Controller.<Post>d__4.MoveNext() in C:\\SelfProjects\\cw\\src\\Cwm\\Controllers\\ApiV2\\UserAuditsV2Controller.cs:line 54\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1
1.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()"
To Reproduce In the Db context constructor:
public CoreDbContext(IEncryption encryptionHelper, IUserSession userSession) :
base(encryptionHelper, userSession)
{
_auditContext = new DefaultAuditContext(this);
_helper.SetConfig(_auditContext);
Audit.EntityFramework.Configuration.Setup()
.ForAnyContext(_ => _
.AuditEventType("EF")
.IncludeEntityObjects())
.UseOptOut();
var esUri = new Uri("###ES URL here ###");
var defaultIndex = "supresindex";
var connectionSettings = new Nest.ConnectionSettings(esUri).DefaultIndex(defaultIndex);
var auditDataProvider = new ElasticsearchDataProvider(new ElasticClient(connectionSettings));
Audit.Core.Configuration.Setup()
.UseCustomProvider(auditDataProvider);
//Audit.Core.Configuration.Setup()
// .UseFileLogProvider(_ => _
// .Directory(@"C:\Logs\AuditLogs")
// .FilenameBuilder(ev => $"{ev.StartDate:yyyyMMddHHmmssffff}_{ev.EventType}.json"));
}
In the overridden saveChanges method:
public override async Task<int> SaveChangesAsync()
{
try
{
//return await _helper.SaveChangesAsync(_auditContext, () => base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken));
return await _helper.SaveChangesAsync(_auditContext, () => base.SaveChangesAsync());
//return await base.SaveChangesAsync();
}
catch (DbUpdateException ex)
{
throw HandleDbException(ex);
}
}
Expected behavior I was getting the audit logs as Json files initially : //Audit.Core.Configuration.Setup() // .UseFileLogProvider(_ => _ // .Directory(@“C:\Logs\AuditLogs”) // .FilenameBuilder(ev => $“{ev.StartDate:yyyyMMddHHmmssffff}_{ev.EventType}.json”));
But I’m getting this exception after just installing the - Audit.NET.Elasticsearch package
Libraries (specify the Audit.NET extensions being used including version): For example:
- Audit.NET, Version=21.0.0.0
- Audit.NET.Elasticsearch, Version=21.0.0.0
- Audit.EntityFramework, Version=20.2.4.0
Target .NET framework: For example:
- EntityFramework, Version=EntityFramework.6.4.4
- .NET Framework 4.8
Issue Analytics
- State:
- Created 5 months ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
I’m sorry for not replying. I created a sample application using .net4.8 and EF6 but could not replicate the issue. The exception disappeared after I did a fresh install of all the packages. Thank you for the assistance.
Hello! again, I ran into an issue when writing the audit logs into ES " {“type”:“illegal_argument_exception”,“reason”:“mapper [entityFrameworkEvent.entries.changes.newValue] cannot be changed from type [text] to [ObjectMapper]”} " I’m using Kinesis firehose to write logs into an Amazon Opensearch ES cluster.
I’m guessing this error was caused because the nodes newValue and originalValue have multiple DataTypes. When they were being written into the kibana index, whichever data type got inserted first, that node was mapped to that data type ([text] in this case) and when it attempted to insert the second value of the changes node, it threw the exception as the node had already been mapped to [text] and could not be changed.
Can I Get around this scenario? (Ideally making the originalValue and newValue accept dynamic DataTypes.)
A part of “entityFrameworkEvent” “entries” JSON looks like this:
My Entity class looks somewhat like this:
public class Patient : EntityBase, IHaveEncryptedProperties { public Guid Id { get; private set; } … … public Name Name { get; set; } … }
Where the name class has the First name and last name properties
public class Name : IHaveEncryptedProperties { … [Encrypt] public string FirstName { get; protected set; } [Encrypt] public string MiddleName { get; protected set; } [Encrypt] public string LastName { get; protected set; } … }