Friday, March 9, 2012

Defining an event inside of an assembly => UNSAFE (no workarounds?)

Can someone verify that an assembly containing an interface with an event definition, such as...

public interface A {
event EventHandler Foo;
}

... can never be loaded under SAFE or EXTERNAL_ACCESS ?

It appears that the compiler-generated add_xxx and remove_xxx have the MethodImpl(MethodImplOptions.Synchronized) attribute defined by default, and "Explicit synchronization is not allowed". The same limitation also applies to classes by default, although technically one is able to define the implementation directly (clearly not ideal).

That's exactly correct. There is some possibility in the future that the CLR could change the way they implement EventHandler synchronization to allow it in non-unsafe assemblies, but for now that is the restricition.

Steven

No comments:

Post a Comment