1

我收到来自远程登录应用程序的用户的错误报告。该应用程序运行良好,直到他们回到办公室并直接登录到他们的桌面 - 应用程序崩溃并且错误报告是标准的“可冻结不能被冻结”,但没有一个已知的解决方法可以解决这个问题。

应用程序中的每个 Brush 资源都用 ice:Freeze 装饰:

<SolidColorBrush ice:Freeze="true" 

此外,异常作为域未处理的异常被抛出,因此现在有办法吞下它。

在过去的几个月里,我花了几个小时分析 Freezables 机器人报告的问题,但找不到任何解决方案。

发生问题的 .NET 代码:

    /// <summary>
    ///     Unbinds a Freezable from its Context.
    /// </summary>
    /// <param name="resource">The resource to freeze.</param>
    private static void Freeze(object resource)
    {
        Freezable freezable = resource as Freezable;
        if (freezable != null && !freezable.IsFrozen)
        {
            freezable.Freeze();
        }
    }

    /// <summary>
    ///     Searches for a resource inside a ResourceDictionary.
    /// </summary>
    /// <param name="key">The original key.</param>
    /// <param name="typeKey">The key cast to Type.</param>
    /// <param name="resourceKey">The key cast to ResourceKey.</param>
    /// <param name="isTraceEnabled">Tracing on/off.</param>
    /// <param name="allowDeferredResourceReference">
    ///     If this flag is true the resource will not actually be inflated from Baml.
    ///     Instead we will return an instance of DeferredDictionaryReference which
    ///     can later be used to query the resource
    /// </param>
    /// <param name="mustReturnDeferredResourceReference">
    ///     If this method is true this method will always return a
    ///     DeferredThemeResourceReference instance which envelopes the underlying resource.
    /// </param>
    /// <param name="canCache">Whether callers can cache the value.</param>
    /// <returns></returns>
    private static object FindDictionaryResource(
        object      key,
        Type        typeKey,
        ResourceKey resourceKey,
        bool        isTraceEnabled,
        bool        allowDeferredResourceReference,
        bool        mustReturnDeferredResourceReference,
        out bool    canCache)
    {
        // Thread safety handled by FindResourceInternal. Be sure to have locked _resourceCache.SyncRoot.

        Debug.Assert(typeKey != null || resourceKey != null, "typeKey or resourceKey should be non-null");

        canCache = true;
        object resource = null;
        Assembly assembly = (typeKey != null) ? typeKey.Assembly : resourceKey.Assembly;

        if ((assembly == null) || IgnoreAssembly(assembly))
        {
            // Without an assembly, we can't figure out which dictionary to look at.
            // Also, ignore some common assemblies we know to not contain resources.
            return null;
        }

        ResourceDictionaries dictionaries = EnsureDictionarySlot(assembly);
        ResourceDictionary dictionary = dictionaries.LoadThemedDictionary(isTraceEnabled);
        if (dictionary != null)
        {
            resource = LookupResourceInDictionary(dictionary, key, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);
        }

        if (resource == null)
        {
            dictionary = dictionaries.LoadGenericDictionary(isTraceEnabled);
            if (dictionary != null)
            {
                resource = LookupResourceInDictionary(dictionary, key, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);
            }
        }

        if (resource != null)
        {
            // Resources coming out of the dictionary may need to be frozen
            Freeze(resource);
        }

        return resource;
    }

System.InvalidOperationException:无法冻结此 Freezable。在 System.Windows.Freezable.Freeze() 在 System.Windows.SystemResources.Freeze(对象资源) 在 System.Windows.SystemResources.FindDictionaryResource(对象键,类型 typeKey,ResourceKey resourceKey,布尔 isTraceEnabled,布尔 allowDeferredResourceReference,布尔 mustReturnDeferredResourceReference,布尔& canCache) 在 System.Windows.SystemResources.FindResourceInternal(Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference) 在 System.Windows.FrameworkElement.FindResourceInternal(FrameworkElement fe, FrameworkContentElement fce, DependencyProperty dp, Object resourceKey, Object unlinkedParent, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, DependencyObject 边界元素,1 dataField, ItemStructList1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructListSystem.Windows.StyleHelper.GetChildValue(UncommonField 1& childRecordFromChildIndex、EffectiveValueEntry& 条目、ValueLookupType& sourceType、FrameworkElementFactory templateRoot)处的1& valueLookupList、DependencyProperty dp、DependencyObject 容器、FrameworkObject 子项、Int32 childIndex、Boolean styleLookup、EffectiveValueEntry& 条目、ValueLookupType & sourceType、FrameworkElementFactory templateRoot) System.Windows.StyleHelper.GetValueFromTemplatedParent(DependencyObject 容器,Int32 childIndex,FrameworkObject 子项,DependencyProperty dp,FrugalStructList 1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry) at System.Windows.FrameworkElement.GetValueFromTemplatedParent(DependencyProperty dp, EffectiveValueEntry& entry) at System.Windows.FrameworkElement.GetRawValue(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& entry) at System.Windows.FrameworkElement.EvaluateBaseValueCore(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& newEntry) at System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType) at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp) at System.Windows.StyleHelper.InvalidateResourceDependentsForChild(DependencyObject container, DependencyObject child, Int32 childIndex, ResourcesChangeInfo info, FrameworkTemplate parentTemplate) at System.Windows.TreeWalkHelper.InvalidateStyleAndReferences(DependencyObject d, ResourcesChangeInfo info, Boolean containsTypeOfKey) at System.Windows.TreeWalkHelper.OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, Boolean raiseResourceChangedEvent) at System.Windows.TreeWalkHelper.OnResourcesChangedCallback(DependencyObject d, ResourcesChangeInfo info) at System.Windows.DescendentsWalker1._VisitNode(DependencyObject d)在 System.Windows.DescendentsWalker 1.VisitNode(FrameworkElement fe) at System.Windows.DescendentsWalker1.VisitNode(DependencyObject d)在 System.Windows.DescendentsWalker1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) at System.Windows.DescendentsWalker1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) 在 System.Windows.DescendentsWalker 1.IterateChildren(DependencyObject d) at System.Windows.DescendentsWalker1._VisitNode(DependencyObject d) 在 System.Windows.DescendentsWalker 1.VisitNode(FrameworkElement fe) at System.Windows.DescendentsWalker1.VisitNode(DependencyObject d) 在 System.Windows.DescendentsWalker 1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) at System.Windows.DescendentsWalker1.IterateChildren(DependencyObject d) 在System.Windows.DescendentsWalker 1._VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.VisitNode(FrameworkElement fe) 在 System.Windows.DescendentsWalker 1.VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) 在 System.Windows.DescendentsWalker 1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) at System.Windows.DescendentsWalker1.IterateChildren(DependencyObject d) 在 System.Windows.DescendentsWalker 1._VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.VisitNode(FrameworkElement fe) 在 System.Windows.DescendentsWalker1.VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) 在 System.Windows.DescendentsWalker 1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) at System.Windows.DescendentsWalker1.IterateChildren(DependencyObject d) 在 System.Windows.DescendentsWalker 1._VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.VisitNode(FrameworkElement fe) 在 System.Windows.DescendentsWalker 1.VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumeratorlogicalChildren) 在 System.Windows.DescendentsWalker 1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) at System.Windows.DescendentsWalker1.IterateChildren(DependencyObject d) 在 System.Windows.DescendentsWalker 1._VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.VisitNode(FrameworkElement fe) 在 System.Windows.DescendentsWalker 1.VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) 在 System.Windows.DescendentsWalker1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) at System.Windows.DescendentsWalker1.IterateChildren(DependencyObject d) 在 System.Windows.DescendentsWalker 1._VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.VisitNode(FrameworkElement fe) 在 System.Windows.DescendentsWalker 1.VisitNode(DependencyObject d) at System.Windows.DescendentsWalker1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) 在 System.Windows.DescendentsWalker1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren) at System.Windows.DescendentsWalker1.IterateChildren(DependencyObject d) at System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode) at System.Windows.TreeWalkHelper.InvalidateOnResourcesChange(FrameworkElement fe, FrameworkContentElement fce, ResourcesChangeInfo info) 在 System.Windows.SystemResources.InvalidateTreeResources (Object args) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

4

0 回答 0