Xamarin.forms: Support for mc:Ignorable

Created on 4 Jun 2018  ·  13Comments  ·  Source: xamarin/Xamarin.Forms

Description

... Elements or attributes where the prefix portion of the element name are identified as mc:Ignorable will not raise errors when processed by a XAML processor. ...

Please see https://docs.microsoft.com/de-de/dotnet/framework/wpf/advanced/mc-ignorable-attribute for additional information about this attribute.

In short: there is the markup extension d:DesignInstance which is supposed to be design time only. This configured by mc:Ignorable="d".

A valid use case: design time intellisense support for data contexts: https://stackoverflow.com/questions/29399157/how-do-i-specify-datacontext-viewmodel-type-to-get-design-time-binding-checkin

This is a attribute for "wpf". But is works also with xamarin.forms (sometimes https://bugzilla.xamarin.com/show_bug.cgi?id=27295 ?).

It does work if the xaml gets compiled (See last comments of linked bugzilla page).

Steps to Reproduce

  1. add the following attributes to to any root component of a xaml file:

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DataContext="{d:DesignInstance x:Object}"
    mc:Ignorable="d"

  2. try to execute app

  3. An Unhandled Exception is thrown as soon as the embedded xaml gets interpreted:
    > Xamarin.Forms.Xaml.XamlParseException: Position 8:13. MarkupExtension not found for d:DesignInstance

Expected Behavior

Please see https://docs.microsoft.com/de-de/dotnet/framework/wpf/advanced/mc-ignorable-attribute:

... Elements or attributes where the prefix portion of the element name are identified as mc:Ignorable will not raise errors when processed by a XAML processor. ...

Actual Behavior

The attribute mc:Ignorable is not honored and the app crashes.

Basic Information

Official documentation: https://docs.microsoft.com/de-de/dotnet/framework/wpf/advanced/mc-ignorable-attribute

Reproduction Link

any xamarin.forms project with xaml code should do it.

Xaml </> 4 help wanted high inactive needs-info ❓ bug up-for-grabs

Most helpful comment

reopen please

All 13 comments

I will prepare a repo tommorrow. It does work sometimes, but not always.

And I removed 'live reload' because I got it working. So the underlying issue could be some where else. Sorry for any confusion.

I can confirm we crash on an ignored MarkupExtension, and we should not

Extended "steps to Reproduce" using https://github.com/xamarin/xamarin-forms-samples
and Live Reload:

  1. get the sample XAML\MarkupExtensions running and verify that the subpage "x:Array Demo Page" works
  2. Add Live Reload to the project (see https://docs.microsoft.com/de-de/xamarin/xamarin-forms/xaml/live-reload). Just install and activate it. There does not need to be an actual connection!
  3. Add the following code to ArrayDemoPage.xaml

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DataContext="{d:DesignInstance x:Object}"
mc:Ignorable="d"

  1. Recompile and navigate to the subpage
  2. You will get an "TargetInvocationError"
  • If you remove the added xaml code, it works.
  • If you remove LiveReload.Init();, it works.

I do not know, why I get an TargetInvocationError instead of the actual exception like yesterday (older runtime?).
Nethertheless, the added xaml code should be ignored at runtime.

Without LiveReload everything works as expected.

@Gitii do you know if it used to work in 2.5.x ?

Sadly, Live.Reload only supports >= 3 (just tried).
In the linked old bugzilla thread, they are mentioning 2.4 and there are even comments from 2018.
There are some theories and workarounds mentioned in the thread.

In addition I found another repo (https://github.com/sascha-schwegelbauer/XamFormsSample) for reproducibility. It also uses 2.4 but _without_ Live.Reload.

Any fixes?

I exprerienced the same issue. Are there any news?

I have the same issue

The same issue. Any fixes?

Quick fix:
add
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
to the project with xaml files and recompile

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!

reopen please

Was this page helpful?
0 / 5 - 0 ratings