Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

XamlCompilation seems to break targetPlatform-specific namespaces #9971

Open
chucker opened this issue Mar 15, 2020 · 3 comments
Open

XamlCompilation seems to break targetPlatform-specific namespaces #9971

chucker opened this issue Mar 15, 2020 · 3 comments
Assignees
Labels
a/embedding 📦 a/Xaml </> t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects

Comments

@chucker
Copy link
Contributor

chucker commented Mar 15, 2020

Steps to Reproduce

  1. create a Xamarin Forms app with an iOS app
  2. add a Mac app
  3. in the MyApp.macOS project, add a XAML view:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="MyApp.macOS.Views.MyView">

    <ContentView.Content>
        <StackLayout Orientation="Vertical">
            <Label>macOS MyView</Label>
        </StackLayout>
    </ContentView.Content>

</ContentView>
  1. in the MyApp project, make a XAML page that references the view using a targetPlatform:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:macos="clr-namespace:MyApp.macOS.Views;assembly=MyApp.macOS;targetPlatform=macOS"
    x:Class="MyApp.Views.MyPage">

    <ContentPage.Content>
        <ContentView x:Name="ContentView">
            <OnPlatform x:TypeArguments="View">
                <On Platform="macOS" x:Name="OnMacOS">
                    <macos:MyView />
                </On>
            </OnPlatform>
        </ContentView>
    </ContentPage.Content>

</ContentPage>
  1. make this the main page:
public App()
{
    InitializeComponent();

    MainPage = new Views.MyPage();
}
  1. run the macOS app

Expected Behavior

The page should show a label that reads "macOS MyView".

Actual Behavior

The page is empty. The view seems to fail to resolve, and get silently removed.

However, with [assembly: XamlCompilation(XamlCompilationOptions.Compile)] removed, I cannot reproduce this.

Environment

=== Visual Studio Community 2019 for Mac ===

Version 8.4.8 (build 2)
Installation UUID: 9a7856af-5a33-46d4-af11-dc30d3e1c6f4
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.25 (issue-7441-d16-3-vsmac / 881172e73)

Package version: 606000166

=== Mono Framework MDK ===

Runtime:
Mono 6.6.0.166 (2019-08/d9001b5ae70) (64-bit)
Package version: 606000166

=== Roslyn (Language Service) ===

3.4.0-beta4-19562-05+ff930dec4565e2bc424ad3bf3e22ecb20542c87d

=== NuGet ===

Version: 5.3.0.6192

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.102/Sdks
SDK Version: 3.1.102
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.6.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.1.2
2.1.15

=== Xamarin.Profiler ===

Version: 1.6.13.11
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 11.3.1 (15715)
Build 11C504

=== Xamarin.Mac ===

Version: 6.10.0.21 (Visual Studio Community)
Hash: 02c4b3bdc
Branch: xcode11.3
Build date: 2020-02-18 14:13:31-0500

=== Xamarin.Android ===

Not Installed

=== Microsoft Mobile OpenJDK ===

Java SDK: Not Found

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.4.0.10
Hash: 2c49a7d
Branch: remotes/origin/d16-4
Build date: 2020-02-20 19:25:52 UTC

=== Android Device Manager ===

Version: 16.4.0.32
Hash: 7a5cb8b
Branch: remotes/origin/d16-4
Build date: 2020-02-20 19:26:14 UTC

=== Xamarin Designer ===

Version: 16.4.0.479
Hash: 074544417
Branch: remotes/origin/d16-4
Build date: 2020-01-22 22:50:22 UTC

=== Xamarin.iOS ===

Version: 13.10.0.21 (Visual Studio Community)
Hash: 02c4b3bdc
Branch: xcode11.3
Build date: 2020-02-18 14:13:32-0500

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 804080002
Git revision: 4f35aa7e44fb398379e512d0bfd6f8df8d34b5ac
Build date: 2020-02-27 16:16:52+00
Build branch: release-8.4
Xamarin extensions: 4f35aa7e44fb398379e512d0bfd6f8df8d34b5ac

=== Operating System ===

Mac OS X 10.15.3
Darwin 19.3.0 Darwin Kernel Version 19.3.0
Thu Jan 9 20:58:23 PST 2020
root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64

Build Logs

https://gist.github.com/chucker/d4b18c62a2b93f219acb7ea5f189ab49

Further remarks

  • if I use Xamarin Hot Reload to temporarily remove the view from the page, then re-add it, the view appears.
  • I can also add it after a delay:
async void ContentPage_Appearing(System.Object sender, System.EventArgs e)
{
    await Task.Delay(TimeSpan.FromMilliseconds(0));

    var type = global::System.Reflection.Assembly.GetEntryAssembly().GetType("MyApp.macOS.Views.MyView");

    ContentView.Content = Activator.CreateInstance(type) as View;
}
@chucker chucker changed the title XamlCompilation seem to break targetPlatform-specific namespaces XamlCompilation seems to break targetPlatform-specific namespaces Mar 15, 2020
@chamons chamons transferred this issue from xamarin/xamarin-macios Mar 16, 2020
@pauldipietro pauldipietro added this to New in Triage Mar 16, 2020
@StephaneDelcroix
Copy link
Member

this is a known an documented drawback. you can use platform specific xaml in a netstandard (or other) shared project because it will be resolved at runtime, but you can't compile it as it doesn't have a dependency on the platform project. Multi-targetting should probably help there, but I haven't tested it yet

@chucker
Copy link
Contributor Author

chucker commented Mar 16, 2020

this is a known an documented drawback. you can use platform specific xaml in a netstandard (or other) shared project because it will be resolved at runtime, but you can't compile it as it doesn't have a dependency on the platform project.

I could've sworn I didn't see it before, but the warning is in fact right there on the page I read. Sorry! :)

Still, wouldn't it be possible to extend this to a compiler warning if any imported namespace contains targetPlatform and XamlCompilation is enabled?

@jfversluis
Copy link
Member

While it is a documented limitation, it should still trigger a compilation error when XAML compilation is enabled. That is the actual bug here. Thanks for reporting @chucker !

@jfversluis jfversluis moved this from New to Ready For Work in Triage Mar 18, 2020
@samhouts samhouts moved this from Ready For Work to Needs Estimate in Triage Mar 18, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts added this to To do in vNext+1 (5.0.0) Aug 14, 2020
@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! and removed inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! labels Sep 18, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/embedding 📦 a/Xaml </> t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
Triage
  
Needs Estimate
Development

No branches or pull requests

4 participants