[英]Xamarin - Type not found in xmlns clr-namespace
我正在制作 Xamarin Forms 應用程序,解決方案稱為RESTTest
,我的共享項目稱為RestApp
。
在我的共享項目中,我有一個名為ViewModels
的文件夾,其中包含一個名為MainViewModel.cs
的類
我有一個名為頁面MainPage.xaml
具有代碼隱藏叫MainPage.xaml.cs
。 在我的 XAML 中,我試圖像這樣包含我的 Viewmodels 文件夾:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RestApp"
x:Class="RestApp.MainPage"
xmlns:ViewModels="clr-namespace:RestApp.ViewModels;assembly=RestApp">
但是當我像這樣向我的頁面添加綁定時:
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
我收到一個未處理的異常:
Type ViewModels:MainViewModel not found in xmlns clr-namespace:RestApp.ViewModels;assembly=RestApp
我錯過了什么?
刪除命名空間中的“;assembly=RestApp”,並將鏈接器行為設置為“僅鏈接 SDK 程序集”對我有用並解決了問題!
當您進行鏈接器優化以修剪未使用的代碼時,通常會發生這種情況。
請注意,作為類型使用,鏈接器可能無法檢測到反序列化為類型。
在項目的屬性中,找到“iOS 構建”或“Android 構建”下的“鏈接器行為”選項,並將其設置為“僅鏈接 SDK 程序集”或“不鏈接”。 您需要清理+重建整個解決方案才能使更改生效。
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:cvt="clr-namespace:XamarinTest.UI.Resources.Converts;assembly=XamarinTest.UI">
<cvt:DoubleToImageConverter x:Key="CVT_DoubleToImage"/>
<cvt:MediaTypeToImageConverter x:Key="CVT_MediaTypeToImage"/>
</ResourceDictionary>
在我的應用程序中,我添加了assembly=XamarinTest.UI
解決了這個問題。 我認為開發團隊可能會刪除 Xamarin Forms 5.0 中的assembly=xxxx
部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.