'Exception' does not contain a definition for 'Demystify' using Ben.Demystifier library

Viewed 911

I am trying to log exceptions in a better way where we can get human readable stack traces so I found out about this Ben.Demystifier library and it looks promising.

I added this nuget dependency in my application.

<PackageReference Include="Ben.Demystifier" Version="0.1.6" />

Now in my catch block if I do like this then it gives me compilation error -

catch (Exception ex)
{
    Console.WriteLine(ex.Demystify());
}

Error I get -

> 'Exception' does not contain a definition for 'Demystify' and no
> accessible extension method 'Demystify' accepting a first argument of
> type 'Exception' could be found (are you missing a using directive or
> an assembly reference?)

Anything wrong I am doing here?

1 Answers

It looks like in order to leverage the Demystify extension method, you need to do one of two things:

  1. Ensure that the extension class ExceptionExtentions is available by adding a using directive.
using System.Diagnostics;
  1. Call the extension method as a static method by fully qualifying the namespace.
System.Diagnostics.ExceptionExtentions.Demystify(ex);
Related