InitializeComponent() Cannot locate resource based on system language
The application was developed on machines running windows 10, with the system language set to our local language, danish. Now we are at a stage where the software needs to be used in offices in other countries. However, the view crashes on startup on those machines, and I have found out that if I change the system language on my own machine, it will not work for me either. Why this is, we can't figure out.
Error message from InitializeComponent:
System.IO.IOException: 'Cannot locate resource 'views/main/mainview.xaml'.'
StackTrace:
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:WorkspaceVisual StudioMT Info Center WPFInfo CenterViewsMainMainView.xaml:line 1 at InfoCenter.Views.Main.MainView..ctor() in D:WorkspaceVisual StudioMT Info Center WPFInfo CenterViewsMainMainView.xaml.cs:line 21 at InfoCenter.App.OnStartup(StartupEventArgs e) in D:WorkspaceVisual StudioMT Info Center WPFInfo CenterApp.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, D elegate 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, I nt32 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:WorkspaceVisual StudioMT Info Center WPFInfo CenterobjDebugApp.g.cs:line 51
Here is some of the code:
App.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();
}
Other info: - We deploy using ClickOnce. - The app have some background tasks that will keep running. It look like it just runs without a view. - We use MVVM pattern.
If I am missing some information, don't hesitate to ask!
It was a problem regarding the Culure Info, since you have added this line in your resource file
<UICulture>en-US</UICulture>
Following this post you should be able to solve your problem uncommenting this line
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
in your assembly.info.cs
链接地址: http://www.djcxy.com/p/63610.html