简体   繁体   中英

System.MissingMethodException with Miniprofiler.Windows

Recently in my WinForm project, I installed MiniProfiler.Windows and write following decorator for my QueryHandler s(I'm using CQRS ):

public class MiniProfilerQueryHandlerDecorator<TQuery,TResult>:IQueryHandler<TQuery,TResult> where TQuery : IQueryParameter<TResult>
{
    private readonly IQueryHandler<TQuery, TResult> _decoratee;

    public MiniProfilerQueryHandlerDecorator(IQueryHandler<TQuery, TResult> decoratee)
    {
        _decoratee = decoratee;
    }

    public TResult Handle(TQuery request)
    {
        TResult result;
        using (StackExchange.Profiling.MiniProfiler.Current.Step("Call QueryHandler"))
        {
            result =_decoratee.Handle(request); //call some Linq to entity queries
        }
        var friendlyString = ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings();
        Debug.WriteLine(friendlyString);
        return result;
    }
}

I get following error at var friendlyString=ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings() line.

An unhandled exception of type 'System.MissingMethodException' occurred in IASCo.Application.Core.dll

Additional information: Method not found: 'Boolean StackExchange.Profiling.MiniProfiler.get_HasSqlTimings()'.

Does anyone know where is the problem?

MissingMethodException = an attempt is made to dynamically access a deleted or renamed method of an assembly that is not referenced by its strong name ( msdn ).

Or as this answer puts it:

This is a problem which can occur when there is an old version of a DLL still lingering somewhere around

I notice that the MiniProfiler.Windows library is using a very old (over 2 years) version of MiniProfiler. That version of the code did indeed have a MiniProfiler.HasSqlTimings property. However, the current version (3.0.11) no longer has this property.

I am guessing that you are using the code from the MiniProfiler.Windows library that you linked above, but instead of using the v2 MiniProfiler dll that they have saved in /packages , you are using a v3 MiniProfiler dll (maybe downloaded from nuget). This would explain the exception that you are getting.

If this is indeed the case, then you can solve this by either downloading the version 2.0.2 nuget ( Install-Package MiniProfiler -Version 2.0.2 ) or by upgrading the code in ConsoleProfiling to be compatible with MiniProfiler v3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM