We have a class, WeakRef, that inherits from WeakReference. This class was originally part of a namespace that targets the standard .NET framework. Recently, we have migrated to .NET 4.5 and decided utilize the Portable Class Library. We included WeakRef, but referencing it in our Silverlight application has led to the following runtime exception:
$exception {System.TypeInitializationException: The type initializer for 'AxisModel.ImageDownloadAlert' threw an exception. ---> System.TypeLoadException: Inheritance security rules violated by type: 'Common.WeakRef`1'. Derived types must either match the security accessibility of the base type or be less accessible. If the base class has a non-transparent default constructor, the derived class must also have a default constructor, and the method inheritance rules apply across those two methods.
at Common.WeakRefCallbackHostCore`1..ctor(Object syncRoot)
at AxisModel.ImageDownloadAlert..ctor()
at AxisModel.ImageDownloadAlert..cctor()--- End of inner exception stack trace ---
at AxisModel.ImageDownloadAlert.get_Instance()
at SLWebApp.App..ctor()}System.Exception {System.TypeInitializationException}
I noticed that the Silverlight version of WeakReference has an empty default constructor, which is not the case in the standard .NET version of WeakReference. I think that this is the reason for the thrown exception, since WeakRef does not contain an empty constructor. The problem is that adding an empty constructor to this class will lead to compilation errors in our WPF applications.
Is there a way to share WeakRef between our Silverlight and WPF applications without leading to runtime and compilation errors? I'm looking for minimally invasive solutions.
UPDATE:
There has been some discussion regarding inheriting WeakReference in Silverlight. Apparently, it's not possible so one would have to create a class that contains a WeakReference instance instead. However, irregardless of whether WeakReference is involved, would it be possible to inherit from a class similar to WeakReference in that its Silverlight definition has an empty default constructor whereas its .NET Framework definition does not?
The discussion can be found here:
Inherited WeakReference throwing ReflectionTypeLoadException in Silverlight
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog