Actually it is very strange exception, because it happens only when I build the project as Release and does not happen at all when I choose Debug. In debug mode, the app works perfect and the following code works well.
Here is the code of my extension method:
public static T DeepClone<T>(this T source) where T : UIElement
{
T result;
// Get the type
Type type = source.GetType();
// Create an instance
result = Activator.CreateInstance(type) as T; //throws exception here only if I build project as (release)
CopyProperties<T>(source, result, type);
DeepCopyChildren<T>(source, result);
return result;
}
The exception is:
An exception of type 'System.MissingMethodException' occurred in System.Private.Reflection.Execution.dll but was not handled in user code
Additional information: MissingConstructor_Name, Windows.UI.Xaml.Controls.RelativePanel. For more information, visit http://go.microsoft.com/fwlink/?LinkId=623485
I've found some related questions to this exception, but they all are pointing to missing libraries or update libraries like this but didn't change anything in my app.