Skip to content

Object reference not set to an instance of an object When calling a function with Attribute From Test Project #210

@Krummris

Description

@Krummris

I have a package that execute some code when i add the Attribute to a function, it work normally when i execute the project normally, but in the tests i am getting the error:

Outcome: Failed
Error Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at MyProject.DataAnnotations.ExecuteBeforeAttribute.Advise(MethodAsyncAdviceContext context)
at ArxOne.MrAdvice.Utility.ExceptionExtensions.Rethrow(Exception exception)
at ArxOne.MrAdvice.Invocation.GetResult(Task advisedTask, AdviceValues adviceValues)
at ArxOne.MrAdvice.Invocation.<>c__DisplayClass4_0.b__0(Task t)
at ArxOne.MrAdvice.Threading.TaskContinuer1.<>c__DisplayClass0_01.b__0(Task t)
at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

My class in the package

using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using ArxOne.MrAdvice.Advice;
using Microsoft.Extensions.Logging;

namespace MyProject.DataAnnotations;

[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class ExecuteBeforeAttribute(string? description = null) : Attribute, IMethodAsyncAdvice
{
    public string? Description { get; set; } = description;

    public async Task Advise(MethodAsyncAdviceContext context)
    {

        //Execute my operations
        await context.ProceedAsync();
        
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions