I have a WPF application and sometimes app crashes just after I call ShowDialog() on Window (http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog%28v=vs.110%29.aspx)
When application starts I open a main dialog (it's always opened) then I want to open a new child dialog (see below ShowModal method), and usually everything works fine but sometimes after calling ShowDialog() (see below code snippet) it throws System.NullReferenceException in PresentationFramework.dll in method System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param).
After calling ShowDialog() the window is shown in App, then when I click anywhere on it (for example a textbox), it throws NullReferenceException .
I'm unable to reproduce crashing pattern it behaves completely randomized. And I'm starting to go crazy because I don't have any clue how to trace where is the problem.
This is the snippet from my code:
private Window Wnd { get; set; }
public bool ShowModal(ViewModel vm)
{
if( Wnd == null )
{
throw new InvalidOperationException( "Window was already closed" );
}
Wnd.DataContext = vm;
Result = Wnd.ShowDialog().Equals(true);
return Result;
}
Wnd is not null it contains instance of window I want to show. Exception is thrown in this line
Result = Wnd.ShowDialog().Equals(true);
actually after Wnd.ShowDialog()
Thrown exception snapshot:
System.NullReferenceException {"Object reference not set to an instance of an object."}
HResult = -2147467261
Message = Object reference not set to an instance of an object.
Data = {System.Collections.ListDictionaryInternal}
InnerExcpetion = null
Source = PresentationCore
StackTrace
at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
at System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled)
at System.Windows.Interop.ThreadMessageEventHandler.Invoke(MSG& msg, Boolean& handled)
at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at System.Windows.Window.ShowDialog()
at Intes.Utility.VisualizerService.UiWindow.ShowModal(ViewModel vm) in d:\Coder\Branch-AT\Source\Utilities\VisualizerService\Window abstraction\Implementation\UiWindow.cs:line 109
// this part of call stack is not important, but I will leave it
at A13.ViewModels.CalGroupExplorer.CalGroupExplorerPanelViewModel.NewMessage(IEnumerable`1 referenceIDs) in d:\Coder\Branch-AT\Source\A13\A13\ViewModels\CalGroupExplorer\CalGroupExplorerPanelViewModel.cs:line 159
at A13.ViewModels.EntryViewModel.AddReferencedMessage() in d:\Coder\Branch-AT\Source\A13\A13\ViewModels\CalGroupExplorer\EntryViewModel.cs:line 147
at A13.ViewModels.EntryViewModel.<get_AddReferencedMessageCommand>b__4(Object param) in d:\Coder\Branch-AT\Source\A13\A13\ViewModels\CalGroupExplorer\EntryViewModel.cs:line 136
at Intes.Utility.Wpf.RelayCommand.Execute(Object parameter) in d:\Coder\Branch-AT\Source\Utilities\Wpf\RelayCommand.cs:line 70
at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, 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 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, 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.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at System.Windows.Window.ShowDialog()
It seems like bug in .NET Framework, I'm using .NET Framework 4.5 for both projects A13 and Intes. A13 is main project , while Intes is referenced (method ShowModal is in class that is in project Intes). A13 is compiled as platform target: x86, while Intes as platform target: AnyCPU.
I'm running application in DEBUG mode on Windows 8.1 on x64 processor (Application has to be a x86).
Does anybody have any idea where could be the problem or any help how to trace the problem?
Related
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:\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
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 Culture 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
OnContentRendred will initiate License checking, if there's no valid license I'll provide a LicenseWindow to select one. If the user closes the LicenseWindow without selecting a valid license, the MainWindow will be closed too.
This is the Handler of the OnContentRendred- Event of MainWindow:
private void CheckLicenseOnContentRendered(object sender, EventArgs e)
{
ContentRendered -= CheckLicenseOnContentRendered;
try
{
Initialize(); // may throw LicenseException
}
catch (LicenseException)
{
var licenseWindow = new LicenseWindow();
if (licenseWindow.ShowDialog() == true)
{
// Do Stuff if valid License selected
}
else
{
this.Close(); // <-- NullReferenceException
}
}
catch (Exception ex)
{
// Other Exceptions will be handled here
}
}
As tagged in the codesample the this.Close() results in a NullReferenceException.
I did some debugging and with the ImmediateWindow I managed to find out that this is not null (as it should be)
So then why could this.Close() cause a NullReferenceException and maybe how do I Close the Window in an other way?
EDIT:
Stack Trace:
bei Giag.DataReader.ControlLibrary.Windows.MainWindow.WindowClosing(Object sender, EventArgs e) in d:\...\Windows\MainWindow.xaml.cs:Zeile 210.
bei System.Windows.Window.OnClosing(CancelEventArgs e)
bei System.Windows.Window.WmClose()
bei System.Windows.Window.WindowFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
bei MS.Win32.UnsafeNativeMethods.UnsafeSendMessage(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam)
bei System.Windows.Window.InternalClose(Boolean shutdown, Boolean ignoreCancel)
bei System.Windows.Window.Close()
bei Giag.DataReader.ControlLibrary.Windows.MainWindow.CheckLicenseOnContentRendered(Object sender, EventArgs e) in d:\...\Windows\MainWindow.xaml.cs:Zeile 236.
bei System.Windows.Window.OnContentRendered(EventArgs e)
bei System.Windows.Window.<PostContentRendered>b__4(Object unused)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.DispatcherOperation.InvokeImpl()
bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Windows.Threading.DispatcherOperation.Invoke()
bei System.Windows.Threading.Dispatcher.ProcessQueue()
bei System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
bei MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
bei System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
bei System.Windows.Threading.Dispatcher.Run()
bei System.Windows.Application.RunDispatcher(Object ignore)
bei System.Windows.Application.RunInternal(Window window)
bei System.Windows.Application.Run(Window window)
bei System.Windows.Application.Run()
bei FrameworkTestClient.App.Main() in d:\...\FrameworkTestClient\obj\Debug\App.g.cs:Zeile 0.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
EDIT 2:
In a test Project the code above works fine.. So I will need to find the Fault somewhere else. Thanks for your help, i'll keep you in touch.
Not sure if I understood your question correctly, but if you want to exit the whole program if no license is found, you can use Application.Current.Shutdown(); to close the main window and exit application.
There was an Error in the Closing Event handler.
One will learn debugging correctly sometime...
Thanks to all to you.
I am trying to download a json string from a web page. I have been using System.Net.WebClient.
When I run it, it works fine on the first loop through, however when it comes through a second time it throws this error.
An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in mscorlib.dll
Additional information: Parameter count mismatch.
I have narrowed down the line of code that is causing this error and I am completely baffled by it as works fine on the first attempt but doesn't on the second.
using (var client = new WebClient())
{
var url = string.Format(#"{0}{1}", _partOne, partTwo);
var result= client.DownloadString(url);
}
It is throwing the error on the following line specifically.
var result= client.DownloadString(url);
Just for more background this is a MVVM WPF application.
Stack Trace:
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
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 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, 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.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at MyApp.App.Main() in c:\MyApp\obj\Debug\App.g.cs:line 0
I forgot to mention that the error is thrown on this line then I am able to see that it did infact return the correct data but won't let me continue to the next line.
I am getting the following error when trying to run a WPF based application on windows XP runs fine on windows 7.
System.DllNotFoundException was unhandled
Message=Unable to load DLL 'dwmapi.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=***************************
TypeName=""
StackTrace:
at Presentation.Common.MetroWindowBase.NativeMethods.DwmSetWindowAttribute(IntPtr , Int32 , Int32& , Int32 )
at Presentation.Common.MetroWindowBase.HandleSourceInitialized(Object sender, EventArgs e)
at System.Windows.Window.OnSourceInitialized(EventArgs e)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(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 *********************
InnerException:
The desktop window manager was introduced in Vista, which is almost certainly why you're unable to load it in XP.
You should look at this related question to see if it fixes your problem.
I'm having a very weird error using the WebClient class in .NET 4.
The app simply downloads some files off the internet and provides output on a textbox (the GUI is WPF). The method that does this is the following:
void DownloadFiles(object files) {
var fileL = (List<string>) files;
foreach (string url in fileL)
{
byte[] data;
using (var k = new WebClient())
{
data = k.DownloadData(url);
}
//Bunch of irrelevant code goes here...
}
}
(I added the using while trying to divine [yes I'm that desperate/ignorant] a solution, the problem happens even if the webclient is declared and initialized outside the foreach loop)
Now the problem appears only when I'm executing this method on a thread separate from the WPF UI main thread. If it is executed on the UI thread then it works perfectly. When a new thread is created with:
Thread t = new Thread(DownloadFiles);
t.Start(files);
The first time the code goes into the loop it will work, but when its the second pass inside the loop, I will always receive a TargetParameterCountException.
I can't make any sense of this error. Any help is very much appreciated.
edit
Here are the Exception Details:
Exception.Message = "Parameter count mismatch."
Exception.InnerException = null
Exception.Source = " mscorlib"
The StackTrace follows:
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(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.Threading.Dispatcher.Run()
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 FileDownloader.App.Main() in d:\mis documentos\visual studio 2010\Projects\OneMangaDownloader\FileDownloader\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I know there is a bug in WebClient where it always puts the call on the UI thread. Not sure if this is causing the issues.
For more info read this post.