NavigationService.navigate not working - c#

At a login page, I checked for the validity and I made a simple condition:
if (everything is good)
{
this.NavigationService.Navigate(new Uri("/implementationPage.xaml", UriKind.Relative));
}
Then comes an error that points to this method:
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
MessageBox.Show(string.Format("page {0} failed, error: {1}", e.Uri.ToString(), e.Exception.StackTrace));
e.Handled = true;
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
Has anybody any idea why am I getting error?

Thank you Carlos,
After a lot of searching on the materials online
http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Silverlight-Programming-Navigation-between-Pages.aspx
This came in very handy. I didn't quite utilize the onNavigatedTo function apparently

Related

Xamarin/Tizen: Executing Navigation.PopAsync() crashes the app

I have a navigation page that sets up three pages. The first page loads, the user has to pick an option from a listview and then it loads the second page with PushAsync(). At this point the user can now navigate between the three pages by turning the clock face. If I call PopToRootAsync() on the second page it works fine. If the rotary clock face is turned clockwise it loads a third page via PushAsync().
The problem is if I call PopAsync() on that third page OR I change the PopToRootAsync() on the second page to a PopAsync(), the app crashes. I have no way to determine what the error is either as I just get segmentation fault and nothing is written to the Tizen log that is seemingly indicative of why it crashed.
Is there some reason that a PopAsync() would cause this? I know I saw some other articles this could occur if the MainPage is not loaded into a NavigationPage but I'm doing that. I've been looking through stuff and writing debug logs for days but have nothing to show for it. Any help would be more than appreciated. Thank you!
App.cs
public App()
{
MainPage = new NavigationPage(new ServerSelectionPage());
}
ServerSelection.cs
private void ServerSelection_OnItemTapped(object sender, ItemTappedEventArgs args)
{
App.SERVER = (Server)args.Item;
Navigation.PushAsync(new ArrowsPage());
}
PageBase.cs
public async void Rotate(RotaryEventArgs args)
{
Page _currentPage = Page.REMOTE_BUTTONS;
if (this.GetType() == typeof(ButtonsPage))
_currentPage = Page.REMOTE_BUTTONS;
else if (this.GetType() == typeof(ArrowsPage))
_currentPage = Page.REMOTE_ARROWS;
else
_currentPage = Page.SERVER_SELECTION;
// When rotating (previous rotation is ongoing, do nothing)
if (_rotating)
{
return;
}
_rotating = true;
if (!(App.SERVER is null))
{
if (_currentPage == Page.SERVER_SELECTION)
{
if (args.IsClockwise)
await Navigation.PushAsync(new ArrowsPage());
}
else if (_currentPage == Page.REMOTE_DIRECTIONAL)
{
if (args.IsClockwise)
await Navigation.PushAsync(new ButtonsPage());
else
await Navigation.PopToRootAsync();
}
else
{
try
{
if (!args.IsClockwise)
await Navigation.PopAsync(); // This will crash the app
}
catch(Exception ex)
{
Log.Debug(ex.Message);
}
}
}
_rotating = false;
}
After reading the comment by #vin about checking if the Navigation object is null I suddenly had the thought that it may not be the Navigation page but the RotaryFocusObject. So I changed
if (!args.IsClockwise)
await Navigation.PopAsync();
to
if (!args.IsClockwise)
{
RotaryFocusObject = null;
await Task.Delay(300);
await Navigation.PopAsync();
}
and it no longer crashes. The delay is necessary as if you call PopAsync right after setting the object to null it can still sometimes crash.
So apparently if you pop the current page it causes an error as the focus of the rotary dial is still set to the current navigation page. Why this error does not seemingly occur if you use the Navigation.PopToRootAsync() makes no sense to me.
Navigation.PopToRootAsync() and Navigation.PopToRootAsync() are causing destroy of Page renderer, and the Rotate handler is belong to Page Renderer,
If Page renderer was deleted before completion of Rotate Native Callback that is belong to Page renderer, it will be crashed.
await Task.Delay() let to returning native callback.

Getting error "Internet Explorer cannot display the webpage" in asp.net

I have a code block that leads to a "Internet Explorer cannot display the webpage" error. When I click the submit button, with NONE of the radio buttons checked, the web page status bar displays "waiting for response from host" and then display the "Internet Explorer cannot display the webpage". When I walk through the code in visual studio, the code executes fine, and none of the catch blocks are executed.
How can I trap the error and determine why the error page is being displayed?
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (rbtnSearchBy1.Checked)
{
Server.Transfer("ViewEmpHistory.aspx");
}
if (rbtnSearchBy2.Checked)
{
Server.Transfer("SearchEmp.aspx");
}
if (rbtnSearchBy3.Checked)
{
Server.Transfer("ViewEmpCard.aspx");
}
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
Whatever .cs page your "btnSubmit_Click" is on, put a breakpoint on that page_load event.
Also, put a breakpoint on the page_load event of "ViewEmpHistory.aspx", "SearchEmp.aspx" & "ViewEmpCard.aspx". (so now you have four breakpoints).
Step through the project again and make sure all parameter values are being passed correctly, also make sure that you have correct logic (if applicable) for If (!PostbacK) conditions etc.
HTH
if you don't select one radiobutton it's normal that you don't enter in your catch , because your application no throw exception.
but you can view your eventlog
Enter in your cmd : eventvwr to access your event log
To debug these kind of issues, I often find it easier to use Tracing.
You can turn on tracing at the application level, or at the page level.
Your method call will then become:
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (rbtnSearchBy1.Checked)
{
Server.Transfer("ViewEmpHistory.aspx");
}
if (rbtnSearchBy2.Checked)
{
Server.Transfer("SearchEmp.aspx");
}
if (rbtnSearchBy3.Checked)
{
Server.Transfer("ViewEmpCard.aspx");
}
}
catch(Exception ex)
{
Trace.Warn("Exception Caught", "Exception: btnSubmit_Click", ex);
}
}
You can look at the trace log by then navigating to the Trace Viewer.
What you've done is not exactly well structured. It's cleaner if the blocks are exclusive - which is why I've added the else statements to the code below. I've also indicated where you would want to handle the state where no button is checked in comments.
But you're right, there isn't any exception being thrown. Your code didn't throw one, and when you end processing a request without returning any type of response it doesn't cause an exception.
if (rbtnSearchBy1.Checked)
{
Server.Transfer("ViewEmpHistory.aspx");
}
else if (rbtnSearchBy2.Checked)
{
Server.Transfer("SearchEmp.aspx");
}
else if (rbtnSearchBy3.Checked)
{
Server.Transfer("ViewEmpCard.aspx");
}
else
{
// Here's where the logic will flow to if no radio button is clicked.
// We could
// * Server.Transfer to a default location
// * Throw an exception
// * Do nothing, which returns no response, and causes
// IE to complain that it could not display the webpage.
}

handle "The operation completed successfully" error

I have a vast application running WPF and I occasionally get the
The operation completed successfully
error randomly, could be a whole host of things.
Is there any way to trap this code and just restart the app.
I'm already using
#region "Error Checking"
void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleError("OnAppDomainUnhandledException", e.ExceptionObject.ToString(), e.ExceptionObject.ToString());
}
void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string error = string.Empty;
if (e.Exception.InnerException != null)
error = e.Exception.InnerException.Message;
HandleError("OnDispatcherUnhandledException", e.Exception.Message.ToString(),error);
e.Handled = true;
}
#endregion
but this does not appear to catch/handle the error
When I Google it seems that it has something to do with SplashScreens...
Maybe this may help you, or this.

Application settings do not allways save

I have a bit of a Heisenbug. I have a list of what was recently searched for sometimes it will save the history some times it does not. When I attach the debugger and step through StartFind() it works every time.
public Form1()
{
oldClinicsBindingSource.DataSource = ContractFlowTool.Properties.Settings.Default.RecentClinics;
}
private void StartFind()
{
(...)
if (oldClinicsBindingSource.Contains(newClinic))
oldClinicsBindingSource.Remove(newClinic);
oldClinicsBindingSource.Insert(0, newClinic);
oldClinicsBindingSource.EndEdit();
while (ContractFlowTool.Properties.Settings.Default.NumberOfClinicsToRemember < oldClinicsBindingSource.Count)
{
oldClinicsBindingSource.RemoveAt(oldClinicsBindingSource.Count - 1);
}
ContractFlowTool.Properties.Settings.Default.Save();
(..)
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{ //Breakpoint on this line
ContractFlowTool.Properties.Settings.Default.Save();
}
//In Settings.Designer.cs
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::System.Collections.ArrayList RecentClinics {
get {
return ((global::System.Collections.ArrayList)(this["RecentClinics"]));
}
set {
this["RecentClinics"] = value;
}
}
If I put a breakpoint on the { before the save inside Form1_FormClosing then hit continue (I don't even step over) it saves correctly. If the breakpoint is not there it does not save.
The program does use background workers in other parts but they not being run in my test case case.
Any help would be greatly appreciated.
Commenting out the Save() inside StartFind() appears to have fixed it.
I am still curious why it was happening. Do binding sources use internal threading?

The State of a listView item in the DrawItem event is wrong

The question is in the code. Cannot understand why this is happening.
private void listView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
// This works Ok
if (e.Item.Selected)
{
// ...
}
// This works wrong!
// e.State is always Selected! Why?
if ((e.State & ListViewItemStates.Selected) != 0))
{
// ...
}
}
Does someone have a similar problem?
This looks like a known bug since about 2006, in evidence when the ListView.HideSelection property is set to FALSE.
The only workaround on file is to do what you've already done: use e.Item.Selected.
Here is a link to the bug report - looks like it's been relegated to low priority so far.

Categories

Resources