使用iPhone进行调试时,在命名空间xmlns中找不到Xamarin Form的Resource字典类型 [英] Xamarin Form's Resource dictionary type not found in namespace xmlns when debugging using iPhone

查看:151
本文介绍了使用iPhone进行调试时,在命名空间xmlns中找不到Xamarin Form的Resource字典类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的解决方案包含3个项目:

My solution consist of 3 project:

  1. 带有程序集My_Test_App的后端项目(便携式)

  1. My backend project with assembly My_Test_App (portable)

My_Test_App.Android

My_Test_App.Android

My_Test_App.iOS

My_Test_App.iOS

在后端项目中,我有此XAML页面代码(请原谅)

In the backend project, I have this XAML page code (Please forgive the name)

<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>

它可以在android和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

It works on android and iPhone simulator, but when i tested it on the real iPhone, i get this error: Xamarin.Forms.Xaml.XamlParseException: Position 13:14. Type converters:Converter1 not found in xmlns clr-namespace:My_Test_App.Converters;assembly=My_Test_App

我在后端项目中的Converter1代码:

My code for Converter1 in the backend project:

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()
        {
        }
    }
}

您能帮忙吗?我这里有些嫌疑人:

Could you help with this please? I have a few suspect here:

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

  1. Underscore on assembly name, but i need to keep the current assembly name..

在IOS项目属性中,我将"iOS构建"中的链接器选项从仅链接SDK"更改为链接所有程序集".但是,如果我不更改它,则会收到错误消息无法自动执行程序集...."

In the IOS project properties, i changed the linker Options in iOS Build section from "Link SDK only" to "Link all assemblies". But, if i don't change it, i got error "Could not AOT the assembly......."

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

Possible bug in the current xamarin version (mine is 4.2.2.11)

谢谢您的帮助!

推荐答案

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

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

The Xamarin linker uses static analysis to determine what IL code can be removed from your assemblies to reduce the size and due to reflection invoke usage from Xamarin.Form, the IValueConverter-based class appears not to be used.

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

In your Xamarin.Forms (PCL) project, add a PreserveAttribute class:

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

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

Now add the [Preserve] w/ AllMembers attribute to your IValueConverter class to inform the Linker to skip this class:

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

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

这篇关于使用iPhone进行调试时,在命名空间xmlns中找不到Xamarin Form的Resource字典类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆