1

Recently in my WinForm project, I installed MiniProfiler.Windows and write following decorator for my QueryHandlers(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?

Community
  • 1
  • 1
Masoud
  • 8,020
  • 12
  • 62
  • 123

1 Answers1

1

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.

Community
  • 1
  • 1
Yaakov Ellis
  • 40,752
  • 27
  • 129
  • 174
  • I installed Miniprofiler 2.0.2 instead 3.1.1.140, but now I get `An unhandled exception of type 'System.IO.FileNotFoundException' occurred ..` and `{"Could not load file or assembly 'MiniProfiler, Version=3.1.1.140, Culture=neutral, PublicKeyToken=b44f9351044011a3' or one of its dependencies. The system cannot find the file specified.":"MiniProfiler, Version=3.1.1.140, Culture=neutral, PublicKeyToken=b44f9351044011a3"}` – Masoud Aug 06 '14 at 10:37
  • Sounds like you have some web.config assembly binding (or something like that) that is looking for v2.1.1.140 specifically. If you remove those requirements then hopefully it should work (though this is separate from the question above). – Yaakov Ellis Aug 06 '14 at 10:38
  • yes I had assembly binding in my app.config when I fixed it, now I get:`{"Object reference not set to an instance of an object."} at MiniProfiler.Windows.ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings(Int32 includeSqlWithDurationMoreThanMilliseconds, Int32 takeTopNumberOfQueries) ` – Masoud Aug 06 '14 at 11:11
  • Did you step through the code with a debugger and try to figure out where this was happening? – Yaakov Ellis Aug 06 '14 at 11:23