I am using the SharpObservation framework to dynamically generate weak event references. When I reference an action from within the delegate I get a TypeAccessException.
Attempt by method 'DynamicClass.Construct(System.EventHandler1<XYZ>, System.Action
11<XYZ>>, System.Delegate)' to access type 'System.Action3c__DisplayClass6,System.Object,XYZ>' failed.
If I remove the action then things work fine. I have even tried commenting out the entire body of the action and it still fails. I believe it has something to do with the compiler created method from the action is private or internal or something so that it can not be accessed from outside. How would I get around this?
Action eventCompleted = () =>
{
SomeMethod();
};
EventHandler<XYZ> eventDelegate = delegate
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(eventCompleted);
};
newItem.Event += eventDelegate.MakeWeak();