Xaml UWP应用程序的调试和发布模式

Xaml UWP应用程序的调试和发布模式,xaml,release,uwp,Xaml,Release,Uwp,我试图理解我在处理UWP应用程序时遇到的一个问题。我能够解决这个问题,但我仍然不清楚背后的解释/理由 我正在代码库中使用XAMLBehaviors SDK中的“EventTriggerBehavior”。此事件用于检查GridView的“ClickedItem” 来自Microsoft.Xaml.Interactivity的IAction.Execute方法获取ClickedItem事件作为参数 object propertyValue = parameter as ItemClickEvent

我试图理解我在处理UWP应用程序时遇到的一个问题。我能够解决这个问题,但我仍然不清楚背后的解释/理由

我正在代码库中使用XAMLBehaviors SDK中的“EventTriggerBehavior”。此事件用于检查GridView的“ClickedItem”

来自Microsoft.Xaml.Interactivity的IAction.Execute方法获取ClickedItem事件作为参数

object propertyValue = parameter as ItemClickEventArgs;
函数定义为object IAction.Execute(对象发送方,对象参数)

当我在调试模式下运行应用程序时,它工作正常,参数得到了正确的赋值。但当我配置发布时,我意识到我的行为SDK不能正常工作

这是前面的代码片段:

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);
        }
    }
在进一步的调查中,我意识到propertyValue并没有用正确的值初始化。因此,为了解决这个问题,我对参数执行了类型转换

object propertyValue = parameter as ItemClickEventArgs;
现在一切都开始在发布模式下正常工作,包括启用代码优化时

我会将其归类为该系统。当启用使用.NET本机工具链编译时,反射在发布模式下无法正常工作。当我做隐式演员时,这不再是一个问题


根据这段视频,反射仍然有效,但我必须为行为SDK投稿。我想知道更多的详细信息并正确理解这一点。

在您的项目uwp中,您可以找到一个名为Default.rd.xml的文件(位于Properties文件夹内)。这是一个配置文件,用于指定在启用.net native时指定的程序元素是否可用于反射

在您的情况下,可以添加以下声明以添加ItemClickEventArgs类型。如果需要,可以选择声明名称空间而不是类型

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <!--
      An Assembly element with Name="*Application*" applies to all assemblies in
      the application package. The asterisks are not wildcards.
    -->
    <Assembly Name="*Application*" Dynamic="Required All"/>

    <!-- Add your application specific runtime directives here. -->
    <Type Name="Windows.UI.Xaml.Controls.ItemClickEventArgs" Browse="Required Public"/>

  </Application>
</Directives>