title: dotnet core 2: Serializing delegates is not supported on this platform
body: <p>I am trying to pass the scope (or <code>this</code>) to my custom exception and show it gracefully. My code was working until I added the scope property to the custom exception. I see others have encountered this issue (<a href="https://github.com/dotnet/corefx/issues/23415" rel="nofollow noreferrer">link1</a>, <a href="https://github.com/pardahlman/RawRabbit/issues/286" rel="nofollow noreferrer">link2</a>, <a href="https://github.com/JamesNK/Newtonsoft.Json/issues/1404" rel="nofollow noreferrer">link3</a>) but no solution. Any solution or workaround would be appreciated. Thank you.</p>
  
  <p>My custom exception:</p>
  
  <pre><code>  public class CustomException : Exception
    {
      private readonly object _scope;
  
      public CustomException(string message, object scope = null) : base(message)
      {
        _scope = scope;
      }
  
      public override void GetObjectData(SerializationInfo info, StreamingContext context)
      { 
        info.AddValue("Scope", _scope);
  
        base.GetObjectData(info, context);
      }
    }
  </code></pre>
  
  <p>How I use the exception:</p>
  
  <p><code>throw new InvalidCustomCapsBadSumException("Error message is here!, this);</code></p>
  
  <p>Startup.cs:</p>
  
  <pre><code>services.AddMvc(config =&gt;
  {
      config.Filters.Add(typeof(ExceptionFilterAttribute)); 
  }).AddJsonOptions(x =&gt;
  {
      // ignore circular loops while deserializing
      x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  });
  </code></pre>
  
  <p>ExceptionFilterAttribute.cs:</p>
  
  <pre><code>public class ExceptionFilterAttribute :  IExceptionFilter
  {        
      public void OnException(ExceptionContext context)
      {
          context.Result = new BadRequestObjectResult(new
          {
              Exception = context.Exception
          });
      }
  }
  </code></pre>
  
  <p>Error I am getting:</p>
  
  <pre><code>An unhandled exception was thrown by the application.
  System.Runtime.Serialization.SerializationException: Serializing delegates is not supported on this platform.
     at System.MulticastDelegate.GetObjectData(SerializationInfo info, StreamingContext context)
  </code></pre>