简体   繁体   中英

Xamarin.Forms iOS crash on XAML pages with custom controls

I am working on a Xamarin.Forms project, for which I recently upgraded the shared projects from PCL to .NETStandard.

At that point, I encountered build issues coming from several of my UI XAML files, with the error being:

Failed to resolve assembly: 'MyAssembly, Version 0.0.0.0, Culture=neutral, PublicKeyToken=null'

The problem files were found to be those that referenced custom XAML controls. After finding several people with similar issues online, I eventually found that I could get past this issue by setting the XamlCompilationOptions for those pages from Compile to Skip . The project now builds for iOS and Android.

The Android version works normally, however for the iOS version crashes when one of those pages tries to load, due to the presence of the custom control, with an error such as:

Xamarin.Forms.Xaml.XamlParseException … Type shared.SharedControl not found in xlmns clr-namespace: …

Has anyone encountered this issue, and if so, did you solve it? Is it a code issue or a Xamarin / Visual Studio Mac bug?

Ideally I would like to not have to set the XamlCompilationOptions for those pages to Skip , but either way I don't see why it should affect iOS but not Android.

Firstly, XamlCompilationOptions.Compile means Compile the XAML for the class or project when the application is built.While XamlCompilationOptions.Skip do the same thing when the application is run on the device.

In addition ,I suggest that you can do following steps:

  1. Delete and Re-generate all share files
  2. Remove ;assembly:xxx from App.xaml
  3. Clean and build again.

Here is a similar thread for you referring to Xamarin.Forms.Xaml.XamlParseException has been thrown

PS:There is a link about how to Upgrade PCL to .NET Standard Class Library

You need to load that assembly before using it. On Xaml it does not load, just try to reach, and crashes if its not loaded. Before using it you need to load assembly by calling a method, or creating an object belong MyAssembly .

There should be a Init method for the assembly to init things. you should call it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM