该应用程序是在运行 Windows 10 的机器上开发的,系统语言设置为我们的本地语言丹麦语。现在我们正处于需要在其他国家的办公室使用该软件的阶段。但是,这些机器上的视图在启动时崩溃,我发现如果我在自己的机器上更改系统语言,它也对我不起作用。为什么会这样,我们无法弄清楚。
来自 InitializeComponent 的错误消息:
System.IO.IOException:'找不到资源'views/main/mainview.xaml'。'
堆栈跟踪:
在 MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode 模式,FileAccess 访问) 在 System.IO.Packaging.PackagePart.GetStream(FileMode 模式,FileAccess 访问) 在 System.IO.Packaging.PackagePart.GetStream() 在 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在 D:\Workspace\Visual Studio\MT Info Center WPF\Info Center\Views\Main\MainView.xaml.cs:InfoCenter.App.OnStartup(StartupEventArgs) 中的 InfoCenter.Views.Main.MainView..ctor() e) 在 D:\Workspace\Visual Studio\MT Info Center WPF\Info Center\App.xaml.cs:第 57 行 System.Windows.Application.<.ctor>b__1_0(Object used) 在 System.Windows.Threading。System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl( ) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback) 在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) , 对象状态, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 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) 在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 在 System.Windows。MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage (味精和味精)在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame 框架)在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame 框架)Windows.Threading.Dispatcher.PushFrame(DispatcherFrame 框架)Windows.Threading.Dispatcher.PushFrame(DispatcherFrame 框架)
在 System.Windows.Application.RunDispatcher(Object ignore) 在 System.Windows.Application.RunInternal(Window window) 在 System.Windows.Application.Run(Window window) 在 System.Windows.Application.Run() 在 InfoCenter.App .Main() 在 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>
应用程序.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 进行部署。- 该应用程序有一些将继续运行的后台任务。看起来它只是在没有视图的情况下运行。- 我们使用 MVVM 模式。
如果我遗漏了一些信息,请不要犹豫!