Exception in App Domain usage since VS2015

Topics: C# Language Design, General
Nov 19, 2014 at 8:12 AM
I got the following Exception

A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in MCC.Services.CommonServiceHost.dll

Additional information: Der Typ "MCC.Services.CommonServiceHost.MCCHost+<>c__DisplayClass0" in Assembly "MCC.Services.CommonServiceHost, Version=, Culture=neutral, PublicKeyToken=null" ist nicht als serialisierbar gekennzeichnet.

On this line of Code:
                AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
                        var ex = e.ExceptionObject as Exception;
                        LoggerFactory.CreateLogger("UnhandledException").Error("A Unhandled - Exception ocured", ex);
                        Console.WriteLine("UnhandledException! -> " + ((Exception)e.ExceptionObject).Message + "\n" + "-> see logfile for mor details");

                TaskScheduler.UnobservedTaskException += (object sender, UnobservedTaskExceptionEventArgs excArgs) =>

                    Console.WriteLine("UnobservedTaskException! -> " + excArgs.Exception.Message + "\n" + "-> see logfile for mor details");
                    LoggerFactory.CreateLogger("UnhandledException").Error("A Unhandled - Exception ocured", excArgs.Exception);
But it now also don't work compiled with SD and VS2013 so it's seems a Framework change is causing this issue!
Dec 29, 2014 at 10:33 AM
I fixed it be creating a static method of the Lambda! But don't know why it worked before!