Xamarin.forms: Can't run UWP shared project app after upgrading to Xamarin Forms v3

Created on 7 Apr 2018  ·  12Comments  ·  Source: xamarin/Xamarin.Forms

Description

If you create a starter XF project using VS2017 and select UWP/Shared Project it no longer runs after upgrading to the XF v3 preview NuGet

Steps to Reproduce

  1. Create a new solution by selecting Visual C#/Mobile App (Xamarin Forms)
  2. Select Platform UWP and Shared Project
  3. Upgrade Xamarin Forms NuGet to V3
  4. Build and run UWP project

Expected Behavior

App loads and runs

Actual Behavior

App12.UWP.exe!App12.UWP.App.InitializeComponent.AnonymousMethod__5_0(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) Line 53
at C:\Users\xxx\Documents\Visual Studio 2017\Projects\App12\App12\App12.UWP\obj\x64\Debug\App.g.i.cs(53)

System.ArgumentException: String cannot have zero length.
at System.Reflection.RuntimeAssembly.GetResource(RuntimeAssembly assembly, String resourceName, UInt64& length, StackCrawlMarkHandle stackMark, Boolean skipSecurityCheck)
at System.Reflection.RuntimeAssembly.GetManifestResourceStream(String name, StackCrawlMark& stackMark, Boolean skipSecurityCheck)
at System.Reflection.RuntimeAssembly.GetManifestResourceStream(String name)
at Xamarin.Forms.Xaml.XamlLoader.GetXamlForType(Type type)


//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[assembly: global::Xamarin.Forms.Xaml.XamlResourceIdAttribute("", "", typeof(global::App12.App))]

namespace App12 {


    [global::Xamarin.Forms.Xaml.XamlFilePathAttribute("C:\\Users\\xxx\\Documents\\Visual Studio 2017\\Projects\\App12\\App12\\App12\\App" +
        ".xaml")]
    public partial class App : global::Xamarin.Forms.Application {

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "2.0.0.0")]
        private void InitializeComponent() {
            global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(App));
        }
    }
}

Basic Information

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="3.0.0.354232-pre3" />
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.1" />
  </ItemGroup>

Microsoft Visual Studio Community 2017
Version 15.6.4
VisualStudio.15.Release/15.6.4+27428.2015

regression UWP needs-repro ❔ bug

Most helpful comment

As a workaround, please enable XamlCompilation.

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

All 12 comments

I have this too.

Same issue for me.

As a workaround, please enable XamlCompilation.

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

Thanks that worked.
Now I can investigate FlexLayout😀

This worked!

For others reading along, you can put this:

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]

In the App.xaml.cs, between your Using statements and namespace

I can not reproduce this issue. Could one of you attach a failing project to this issue ? Thanks

@StephaneDelcroix Here you go: https://www.dropbox.com/s/jnmtzi7g4bnnmls/XamarinForms2395.zip?dl=0

It is just a new project updated to Xamarin Forms V3-pre3 on VS 15.6.6 like described in OP. Exception happens when running UWP project. I did delete the obj/bin directories from the UWP project to reduce size.

thx. can repro now

notes to self:

  • the resources are in the final assemblies, non-empty, and with an apparently correct Id;
  • the XamlResourceId have empty resourceId and path, preventing the Xaml loader to map the right resource to the type;
  • looking at the log, it might happens that XamlG is ran too early, before the TargetPath or the ManifestResourceName metadata are assigned.

I keep investigating

Adding DependsOnTargets="PrepareResourceNames" to the XamlG target fixes it for UWP. have to check the implication on other platforms

Hi @samhouts ,

The reported issue occurs in Xamarin Forms version above 4.2. Same issue occurs, is this a break. Kindly help on this issue.

Regards,
Devaraj S

@Devaraj-Sekar Can you please open a new issue? Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jgold6 picture jgold6  ·  3Comments

simontocknell picture simontocknell  ·  3Comments

sonic1015 picture sonic1015  ·  3Comments

EmilAlipiev picture EmilAlipiev  ·  3Comments

deakjahn picture deakjahn  ·  3Comments