2011-03-29 18 views
5

पर पूरे एप्लिकेशन शट डाउन से कैसे बच सकता हूं मेरा एप्लिकेशन बहु-खिड़की है। यदि XamlParseException होता है तो पूरा एप्लिकेशन बंद हो जाता है।मैं XamlParseException

मैं जो करना चाहता हूं, अधिकतम, इस त्रुटि के विंडो को 'जिम्मेदार' बंद कर रहा है।

क्या आप इसे प्राप्त करने का कोई तरीका जानते हैं?

एक अपवाद उदाहरण:

System.Windows.Markup.XamlParseException: Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception. ---> System.Exception: Cannot find resource named 'PasteCommandRef'. Resource names are case sensitive. 
    at System.Windows.StaticResourceExtension.ProvideValueInternal(IServiceProvider serviceProvider, Boolean allowDeferredReference) 
    at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider) 
    at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider) 
    --- End of inner exception stack trace --- 
    at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri) 
    at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter) 
    at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter) 
    at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField) 
    at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren) 
    at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate) 
    at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container) 
    at System.Windows.FrameworkElement.ApplyTemplate() 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Primitives.UniformGrid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
    at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at System.Windows.ContextLayoutManager.UpdateLayout() 
    at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) 
    at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() 
    at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() 
    at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) 
    at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
+6

बेवकूफ उत्तर, लेकिन XamlParseException से परहेज करना इसे संभालने का सबसे अच्छा तरीका होगा। यह एक बहुत ही महत्वपूर्ण अपवाद है (जिसका अर्थ है कि आपके नियंत्रण को प्रारंभ करते समय कुछ बकवास हुआ), इसे अनदेखा करने से आपके यूआई के लुक'फेल को मार दिया जाएगा:/ – Damascus

उत्तर

2

आपके उदाहरण में ऐप क्रैश हो रहा है क्योंकि यह उस संसाधन को नहीं ढूंढ सकता है जिसे आप स्टेटिक स्टेटिक रिसोर्स मार्कअप एक्सटेंशन के माध्यम से संदर्भित करते हैं। आप डब्ल्यूपीएफ को बता रहे हैं कि जब आप इसके लिए जाते हैं तो यह संसाधन बेहतर होता है। तो निश्चित रूप से इसमें एक समस्या होगी।

अपने विशिष्ट उदाहरण को ठीक करने के लिए (संसाधन नहीं मिलने पर अपवाद से परहेज) आप डायनामिक रिसोर्स मार्कअप एक्सटेंशन का उपयोग करने के लिए बदल सकते हैं। यह डब्ल्यूपीएफ को बताएगा कि संसाधन हो सकता है जब यह देखने के लिए जाता है और के लिए अपवाद फेंकने में डब्ल्यूपीएफ अधिक आराम से होगा उदाहरण।

सामान्य रूप से, आपको हमेशा अपने WPF अनुप्रयोग के लिए रूट स्तर अपवाद हैंडलर प्रदान करना चाहिए क्योंकि वेस्ले ने App_HandledExcpetion विधि का उपयोग करके इंगित किया था।

लेकिन XAMLParseException को अंधेरे से निगलने से आपके ऐप में बहुत अधिक समस्याएं पैदा हो रही हैं जो निगलने के अपवादों के साथ डीबग करना मुश्किल होगा।

1

जब से तुम Try..Catch blocks में XAML लपेट नहीं कर सकते, तो आप कोड के माध्यम से डेटा स्रोत को लोड करने की आवश्यकता होगी, लपेट अपवाद हैंडलिंग में है कि, और मान्य डेटा स्रोत मान्य XML है इसे बाध्य करने से पहले।

मुझे लगता है कि, ऐप.एप्लिकेशंस_उन्डहैंडेड अपवाद में, मैं अनचाहे अपवाद भी पकड़ सकता हूं और यह सुरुचिपूर्ण नहीं है।

+0

निष्पादन उदाहरण में, मुझे नहीं पता कि मुझे कहां रखना है कोशिश करें .. ब्लॉक पकड़ो। क्या आपके पास कोई विचार है ? – manuc66

+0

यदि आप 'XAML Try Catch' खोजते हैं, तो यहां एक गुच्छा उदाहरण ऑनलाइन हैं, जैसे http://www.eggheadcafe.com/tutorials/aspnet/5d2dda03-0791-4eca-8a2c-a4d2a2d0244b/exception-handling-made-easy-in -xaml-applications.aspx, और अनचाहे अपवादों के लिए आप try..catch निर्दिष्ट नहीं करते हैं, आप बस ऐप क्लास में ईवेंट को संभालते हैं। – invert