MAUI - ResourceManager.GetString 引发异常 System.IO.FileNotFoundException

问题描述 投票:0回答:1

我已将 Xamarin 应用程序的代码移植到 .NET MAUI 应用程序。没有编译错误,因此我尝试运行该应用程序并检查它最初的工作情况。不幸的是我得到了 System.IO.FileNotFoundException: '' .

这是抛出错误的 Appresource.Designer.cs 文件。

    internal class AppResources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal AppResources() {
        }
        
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Appname.Resources.Strings.AppResources", typeof(AppResources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
        
        
        /// <summary>
        ///   Looks up a localized string similar to Menu.
        /// </summary>
        internal static string basement_header {
            get {
                return ResourceManager.GetString("basement_header", resourceCulture);
            }
        }

这里是**App.xaml.cs **

   public App()
   {
       InitializeComponent();
       
       MainPage = new Views.FlyoutPageView { Detail = new NavigationPage(new dashboard()) };
   }

FlyoutPageView.xaml.cs

public partial class FlyoutPageView : FlyoutPage

    public FlyoutPageView()
    {
        InitializeComponent();
        menuPageView.NavigationListView.ItemSelected += NavigationListView_ItemSelected;
    }

    private void NavigationListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        if (e.SelectedItem is MasterNavigationItem item)
        {
            Detail = new NavigationPage((Page)Activator.CreateInstance(item.Target));
            menuPageView.NavigationListView.SelectedItem = null;
            IsPresented = false;
        }
    }

}

MenuPage.xaml.cs

    public partial class MenuPage : ContentPage
    {
        public MenuPage ()
        {
            InitializeComponent();
            
        }
    }

MenuPage.xaml

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:strings="clr-namespace:Appname.Resources.Strings"   
             Title="{x:Static strings:AppResources.basement_header}"
             BackgroundColor="{StaticResource darkBlueBS}"
             >

我可能正在使用已弃用的代码,因为我不是 Xamarin 开发人员,但不确定现在要做什么或为什么它为空,因为我已在 AppResources.resx 中添加了 Strings 值

  1. 将 Xamarin 应用程序代码迁移到 .NET 8。
  2. 删除了 MAUI 不支持的旧 Xamarin 软件包。
  3. 在迁移之前我确实将 MasterDetailsView 页面转换为 FlyoutPageView,因为它已被弃用。
  4. 迁移的 Xamarin.Android 文件。
  5. 入口点现在更改为App.xaml,因此我无法比较和调试。
  6. 打开 System.Exception,否则它会在 FlyoutPageView InitializeComponent - System.Reflection.TargetInvocationException 上抛出此错误 Message=调用目标已引发异常。
c# xamarin.forms maui
1个回答
0
投票

这是 Xamarin 中的一个已知问题。您可以关注问题

您可以注意到这是快速部署的问题,其中 en-US/MyLibrary.resources.dll 等文件未正确部署。

这里有一些适合您的解决方法。

首先,您可以尝试禁用示例项目的 Android“快速部署”选项设置。

其次,您还可以从“调试”菜单中取消选中

System.Exception
,这将使项目正常运行。

© www.soinside.com 2019 - 2024. All rights reserved.