How to get real error messages in Nancy on Mono? - c#

I can't figure out how to get actual 500 errors to be written into the response body. All I get is the Nancy 500 error page with JavaScript button to show the error. Since this is all happening behind the scenes via an iOS application I can't view the error, and in fact Nancy does not render the error to the div at all.
Is there some wonky self-hosting configuration to just let the runtime stacktrace get inserted into the response? (Obviously just while we are debugging).
In normal ASP it would be easy to limit debugging to localhost. Anyway, I feel kind of blind coding in Nancy and only being able to debug with Visual Studio. All the responses come from within a standard route handler/ controller module.
I'd like to avoid having to sprinkle everything with try catches and just let things fail and get real errors when things fail.

Implement your own IStatusCodeHandler and handle 500 return codes. If you need to, you can also override the OnError pipeline to get access to the actual exception (you can read about this in the documentation).
Detailed information, on the error page, is shown when built in debug mode. For some reason it does not appear to show it for you. What you could do is force it to always be enabled by setting in code:
StaticConfiguration.DisableErrorTraces = false

Related

ABP.io angular cannot read property replace of undefined

I'm using Abp.io for .net backend and angular for frontend, I've the backend up and running and works pretty ok on swagger.
However when I generate proxies for the backend with the command "abp generate-proxy" it throws me an error saying "cannot read property replace of undefined" and that's bout it, I've no clue where to look for errors.
Note I've generated proxies before and I know how they look inside an angular project but after adding more endpoints I keep getting this error, I've also attached a screen shot just in case you want to have a look at it.
I would really appreciate some help, thanks guys.
I also received this error. I believe this occurs if there are no models/services to generate. After adding my first model and CrudService the error never re-appeared.
I figured it out. First there was a JSON serialize in startup file that was causing that error and the frontend project's API address was targeting to the live instead of the local one.

Accessing SqlCeException on Windows Phone 8

I am getting SqlCeException in my WP8 application. The message says only:
An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in
Microsoft.Phone.Data.Internal.ni.dll but was not handled in user code
As you can see, it is not very specific as to why did it happen. After some googling I found an advice to inspect the exception further by accessing its Errors property (link to discussion). However, I am not able to import the System.Data.SqlServerCe.SqlCeException into my code. Therefore in consequence I am not really able to access any more information about the exception. How can I import this exception to my project so I could work with it? The only idea I got was to add Entity framework, but for some reason NuGet fails to install it.
EDIT:
For further generations, I am still not able to access it, even the Reflections seems to reject messing with it (MethodAccessException thrown when I tried to access the value of Errors property of the SqlCeException). At least the SqlCeException.ToString() method returns quite a meaningful description.
You can't connect to an SQL db from Windows phone, the best way it to create a REST Web Service which connects to your db and start consuming it.

Localization in a WCF server

I am fairly well versed in using localization in a simple WPF UI application.
I am now in the process of developing a WCF client/server architecture; I want to be able to create various types of exception in the server, and have the error message in the culture of the client.
This seems straightforward enough - somehow we will identify the culture being used by the particular WCF client at the time.
However, I want the messages to potentially also be logged into the server's logfile in one language (typically English) to allow easier support of the application.
There are various assemblies used in both the server and the client side; each assembly is going to have a string table of error messages. Therefore when an exception is created, it needs to have the resource ID and the resource manager for that given assembly to hand. Without sub-classing each available exception type, I cannot see how to get around this. This seems like a lot of work for a problem that has surely been encountered before?
Example
Server.A.dll
Error Resources: MyErrorString1, MyErrorString2
Resource Manager: ResourceManagerA
Server.B.dll
Error Resources: MyErrorString3
Resource Manager: ResourceManagerB
So ideally I need to have access to the resource manager for a given string at the time I need to either log the message to the file or send it back over WCF as a fault; but I don't want to lose the ability to catch types of exceptions by using one generic exception class.
Does anyone have any experience of this problem, or any cool suggestions on how to go about implementing it?
Thanks in advance,
Steve
I don't think that is good idea to show plain Exception messages to users. Instead, I would catch them log them and show friendly message in UI. That way you won't need to subclass anything...
If it is a technical exception, there is no need for details that the user won't understand anyway. Just display a generic error message.
As for expected error condition, they should be cataloged somewhere. Then you just need to exchange error codes between client and server and do the localization on the client based on the error code.

How to catch and save compile time and run time errors of my solution project in Visual Studio 2008/2010

I am currently trying to figure out a way on how I can possibly save the compile time and runtime errors (in database tables) that the project/solution/website in my visual studio solution explorer could possibly throw.
Thanks for the help in advance.
Update: For now I would want to log the errors only for C# language.
I am desperately looking for a way or solution to implement this...any help will be deeply appreciated...
NiK.
Compile time errors are saved in a html buildlog, check your output window for the link. Shouldn't be too hard to put in a database. A piece of software that does use this information is CruiseControl.Net, so you could probably learn from looking at their code.
For runtime errors, it's impossible to answer. First of all, it's unclear what you are asking. By "runtime errors", do you mean exception eg divide by zero? Second, this is also very different between different languages supported in VS, eg .NET languages and straight C++.
Update: Since you're on the .NET platform, I suggest you either wrap your main function with a try/catch block that catches all thrown errors, and just log all the information you can get from that error to your database (eg stack trace, Exception kind, perhaps a minidump). This, of course, will not work with errors that are caught or swallowed. In case you would also want to log those (for whatever reason), you would have to do some more clever source transformations, for example by using reflection. An example would be to add logging to the constructor of the base class Exception.
My suggestion would be to look into developing an extension to visual studio, similar to Jetbrain's Resharper. Visual Studio exposes a rich api for interacting with the IDE itself. If you are using command line builds outside of visual studio, you may need to pipe the output to a file and parse it.
Here's a few links to get you started on developing an extension/add-in:
http://msdn.microsoft.com/en-us/library/dd885119.aspx
http://msdn.microsoft.com/en-us/vstudio/bb968855
And here's a link for a video for integrating with the error list:
http://msdn.microsoft.com/en-us/vstudio/cc563922
Runtime errors may be easier since there is an appdomain exception event that you can handle. You can wire up a handler to this event and log the exception.
http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx
For handled exceptions, there are a couple of techniques. Microsoft has an exception handling block that can be used, or you could create a custom exception type that you use throughout the application.
Sound like you want this for a website. You can create a Global class (Global.asax.vb) and then handle the error in the Application_Error event. This is where you deal with any unhandled exceptions (vb example is what I have):
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim appException As System.Exception = Server.GetLastError()
Dim tempException As System.Exception = Nothing
If appException Is Nothing Then
Return
End If
tempException = appException.InnerException
tempException will hold the unhandled exception and you can store it in a database, or email it to someone. Your choice.
You can do something very similar in winform apps by handling the _unhandledException event in the Application events.
Visual Studio Project files are MSBuild files which can contain custom compilation steps. Maybe it's possible to replace the compilation step with a custom step which calls the CSharp compiler and logs the error.
If you give us a bit more information on what you want to use it for, maybe we can provide alternative solutions. For example do you need to log the errors from inside visual studio or is it enough to have an external tool log these errors?
Only the C++ compiler does a buildlog. C# does not. You will have to either go the plugin/extension route (in which case, use Dave Ferguson's suggestions to get started) or you can use the command line to compile (csc.exe) and pipe the output to a file (csc.exe /options >> log.txt), and parse it.

All the time getting WebResource.axd?d=.... errors

I have an ASP.NET C# application and I am getting different errors all the time, like the one you can see below. Does anyone know how to fix that? Thank you.
Page: http://www.sitename.com/WebResource.axd?d=OYuYekAZWSmOdOaJyDRqKg2&t=634022222718906250
Message: This is an invalid webresource request.
Source: System.Web
Inner Exception:
Stack Trace: at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I can think of three causes, only one of which actually point to a real error as such:
Somebody is trying to exploit a security hole in asp.net (a patch here) where you can get one of the axd handlers to serve up any content on the web server if you can figure out the encryption key. It is unlikely, but its possible. In this case, you don't have to do anything, except make sure that you have that fix applied.
(This is something I have observed on a site that I just finished) The scenario is where an existing site has been replaced or where the web server has been changed from what it was previously. If you have a site that is public and on Google, say, people might often view 'cached' page if they're trying to get to old content or indeed if the current page is not what they expect (perhaps an error or indeed just different). The problem being that if the site uses webresource.axd, that page will have a reference to it. The browser opens the cached html and then makes the request. If the site has been changed or is a replacement then the old axd links might not be valid any more and will cause an error.
If this is an mvc site you might no longer be using resources rendered by the axds, in which case you could consider removing them from the site by editing the web config and adding 'remove' entries for them in the handlers section of system.webserver. Then the requests will yield a 404 and no longer will you get errors. Equally if the site does use axds legitimately, but you can't repro the errors yourself by browsing it, then you probably don't have anything to worry about.
the site runs in a web farm and each machine therefore needs to have the same machine key, this is the one actually needs attention if it is the case. I left it till last, tho, because looking at your other questions I'm assuming a web farm is not involved :)
I would have liked to format this answer better but I am on my phone, apologies!
Additionally to Andras thorough (and impressive from a phone:) answer, there was a bug in IE8 (patched already, but some may still have it in the wild) that use to cause a similar error. Although in that case the request came with garbage at the end, which does not seem to be your case, but it may give you a different thing to look at. Here's a question on SO that talks about it
Invalid Webresource.axd parameters being generated

Categories