I am trying to understand this one issue which I faced when I was working on UWP applications. I was able to fix this issue but I am still not clear with the explanation/reasoning behind it.
I am using "EventTriggerBehavior" from XAMLBehaviours SDK in my codebase. This event was to check for "ClickedItem" of GridView.
IAction.Execute Method from Microsoft.Xaml.Interactivity gets the ClickedItem event as parameter.
The function definition is object IAction.Execute( object sender, object parameter )
When I was running the app in Debug mode,this was working fine and parameter was getting the correct values assigned. But when I did my configuration to Release, I realized that my Behaviors SDK is not working correctly.
This was the previous code snippet:
object IAction.Execute(object sender, object parameter)
{
object propertyValue = parameter;
foreach (var propertyPathPart in propertyPathParts)
{
var propInfo = propertyValue.GetType().GetTypeInfo().GetDeclaredProperty(propertyPathPart);
if (propInfo != null)
propertyValue = propInfo.GetValue(propertyValue);
}
}
On further investigation, I realized that propertyValue does not get initialized with the correct value. Hence, to fix this, I did Type Cast on parameter.
object propertyValue = parameter as ItemClickEventArgs;
Now everything started working fine in Release Mode including when code optimization is enabled.
I would classify into that System.reflection was not working fine in Release mode when Compile with .NET Native tool chain was enabled. When I did Implicit cast, it wasnt a problem anymore.
According to this video https://channel9.msdn.com/Shows/Going+Deep/Inside-NET-Native, Reflection still works yet I had to cast for Behaviors SDK. I would like to know more detailed info for this and understand this properly.