简体   繁体   English

带有Miniprofiler.Windows的System.MissingMethodException

[英]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 ): 最近在我WinForm项目,我安装MiniProfiler.Windows和写入以下装饰我的QueryHandler秒(我使用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. 我在var friendlyString=ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings()行中收到以下错误。

An unhandled exception of type 'System.MissingMethodException' occurred in IASCo.Application.Core.dll IASCo.Application.Core.dll中发生了类型为'System.MissingMethodException'的未处理异常

Additional information: Method not found: 'Boolean StackExchange.Profiling.MiniProfiler.get_HasSqlTimings()'. 附加信息:找不到方法:“ 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 ). MissingMethodException =试图动态访问程序集的删除或重命名方法,而该程序集的强名( 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 当仍然有旧版本的DLL徘徊时,可能会出现此问题

I notice that the MiniProfiler.Windows library is using a very old (over 2 years) version of MiniProfiler. 我注意到MiniProfiler.Windows库使用的是非常旧(超过2年)的MiniProfiler版本。 That version of the code did indeed have a MiniProfiler.HasSqlTimings property. 该版本的代码确实确实具有MiniProfiler.HasSqlTimings属性。 However, the current version (3.0.11) no longer has this property. 但是,当前版本(3.0.11)不再具有此属性。

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). 我猜想您正在使用上面链接的MiniProfiler.Windows库中的代码,但不是使用v3 MiniProfiler dll(可能是从nuget下载),而是使用了它们保存在/ packages中的v2 MiniProfiler dll。 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. 如果确实如此,则可以通过下载2.0.2 nuget版本( Install-Package MiniProfiler -Version 2.0.2 )或通过升级ConsoleProfiling的代码以与ConsoleProfiling v3兼容来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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