使用 iPhone 进行调试时,在命名空间 xmlns 中找不到 Xamarin 窗体的资源字典类型



我的解决方案由3个项目组成:

  1. 我的带有程序集My_Test_App的后端项目(可移植)

  2. My_Test_App.安卓

  3. My_Test_App.iOS

在后端项目中,我有这个 XAML 页面代码(请原谅名称)

<ContentPage
    x:Class="My_Test_App.Pages.LoginPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:converters="clr-namespace:My_Test_App.Converters;assembly=My_Test_App"
    xmlns:effects="clr-namespace:My_Test_App.Effects;assembly=My_Test_App"
    xmlns:viewModels="clr-namespace:My_Test_App.ViewModels;assembly=My_Test_App"
    xmlns:views="clr-namespace:My_Test_App.Views;assembly=My_Test_App">
    <ContentPage.Resources>
        <ResourceDictionary>
            <converters:Converter1 x:Key="conv1" />
            <converters:Converter2 x:Key="conv2" />
            <converters:Converter3 x:Key="conv3" />
        </ResourceDictionary>
    </ContentPage.Resources>
</ContentPage>

适用于安卓和iPhone模拟器,但是当我在真正的iPhone上测试它时,我收到此错误: Xamarin.Forms.Xaml.XamlParseException: Position 13:14. Type converters:Converter1 not found in xmlns clr-namespace:My_Test_App.Converters;assembly=My_Test_App

我在后端项目中的转换器 1 代码:

namespace My_Test_App.Converters
{
    public class Converter1: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool original = (bool)value;
            return !original;
        }       
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        public My_Test_App()
        {
        }
    }
}

你能帮忙吗?我这里有几个嫌疑人:

    在程序集名称
  1. 上划线,但我需要保留当前的程序集名称。

  2. 在 IOS 项目属性中,我将 iOS 构建部分中的链接器选项从"仅链接 SDK"更改为"链接所有程序集"。但是,如果我不更改它,我会收到错误"无法AOT程序集......"。

  3. 当前 xamarin 版本中可能存在的错误(我的是 4.2.2.11)

谢谢你帮助我!

类型转换器:未找到转换器1

Xamarin 链接器使用静态分析来确定可以从程序集中删除哪些IL代码以减小大小,并且由于反射调用从 Xamarin.Form 使用,基于 IValueConverter 的类似乎未被使用。

在 Xamarin.Forms (PCL) 项目中,添加一个PreserveAttribute类:

public sealed class PreserveAttribute : System.Attribute {
    public bool AllMembers;
    public bool Conditional;
}

现在将 [Preserve] w/AllMembers 属性添加到IValueConverter类中,以通知链接器跳过此类:

[Preserve(AllMembers = true)]
public class Converter1: IValueConverter
{
  ~~~
}

回复:https://developer.xamarin.com/guides/ios/advanced_topics/linker/

最新更新