I am using following code for unhandled exceptions.
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
e.Handled = true;
Error.Exp = e.ExceptionObject;
(RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source = new Uri("/Error.xaml", UriKind.Relative);
}
This code should direct the control to Error.xaml page but it goes to visual studio with the error message of the exception (even after commenting out if block). What is wrong here ?
The source of error is
GeneralTransform generalTransform1 = canvas1.TransformToVisual(start_rec);
Error message was
"Argument exception was unhandled. The parameter is incorrect."
try
{
// do something with your crash , report it or write log
}
catch
{
}
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
the debug go to the place exception throw .
Related
i was working on .net core wpf game lancher but the error "Error CS0103: The name 'ZipFile' does not exist in the current context" appeared. even i used the following line: using System.IO.Compression; but it didnt work.
private void DownloadGameCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
try
{
string onlineVersion = ((Version)e.UserState).ToString();
ZipFile.ExtractToDirectory(gameZip, rootPath, true); // error cs0103
File.Delete(gameZip);
File.WriteAllText(versionFile, onlineVersion);
VersionText.Text = onlineVersion;
Status = LauncherStatus.ready;
}
catch (Exception ex)
{
Status = LauncherStatus.failed;
MessageBox.Show($"Error finishing download: {ex}");
}
}
tried change namespace, class to GameLauncher in mainwindow.xaml (didn't work)
I'm building a WPF data visualization tool with the Geared version of LiveCharts.
I have a SectionsCollection object named SectionsCollection that I need to reload as the data changes. I run the following code segment before reassigning to SectionsCollection.
try
{
if (SectionsCollection != null && SectionsCollection.Count > 0)
{
SectionsCollection.Clear();
}
}
catch(Exception e)
{
Status += "Error in clearing SectionsCollection.\n"+e;
}
SectionsCollection = new SectionsCollection();
The following error occurs intermittently on the SectionsCollection.Clear(); line, with the label NullReferenceException occurred.
Exception thrown: 'System.NullReferenceException' in LiveCharts.Wpf.dll
Additional information: Object reference not set to an instance of an object.
If I check that SectionsCollection is not null and is not empty, why is this error coming up?
This error seems to occur for VisualsCollection and SeriesCollection types as well.
Try add flag to prevent unwanted multiple exec. in your process:
bool collIsBusy = false;
try
{
if (SectionsCollection != null && SectionsCollection.Count > 0 && !collIsBusy)
{
collIsBusy = true; //flag to prevent throttling multiple executions
SectionsCollection.Clear();
collIsBusy = false;
}
}
catch (Exception e)
{
Status += "Error in clearing SectionsCollection.\n" + e;
}
SectionsCollection = new SectionsCollection();
Why doesn't my assert method fail when the two strings clearly do not match?
public void checkHomepageURL_Test1() throws Exception {
basePage.loadHomePage();
try {
System.out.println("inside try block");
Assert.assertEquals("Actual String Expected", "Im Wrong!");
System.out.println("inside try block SECOND!!");
} catch (Throwable e) {
System.out.println("BETA!!!!!!" + e.getMessage());
} finally {
System.out.println("All over now!");
}
}
New Examaple
When an assert fails it throws an Throwable. Since you have your assert inside a try-catch block, when that Throwable is raised, it will be captured by the catch block, your program will log ""BETA!!!!!!" + e.getMessage()" and then it will finish properly.
You should either:
remove your try catch block
catch Exception instead of Throwable
(the first option is the proper one for a test AFAIK)
If you remove the Catch, your error will be printed as follows in your console.
org.junit.ComparisonFailure:
Expected :Actual String Expected
Actual :Im Wrong!
<Click to see difference>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.scouto.test.checkHomepageURL_Test1(test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
I have a bit of code in my App.cs file to catch unhandled exceptions in the event of a crash. The problems is when I step through the code, it reads as if the file exists, but no new file is actually created. I am probably overlooking something simple but I could use a second (or more ;)) set of eyes on it. Here is my method.
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var contents =
string.Format(
"HResult: {1}{0}" + "HelpLink: {2}{0}" + "Message: {3}{0}" + "Source: {4}{0}"
+ "StackTrace: {5}{0}" + "{0}",
Environment.NewLine,
e.Exception.HResult,
e.Exception.HelpLink,
e.Exception.Message,
e.Exception.Source,
e.Exception.StackTrace);
if (!File.Exists("/Source/CrashLogs/Exceptions.txt"))
{
File.WriteAllText("/Source/CrashLogs/Exceptions.txt", contents);
}
else
{
File.AppendAllText("/Source/CrashLogs/Exceptions.txt", contents);
}
e.Handled = true;
}
I'll next expand this out so that the file name contains the current date, but I would just like to get it running first.
Thanks!!
is folder /Source/CrashLogs/ already exists?
handle also AppDomain.CurrentDomain.UnhandledException
more info here
I've had this code working for at least a year and today it threw an exception that i haven't been able to figure out why its happening. Its a Forms.WebBrowser that hits a generic site first and then a secondary site.
'first site
wbr.ScriptErrorsSuppressed = False
wbr.Navigate("http://www.bing.com/?rb=0")
Do
Application.DoEvents()
Loop Until wbr.ReadyState = WebBrowserReadyState.Complete
'second site
wbr.ScriptErrorsSuppressed = True
Dim start As DateTime = DateTime.Now
Dim loopTimeout As TimeSpan = TimeSpan.FromSeconds(timeout)
wbr.Navigate("http://www.FlightAware.com")
Do
Application.DoEvents()
'loop timer
If DateTime.Now.Subtract(start) > loopTimeout Then
'stop browser
wbr.Stop()
'throw exception
Dim eExpTme As Exception = New Exception("A loop timeout occurred in the web request.")
Throw eExpTme
End If
Loop Until wbr.ReadyState = WebBrowserReadyState.Complete
The error happens on the second site access and it shows that it errors on the very last line with
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Windows.Forms.UnsafeNativeMethods.IHTMLLocation.GetHref()
at System.Windows.Forms.WebBrowser.get_Document()
at System.Windows.Forms.WebBrowser.get_ReadyState()
I just don't get why its errorring on the second site and not the first and what exactly that error message means. I've looked at some help forums but nothing concrete that i can use to troubleshoot.
AGP
The web site has a frame on ad.doubleclick.net, by default cross-domain frame access is disabled for the internet zone, so you get a security exception.
Catch the exception and move on. There isn't much you need to care about in the frame, doubleclick is an ad service.
You can implement IInternetSecurityManager and let IE to believe ad.doubleclick.net and FlightAware.com are the same web site, but this can cause security problem if you extend the trust to arbitrary web sites.
Here is a little hack in C# which you can convert in Vb.net:
public class CrossFrameIE
{
// Returns null in case of failure.
public static IHTMLDocument2 GetDocumentFromWindow(IHTMLWindow2 htmlWindow)
{
if (htmlWindow == null)
{
return null;
}
// First try the usual way to get the document.
try
{
IHTMLDocument2 doc = htmlWindow.document;
return doc;
}
catch (COMException comEx)
{
// I think COMException won't be ever fired but just to be sure ...
if (comEx.ErrorCode != E_ACCESSDENIED)
{
return null;
}
}
catch (System.UnauthorizedAccessException)
{
}
catch
{
// Any other error.
return null;
}
// At this point the error was E_ACCESSDENIED because the frame contains a document from another domain.
// IE tries to prevent a cross frame scripting security issue.
try
{
// Convert IHTMLWindow2 to IWebBrowser2 using IServiceProvider.
IServiceProvider sp = (IServiceProvider)htmlWindow;
// Use IServiceProvider.QueryService to get IWebBrowser2 object.
Object brws = null;
sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out brws);
// Get the document from IWebBrowser2.
IWebBrowser2 browser = (IWebBrowser2)(brws);
return (IHTMLDocument2)browser.Document;
}
catch
{
}
return null;
}
private const int E_ACCESSDENIED = unchecked((int)0x80070005L);
private static Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
private static Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
}
// This is the COM IServiceProvider interface, not System.IServiceProvider .Net interface!
[ComImport(), ComVisible(true), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IServiceProvider
{
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}