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.

I get a missing method Exception when saving

See original GitHub issue

Describe 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.TaskAwaiter1.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__11.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:closed
  • Created 5 months ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shubhamCedargatecommented, Apr 28, 2023

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.

0reactions
shubhamCedargatecommented, May 11, 2023

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:

         "action":"Update",
         "changes":[
            {
               "columnName":"Name",
               "originalValue":{
                  "firstName":"Robin",
                  "lastName":"Scherbatsky",
                  "firstNameDecrypted":"Robin",
                  "lastNameDecrypted":"Scherbatsky",
                  "nameDecrypted":true
               },
               "newValue":{
                  "firstName":"ENCRYPTED_STRING_HERE",
                  "lastName":"ENCRYPTED_STRING_HERE",
                  "firstNameDecrypted":"Robin Sparkles",
                  "lastNameDecrypted":"Scherbatsky",
                  "nameDecrypted":true
               }
            },
            {
               "columnName":"NameHash",
               "originalValue":"ENCRYPTED_STRING_HERE",
               "newValue":"ENCRYPTED_STRING_HERE"
            }
         ]

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; } … }

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.MissingMethodException: Method not found?
This is a problem which can occur when there is an old version of a DLL still lingering somewhere around. Make sure that...
Read more >
MissingMethodException Class (System)
MissingMethodException is thrown when code in a dependent assembly attempts to access a missing method in an assembly that was modified. MissingMethodException ......
Read more >
MissingMethodException / "Method not found" after update ...
MissingMethodException s usually indicate that you have old DLLs lurking around somewhere that are not binary-compatible with the version ...
Read more >
Type: System.MissingMethodException
MissingMethodException is thrown when code in a dependent assembly attempts to access a missing method in an assembly that was modified. MissingMethodException ......
Read more >
MissingMethodException: Method not Found ASP.NET CORE
In this video, I am going to fix this issue in ASP.NET CORE: MissingMethodException : Method not Found: System.
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