XamlLoader.ValueCreatedCallback = null;
XamlLoader.InstantiationFailedCallback = null;
Xamarin.Forms.Internals.ResourceLoader.ExceptionHandler = null;
+#pragma warning disable 0618
+ Xamarin.Forms.Xaml.Internals.XamlLoader.DoNotThrowOnExceptions = false;
+#pragma warning restore 0618
}
[Test]
}
[Test]
+ public void IgnoreMarkupExtensionException()
+ {
+ var xaml = @"
+ <ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
+ xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"">
+ <ListView ItemsSource=""{x:Static Foo}"" />
+ </ContentPage>";
+
+ var exceptions = new List<Exception>();
+ Xamarin.Forms.Internals.ResourceLoader.ExceptionHandler = exceptions.Add;
+ Assert.DoesNotThrow(() => XamlLoader.Create(xaml, true));
+ Assert.That(exceptions.Count, Is.GreaterThan(1));
+ }
+
+ [Test]
public void CanResolveRootNode()
{
string assemblyName = null;
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
+
+ //there's a test not resetting the values correctly, but can't find which one...
+ Xamarin.Forms.Internals.ResourceLoader.ExceptionHandler = null;
+#pragma warning disable 0618
+ Xamarin.Forms.Xaml.Internals.XamlLoader.DoNotThrowOnExceptions = false;
+#pragma warning restore 0618
}
[TearDown]
[TestFixture]
public class XamlLoaderCreateTests
{
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ XamlLoader.FallbackTypeResolver = null;
+ XamlLoader.ValueCreatedCallback = null;
+ XamlLoader.InstantiationFailedCallback = null;
+ Xamarin.Forms.Internals.ResourceLoader.ExceptionHandler = null;
+ Xamarin.Forms.Xaml.Internals.XamlLoader.DoNotThrowOnExceptions = false;
+ }
+
[Test]
public void CreateFromXaml ()
{
foreach (var cnode in node.CollectionItems)
cnode.Accept(visitor, node);
- value = markup.ProvideValue(serviceProvider);
-
+ try {
+ value = markup.ProvideValue(serviceProvider);
+ }
+ catch (Exception e) {
+ var xamlpe = e as XamlParseException ?? new XamlParseException("Markup extension failed", serviceProvider, e);
+ if (Context.ExceptionHandler != null) {
+ Context.ExceptionHandler(xamlpe);
+ }
+ else
+ throw xamlpe;
+ }
if (!node.Properties.TryGetValue(XmlName.xKey, out INode xKey))
xKey = null;