System.MissingMethodException with Miniprofiler.Windows

本文关键字:Windows Miniprofiler with MissingMethodException System | 更新日期: 2023-09-27 18:16:37

最近在我的WinForm项目中,我安装了MiniProfiler。为我的QueryHandler s(我使用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;
    }
}

我得到以下错误在var friendlyString=ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings()线。

类型为"System"的未处理异常。MissingMethodException'发生在iasc . application . core .dll

附加信息:方法未找到:'Boolean StackExchange.Profiling.MiniProfiler.get_HasSqlTimings()'.

有人知道问题在哪里吗?

System.MissingMethodException with Miniprofiler.Windows

MissingMethodException =尝试动态访问未被其强名称(msdn)引用的程序集中已删除或重命名的方法。

或者就像这个答案所说的:

这是一个问题,当有一个旧版本的DLL仍然徘徊在

我注意到MiniProfiler。Windows库正在使用一个非常旧的(超过2年)版本的MiniProfiler。那个版本的代码确实有一个MiniProfiler。HasSqlTimings财产。但是,当前版本(3.0.11)不再具有此属性。

我猜你正在使用MiniProfiler中的代码。你上面链接的Windows库,但不是使用他们保存在/packages中的v2 MiniProfiler dll,你正在使用v3 MiniProfiler dll(可能从nuget下载)。这就解释了你得到的例外。

如果确实是这种情况,那么您可以通过下载版本2.0.2 nuget (Install-Package MiniProfiler -Version 2.0.2)或通过升级ConsoleProfiling中的代码以与MiniProfiler v3兼容来解决这个问题。