Jimmy W
Jimmy W

Reputation: 539

In the Portable Class Library, can I inherit from a class whose Silverlight definition has an empty constructor not found in the .NET Framework?

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:

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

Upvotes: 2

Views: 325

Answers (1)

David Kean
David Kean

Reputation: 5772

What is the repro for this? We don't expose the default constructor of WeakReference in the RTM bits of Visual Studio 2012 for this very reason. What build are you using?

Upvotes: 1

Related Questions