From af2a634503eed2f4e8ab146b23294dce34a333f5 Mon Sep 17 00:00:00 2001 From: Bill Hally Date: Fri, 6 Dec 2019 22:14:11 +0000 Subject: [PATCH] Explicitly close the XamlObjectWriter when handling an exception Resolves issue #81 --- src/FsXaml.Wpf/Utilities.fs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/FsXaml.Wpf/Utilities.fs b/src/FsXaml.Wpf/Utilities.fs index 3f64d41..af5b9ba 100644 --- a/src/FsXaml.Wpf/Utilities.fs +++ b/src/FsXaml.Wpf/Utilities.fs @@ -85,6 +85,12 @@ module InjectXaml = writer.WriteNode(reader) with | :? XamlException as xamlException -> // From writer + + // Explicitly close the writer. Otherwise, as it is disposed + // when it goes out of scope it may raise an exception, which will + // prevent the propagation of the helpful one we're just about to raise + try writer.Close () with _ -> () + let message = if reader.HasLineInfo then sprintf "Error parsing XAML contents from %s.\n Error at line %d, column %d.\n Element beginning at line %d, column %d." file xamlException.LineNumber xamlException.LinePosition reader.LineNumber reader.LinePosition