How can I get details about a Silverlight code generation exception? - silverlight

I'm getting the following error now when I build my Silverlight Business Application:
The code generator
'Microsoft.ServiceModel.DomainServices.Tools.CSharpCodeDomClientCodeGenerator'
encountered a fatal exception and
could not generate code for project
'C:\Software\ProjectPartCenterAdmin\Alpha\Latest
Version\ProjectPartCenterAdmin\ProjectPartCenterAdmin.csproj':
Exception has been thrown by the
target of an invocation.
I DID ABSOLUTELY NOTHING TO MY CODE since it last worked! All I did was a clean rebuild of the application. Is there a way to get the details on what the exception was? I am dead in the water until i can figure this out.
Oh, and by the way, I hate code generation! I've had endless problems with RIA Services and I'm trying my best to do things "the right way"; that is, no hacks.
Edit:
I've also been getting a similar warning:
The following exception occurred
creating the MEF composition
container:
Unable to load one or more
of the requested types. Retrieve the
LoaderExceptions property for more
information.
The default code
generator will be used.
I've been getting this for some time now, and have ignored it because the application seems to be working fine.
Also, when I remove my CustomValidation attributes the exception goes away. But the warnings do not.

First, you need to check if there were custom validation errors in the project. I had the same issue but when I realized that I had two validation result methods with the same name! and change it, the built was successfull.

Related

babel-node error 'Reference error: window is not defined'

I was given the task to implement server-side rendering for a react application. I've followed the this tutorial: https://scotch.io/tutorials/react-on-the-server-for-beginners-build-a-universal-react-and-node-app and, afterwards, followed the exact steps on the actual application. Everything worked well with implementing the client-side rendering, but as soon as I continued with the server-side one, I got the following error: 'Reference error: window is not defined'
The problem is that the application uses scrollmagic, which is a client-side-only library (note: I added conditionals 'require' to any scrollmagic references in the code itself, but I can't find a way to bypass the module).
I thought about adding the scrollmagic library on the client-side, but as soon as I remove it I get an error from the 'require' statements.
I apologize if this is something obvious but I am new to JavaScript and have been searching for a couple of days and found nothing so far. If I can provide any additional information please let me know! Also, if you have any suggestions as to how I should handle this, I am all ears!
Best regards,
Andrew
The window object is a property of the browser/client, so you will not have access to it when executing javascript on the server. A library such as: https://www.npmjs.com/package/window-or-global can help, as well as adding conditional logic to check for the window object before executing code that depends on it.
In addition to the suggestion by #sconway to manually check for the presence of window when calling these client-side methods another method I have used in the past is to put that code in componentDidUpdate life-cycle method.
This method is guaranteed to not be called on the server, only on the client.

Silverlight Exception Message is different on other machines

I am currently stuck with the following problem and running desperately out of ideas, any clues are welcome!
We are using a custom built framework that loads what we call "pages" on demand for the UI, each of these "pages" is a self contained Silverlight XAML that is loaded on demand via:
XamlReader.Load(somePageXamlFile)
It may happen that a part inside this xaml is outdated, so a try / catch block ensures that a XAMLParseException is caught and the respective error handled.
Our current error handling is heavily based on the message of the exception, e.g. we expect a message like this:
"The type 'someType' could not be found. [Line: x Position: y]"
-> we parse the message string and replace the essential xaml parts with custom logic to make it valid again and display info for administrators.
The problem:
Some test machines throw the same exception, but with a different message!
Errormessage there:
"Error 2502 An error has occured."
This breaks our "safety net" logic for this case and currently we can not figure out any reason for this.
Solutions or proposals are very welcome,
thanks in advance!
-Steve
After long and hard search we came down to the following: The clients and the development machines seem to have different versions of the Microsoft agcore.dll (development machines have 2 different version in different paths). As this is the core of the exception we suppose this is the reason for the different error message - we were unable to fix this issue however (we cannot be sure what dll our clients get during SL5 download...) therefore we decided to rewrite the whole code segment to not make use of the exception message text at all. Lesson learned.
Thanks for the feedback. -Steve

Using elmahr.elmah in winform application

I have recently shown to my team leader the ElmahR Dashboard and now he wants to implement ExceptionsLog with ElmahR in all of our current projects, including those that are Winform Applications, and after many days of searching I can't find a way to add a Winform Application as "ElmahR source".
Does anyone have a clue?
ErrorPostModule in ElmahR.Elmah does not support Winforms apps because it's been written to be an ELMAH module, so it's tied to an ASP.NET lifecycle and cannot be easily adapted. That said, ErrorPostModule does not do anything so magic and can be easily taken as a guideline to write a small "handler" to be used in a Winforms app. Take a look at its code here, what you should do is:
replace what's in the OnInit method, which simply reads configuration bits and attaches the error handler
when an error occurs, handle it like it's done in the SetError method to post it to the right destination reading the configuration parameters you read before. You would reference ELMAH and create an Error instance from your exception, and then use ErrorJson.EncodeString to encode it
You may want to borrow the W3.cs file to simplify the http form compilation.
At some point I might generalize this work and put it in ElmahR.Elmah, but not sure when I'll be able to do it.
I just forked the elmahr source code to work on this, I want to post errors from console applications, so I'm going to remove the dependency on Elmah and create the "error" objects and send them to the dashboard.
It's a work in progress but can be used as starting point for solving your problem.
https://bitbucket.org/rudygt/elmahr
Update: the fork now include full support to post to ElmahR using a ServiceStack endpoint, using json over http. This remove the dependency over the original Elmah to publish errors to the dashboard. The first example is a C# Console Application

How to detect and wrap "debugging resource strings are unavailable" w/o installing developer runtime?

I'm working on a Silverlight app that has an UnhandledException handler in the App class, which shows a message box containing the exception message. This is often fine for custom exceptions. However, it's not so good for built-in exceptions (e.g. NullReferenceException), because users don't have the developer runtime installed and therefore get a rather ugly "Debugging resource strings are unavailable" message.
My first thought (which I quickly dismissed) was to check the exception message for "debugging resource strings". I imagine if someone's running the app in, say, French, they'd get something like "les chaînes de ressources de débogage", so that wouldn't work.
Perhaps there's a way for a Silverlight app to detect whether it's running in the end-user runtime vs. the developer runtime? I've looked in the Application and Environment and Deployment classes, and haven't found anything.
I suppose this wouldn't be an issue if the application always threw custom exceptions anytime some sort of message needed to be shown to the user. Then I could easily hide the non-custom ones with a friendlier generic message. Is that the best/only option?
Just from an application design point of view, what user will know what to do with any kind of techy error message? "The value 'null' was found where an instance of an object was required." huh??
A simple "Something bad happened, if it continues, please contact support" should suffice. Just ensure that you log whatever bad happened somewhere, so that when you get the phone call/email, you can retrieve the issue in whatever techy details you require to solve the problem.

How to return warnings from server side to silverlight

We have a business case that need to return both validation errors and warings from server side and display on silverlight.
I see the silverlight is using System.ComponentModel.DataAnnotations.ValidationResult to process errors. It does not contain and fields for "warnings".
I am wondering if anybody has a good idea to handle this problem. Thanks.
I think ValidationResult is used by ValidationException which is thrown by the subclasses of ValidationAttribute. Normally this mecanism is used with blocking validation errors because throwing to exception stops execution of the code. If it happens in your service, the exception can be sent to the client and processessed, but this is not always a wanted scenario.
You could extend this model (those classes ValidationAttribute, its subclasses, ValidationException are not sealed) to add a warning flag but then you'd have to trap the exception to continue the processing and rethrow in case of a warning.
Another alternative is to add business logic validation errors and warnings to your response to the client. I like this approach because you can then include whatever info you want the way you want/need it.

Resources