MissingMethodException for OnEntry for unit test.

geoffhin's Avatar

geoffhin

28 Nov, 2017 06:22 PM

I'm getting exceptions when trying to run unit tests on aspects.

System.MissingMethodException occurred Message=Method not found: 'Void AspectedLogging.LogMethodAttribute.OnEntry(PostSharp.Aspects.MethodExecutionArgs)'.

Here is the implementation:

[PSerializable]
    public class LogMethodAttribute : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args)
        {
            Debug.WriteLine("Test OnEntry");
        }
        public override void OnSuccess(MethodExecutionArgs args)
        {
            Debug.WriteLine("Test OnSuccess");
        }
    }

Here is a simple unit test to validate that the methods are called

    [TestFixture]
    public class AspectLoggerUnitTest
    {  
        [LogMethod]
        public void AspectedMethodSuccess()
        {
            Debug.WriteLine("I'm a test method, designed for SUCCESS");
        }

        [Test]
        public void TestAspectSuccessShouldSucceed()
        {
            AspectedMethodSuccess();
        }        
    }

Inspecting the IL reveals that PostSharp is weaving the methods in.

// AspectLogging.UnitTests.AspectLoggerUnitTest
public void AspectedMethodSuccess()
{
    MethodExecutionArgs methodExecutionArgs = new MethodExecutionArgs(null, null);
    <>z__a_1.a0.OnEntry(methodExecutionArgs);
    Debug.WriteLine("I'm a test method, designed for SUCCESS");
    <>z__a_1.a0.OnSuccess(methodExecutionArgs);
}

Is there some issue with unit tests that is preventing this from working? I'm hoping to share this logging attribute across multiple services, so this has me a bit concerned.

  1. Support Staff 1 Posted by PostSharp Techn... on 29 Nov, 2017 03:36 PM

    PostSharp Technologies's Avatar

    Hello,

    I wasn't able to reproduce your issue, unfortunately. I have tried with Visual Studio 2017, NUnit 3 and PostSharp 5.0.39. Do you have a different configuration?

    Couldn't you send me a reproduction project, please?

    For logging, you can also use our ready-made Diagnostics Framework, see https://www.postsharp.net/diagnostics.

    Best regards,
    -tony

  2. 2 Posted by geoffhin on 29 Nov, 2017 11:15 PM

    geoffhin's Avatar

    Thanks Toni,

    I'll try a new project and see if it happens again. If so, I'll share it.

  3. Support Staff 3 Posted by PostSharp Techn... on 13 Dec, 2017 02:50 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  4. PostSharp Technologies closed this discussion on 13 Dec, 2017 02:50 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac