In one of my ClickOnce applications I get an System.MethodAccessException
when I try to subscripe to AppDomain.CurrentDomain.UnhandledException
My initializations code look like this:
App.xaml:
<mylib:MyApplicationBase x:Class="MyApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApplication"
xmlns:mylib="clr-namespace:MyLib;assembly=MyLib"
>
</mydll:MyApplicationBase>
App.xaml.cs:
namespace MyApplication
{
public partial class App : MyApplicationBase
{
public App()
{
var domain = AppDomain.CurrentDomain;
// exception in next line
domain.UnhandledException += OnUnhandledException;
}
public void OnUnhandledException(object sender, UnhandledExceptionEventArgs eventArgs)
{
// todo
}
}
}
and in another assembly: MyApplicationBase.cs
namespace MyLib
{
public class MyApplicationBase : System.Windows.Application
{
// Some more code but no explicit constructor definitions
}
}
The code run fine on same machine if not installed by ClickOnce
I use a similar approach in other applications without problems
I got the System.MethodAccessException
instead of the underlying problem. Because the appliaction had Project Properties Security set to:
So the approach I took was: