【问题标题】:Debug and Release Mode of UWP AppsUWP 应用的调试和发布模式
【发布时间】:2015-12-02 12:05:41
【问题描述】:

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

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

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

函数定义为object IAction.Execute(object sender, object parameter)

当我在调试模式下运行应用程序时,它工作正常并且参数被分配了正确的值。但是当我对 Release 进行配置时,我意识到我的 Behaviors SDK 无法正常工作。

这是之前的代码sn-p:

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 Native 工具链编译时,我会归类为 System.reflection 在发布模式下无法正常工作。当我进行隐式转换时,这不再是问题了。

根据这个视频https://channel9.msdn.com/Shows/Going+Deep/Inside-NET-Native,反射仍然有效,但我不得不为 Behaviors SDK 投射。我想了解更多详细信息并正确理解这一点。

【问题讨论】:

    标签: xaml release uwp


    【解决方案1】:

    在您的项目 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>
    

    您可以查看此链接以获取更多详细信息:

    Reflection and .NET Native

    NET Native Deep Dive: Help! I Hit a MissingMetadataException

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 2015-07-15
      • 2017-03-27
      • 2020-03-01
      • 2013-10-31
      相关资源
      最近更新 更多