gpt4 book ai didi

c# - InitializeComponent() 无法根据系统语言定位资源

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:07 24 4
gpt4 key购买 nike

该应用程序是在运行 windows 10 的机器上开发的,系统语言设置为我们的本地语言丹麦语。现在我们正处于需要在其他国家的办公室使用该软件的阶段。但是, View 在这些机器上启动时崩溃,而且我发现如果我在自己的机器上更改系统语言,它也不会为我工作。这是为什么,我们无法弄清楚。

来自 InitializeComponent 的错误消息:

System.IO.IOException: 'Cannot locate resource 'views/main/mainview.xaml'.'

堆栈跟踪:

at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access) at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access) at System.IO.Packaging.PackagePart.GetStream() at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at InfoCenter.Views.Main.MainView.InitializeComponent() in D:\Workspace\Visual Studio\MT Info Center WPF\Info Center\Views\Main\MainView.xaml:line 1 at InfoCenter.Views.Main.MainView..ctor() in D:\Workspace\Visual Studio\MT Info Center WPF\Info Center\Views\Main\MainView.xaml.cs:line 21 at InfoCenter.App.OnStartup(StartupEventArgs e) in D:\Workspace\Visual Studio\MT Info Center WPF\Info Center\App.xaml.cs:line 57 at System.Windows.Application.<.ctor>b__1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at InfoCenter.App.Main() in D:\Workspace\Visual Studio\MT Info Center WPF\Info Center\obj\Debug\App.g.cs:line 51

部分代码如下:

应用.xaml

<!--ANCHOR: Updater-->
<updater:SingleInstanceApplication x:Class="InfoCenter.App"
x:Name="App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:updater="clr-namespace:InfoCenter.Updater">
<Application.Resources>
</Application.Resources>
</updater:SingleInstanceApplication>

App.xaml.cs:

protected override void OnStartup(StartupEventArgs e)
{
if (PreProcessor.Prod)
Dispatcher.UnhandledException += OnDispatcherUnhandledException;

base.OnStartup(e);

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

var app = new MainView { ShowInTaskbar = false, Topmost = true }
var context = new MainViewModel();
app.DataContext = context;
app.Show();
}

其他信息:- 我们使用 ClickOnce 进行部署。- 该应用程序有一些将继续运行的后台任务。看起来它只是在没有 View 的情况下运行。- 我们使用 MVVM 模式。

如果我遗漏了一些信息,请随时询问!

最佳答案

这是一个关于文化信息的问题,因为你已经在你的资源文件中添加了这一行

<UICulture>en-US</UICulture> 

正在关注 this post你应该能够解决你的问题,取消注释这一行

[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 

在你的 assembly.info.cs 中

关于c# - InitializeComponent() 无法根据系统语言定位资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47809479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com