Simple Error handling in windows phone sdk - c#

I have created a simple app which will do some calcualtions when user input some values.The app is working properly but when user forget to input some values in a textbox and run the app; the app stops working and it hangs. I want to know is there any simple error handling script for windows phone sdk.
I have used this error handiling script before in visual basic and in their its work perfectely.
On Error GoTo error_handler
Dim one,two ....
//some codes
.
.
......
error_handler:
Textblock1.Text = "Error"
I tried to use this above script in sdk but its showing this error
Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.ProjectData.CreateProjectError' is not defined.

As i asked in the question i was looking for a simple error handling script. I have found "accidently" the error handling script using try and catch method.Below is the code i used for error handiling.
Try
// Your code for app
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error!", MessageBoxButton.OK)
End Try

Related

Azure functions V3 logging exceptions in startup file

Currently we are preapring a set of azure functions to trigger a blob storage. The function app V3 should do some kind of checks on startup. So I added the Startup.cs file in the VS solution. The problem what I'm having is that sometimes exceptions happen while performing these checks in the startup file. But I never find these exceptions in azure portal (application insights/exceptions). I tried many ways to implement logging there, but unfortunately the app keeps saying Host is not running without any logging in these logs:
I'm not talking about the logs of a specific function, I mean here the logs of the function app on startup.
This is the code where it throws the exception in startup.cs:
try
{
// async method CheckSomeBlobsFiles
CheckSomeBlobsFiles(connectionString,
blobContainerName, blobDirectoryName).GetAwaiter().GetResult();
}
catch (Exception e)
{
throw new Exception($"Error while checking database schemas: {e.Message}");
}
After some research, for the exceptions from Startup.cs, you can find it in azure portal -> Diagnose and solve problems blade.
The steps as beow:
1.Nav to azure portal -> your function app -> on the left side, click on Diagnose and solve problems -> then input function app down in the search box -> then click on the Function App Down or Reporting Errors. The screenshot as below:
2.In the new page of Function App Down or Reporting Errors, expand
Function Executions and Errors -> then expand Detected host offline in your function app. Then you can see the exceptions in the startup.cs are logged there(if it's not there, please specify a proper time range on this page). The screenshot as below:
Can you try with HttpRequestException as shown the following code?
catch (HttpRequestException ex)
{
throw new Exception($"Error while checking database schemas: {e.Message}");
}

System.Diagnostics.Process.Start Exception for different user

I created an exe application with a button which has the following code executed when clicked. It is working when clicked by the same user which is used to create the exe. But the same exe when clicked by other users get exception message as "Application not found". Also the stack trace looks like given below.
try
{
System.Diagnostics.Process.Start("https://google.com");
} catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
Exception:
Exception Info: System.ComponentModel.Win32Exception
at System.Diagnostics.Process.StartWithShellExecuteEx(System.Diagnostics.ProcessStartInfo)
at System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
at MyTool.MainWindow.MyButton_Click(System.Object, System.Windows.RoutedEventArgs)
Maybe the other users that are running your .exe don't have a default browser or application to run this command. You can validate my theory if you execute the command in Run (Windows+R) and you encounter an error.
You're trying to start application named "https://google.com". You need to start web-browser application with parameter as URL:
System.Diagnostics.Process.Start("chrome.exe", "https://google.com");
Or with other application name.

C# simple device application is throwing Class not registered exception

I wrote a simple program to read barcode using Motorola mc5040 SDK
As soon as below code line gets executed
CCoreScanner cCoreScanner = new CCoreScanner();
Following exception gets thrown
exp.Message = "COM object with CLSID '{9F8D4F16-xxx-xxxx-98B3-xxxx}' cannot be created due to the following error: Class not registered ."
Any pointers how to resolve this ? I am running simple windows form with one button and a text box on actual Device running Windows CE.

Mathematica .Net/Link in an Asp.Net application

I am using the Mathematica .Net/Link platform to create a web service to format and calculate math problems. However I am unable to get it working.
I create it using this code:
_Log.IpDebug("Starting the Kernel Link");
if (string.IsNullOrEmpty(_MathLinkArguments))
_InternelKernel = MathLinkFactory.CreateKernelLink();
else
_InternelKernel = MathLinkFactory.CreateKernelLink(_MathLinkArguments);
_Log.IpDebug("Kernel Link Started");
_InternelKernel.WaitAndDiscardAnswer();
The value of _MathLinkArguments is -linkmode launch -linkname \"C:\\Program Files\\Wolfram Research\\Mathematica\\7.0\\Math.exe\".
This piece of code is called from the Application_Start method of the global.asax.cs file.
When it gets to the WaitAndDiscardAnswer() call it gives the server error:
Error code: 11. Connected MathLink program has closed the link, but there might still be data underway.
Note: The SampleCode given with the .NET/Link package (both a console app and a WinForms app) works.
Edit:
I copied the console app sample code given with Mathematica into an asp.net page and it gave me the same error the first load and then on subsequent loads it gave me:
Error code: 1. MathLink connection was lost.
Edit2:
I forgot to mention that when I have procmon and task manager open while running my app, I can tell that Math.exe starts but it immediately exits, which makes those error code make complete sense...but doesn't explain why that happened.
To allow the .Net/Link to work in Asp.net (at least in IIS 7.5) you need to enable the property loadUserProfile on the app pool for the web site.
I am not entirely sure why this is the case, but from what I found while trying to debug this, there are some things that are gotten from the user's profile. I know for a fact that the default location of the kernel is, which explains why I couldn't use it with no arguments, and so I can only assume that other things are needed as well and without the profile it couldn't determine that.
But whatever the reason is this is required, it is, or at least it is a fix if you are getting similar problems like this in your own application.
I got the same error in a .Net WinForm application.
mathKernel = new MathKernel();
mathKernel.Compute("<< XYZ`XYZGraphs`");
The error occurred on loading the package straight after instantiating the MathKernel.
To resolve it you can wait a couple of seconds and then instantiating the MathKernel works fine. During this state where there might still be data underway the following conditions are both false:
if (!MathKernel.IsConnected)
{
MathKernel.Connect();
}
if (MathKernel.IsComputing)
{
MathKernel.Abort();
}
Edit:
I've recieved the error again and this time was able to determine the problem.
Using a command line open the MathKernel.exe and view the error message:

How to catch 500 internal server error in c#

Im using Google Analytics Dashboard Control which are available at
http://gadashboardcontrols.codeplex.com/
Issue is its working fine when im connected to internet but if im using it on a machine that doesnt have internet access then it shows
Server Error in '/' Application.
The remote name could not be resolved: 'www.google.com'
I want to catch this exception and shows a friendly message to user. Im calling these dashboard control on my View in an iframe like this
<iframe src="../../GoogleAnalytics/Visitor.aspx" height="275"></iframe>
and if i place try catch in Visitor.aspx page it doesnot catch the exception. How should i catch this exception, Im using asp.net mvc 2 with c#
You cannot catch this exception because the problem occurs in the browser and not on the server. You do not have control over this from the aspx code.
What you can do instead is check network connectivity and serve alternate content in the page if the user is offline. Look into
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() for this.
There's no good way to catch this exception since you're using an iframe and the page is loaded in the browser and not via code. There are some tricks for this, but not as reliable.
The error is server-side so should actually try to fix it in your code.

Categories