Archive for March, 2010

Silverlight, REST, and Unhandled Exception

March 19th, 2010

As part of the final push to finish up our brand-new, Silverlight 3, MVVM application I have been writing a lot of logging and instrumentation code.  Any new platform is a risk, and while we believe we have taken a solid approach using MVVM and the unit testing it allows, we still don’t really know how this thing will perform in the field.  With this in mind, I am trying to be rather liberal in the logging.

In Silverlight, one can write code to handle any unhandled exception in the application.  This type of functionality exists in Winforms, WPF and ASP.Net, so I wasn’t terrible surprised to find it available.  This is incredibly convenient.  I can attack areas likely to cause exceptions such as web service calls with specific logging and exception handling code, and catch everything else with a few lines of general-purpose logging.

As soon as I implemented this catch all I immediately started getting log messages stating:

No XAML was found at the location ”.

at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)

at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)

at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)

at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)

Well, that was really helpful.  And after some Google searches I soon realized that I wasn’t going to find a solution on the web.  Well, I guess this is why I actually get paid to program.  After some testing I discovered that the only time I saw this error (and it was just logging, it never bubbled up to the UI) it was when leaving the Silverlight app for another page in our web application.

Our app takes advantage of Silverlight’s Frame + Page navigation handling, which can map one URI to another.  In practice this is basically REST.  When the frame “hears” a new URI entered it converts the URI  to an internal, component-based URI with the location of the Silverlight page to display.  These mappings are configured during our bootstrap process which rides on top of Prism.

As it turns out, when the user (me) clicks on a link to leave the Silverlight app, the frame “hears” a new URI.  The browser is navigating, and the frame tries to handle it.  But it doesn’t have a mapping for the URI, which is curiously an empty string no matter where outside the Silverlight app one is navigating.  The frame barf, and produces the above exception.  But no one sees it because the app is closed within a split second of all this happening.

After poking and prodding with various ways of squashing this, I finally figured out that in the Navigating event of the Frame I can just set e.Cancel = true, which tells the frame to not navigate.  My conditional logic simply checks to see if the URI is empty.  The browser continues on with its business, and the Silverlight app ignores the navigation from that point on.

Hopefully this entry helps someone else doing REST in Silverlight.

The Algebraist

March 15th, 2010

There are two Iain Banks.  There is Iain Banks, the Scottish Author of such novels as The Wasp Factory and Transition.  There is another Banks, Iain M. Banks, the Scottish Author of modern science fictions masterpieces such as books from The Culture Series.  Well, OK, the two Banks are the same guy writing under slightly different names to denote when he is writing regular fiction (no M.) and science fiction (M.).  Banks is well respected in the world of literature, and I suspect one of the reasons he has gained so much respect is that he does a lot of non-science fiction.  Banks is an excellent writer in the truest sense; his prose is unusually rich without feeling unusually rich.  I sometimes marvel at coloring he has invented for a particular scene, or his subtle humor sprinkled throughout his works.

Banks, on top of being an exception writer, is also a world-class story teller and science thinker.  His stories tend to be more hard-science fiction while sticking to many traditional science fiction themes.  In short, he draws from the best of various genres when spinning his science fiction tales.  And The Algebraist is no exception.

The world of The Algebraist feels like that of The Culture in some ways, very different in others.  The universe he paints consists of a culture billions of year old, similar in many ways to The Culture.  But unlike The Culture, there are no Faster Than Light drives, no teleportation, and many of the main characters are no where near humanoid.  In these points The Algebraist departs significantly from The Culture.

Banks’s novel follows 3 main characters that grew up together throughout their many-centuries lives.  One, Seer Fassin Taak, serves as the protagonist of the story.  Taak (or Fassin as he is called throughout much of the story) is a kind of futuristic anthropologist, archeologist, historian, and adventurer, all rolled into one.  He is part of a collection of individuals that dive into gas giants with small, personal ships to communicate with the life forms there.

Banks’s inventiveness here is quite fun to read.  The Dwellers, the very strange race that inhabits gas giants throughout the galaxy, is quite different from humans in many ways and strikingly similar in others.  Their technology is far more advanced than the current human culture, yet most live only to party and have fun in a strange economy of “kudos”.  In many ways the Dwellers are more human than us, in other, frightful ways, they are very alien.

The main plot of the book sees Taak sent on a mission for the current human government.  The result of that mission is surprising.  I found the ending to be quite fulfilling, especially the afterward.  Upon finishing the book, I can honestly say that it is probably one of the best written books I have ever read.  While the story line was fairly clever, I have read much more original or through-provoking books.  But fewer books have provided the pure joy in reading that this book did.  The Algebraist is a find story told excellently, and I highly recommend it.

ASP.Net MVC 2 Is GA

March 12th, 2010

Scott Guthrie just posted on his blog that ASP.Net MVC 2 has been released.  Looks like I am going to have to buy a new ASP.Net MVC book, and I didn’t even finish the last one!

Dempster vs Bradley

March 11th, 2010

Carrie Muskat has a short interview with Ryan Dempster over on her blog.  Dempster addresses Milton Bradley’s recent statements about the Cubs.  Here is what I wrote about the situation on Muskat’s site:

I cannot speak for other Cubs fans, but personally I gave Milton Bradley the benefit of the doubt when he came to Chicago, and even when he struggled early in the season. I really wanted the man to succeed. It would have been a wonderful story for him to have finally grown up and really contributed to the Cubs. Seriously, who would not have liked that outcome? People can change, and for him to have found a home in Chicago would have been a point of pride for him and the Cubs. But that isn’t what happened, and for me its obvious that its almost entirely Bradley’s fault.

I continued on comparing Bradley to Dempster, who struggled a few years back for the Cubs but handled it in a very different way:

Compare and contrast this with Dempster three years ago. He wasn’t a good closer. I wasn’t happy with the man at all. But I never, ever felt like he wasn’t trying. I never felt about him the way I felt about Bradley mid-season last year, even before Bradley started shooting off his mouth about the fans. Dempster’s talent and character have obviously shined through. He endured a tough situation and came through for the Cubs, for the fans, and for himself. Milton Bradley should study Ryan Dempster. This is the type of player Bradley should try to be.

Jewel Cave

March 3rd, 2010

When I was little  we lived in Newcastle, WY.  My mother and father were public school teachers.  In the summers they did a number of things.  For a couple of summers my father worked as a park ranger at Jewel Cave National Monument.  I grew up listening to stories about my father’s time at Jewel Cave.

Jewel is a beautiful cave.  Jewel is an apt description.  There are many crystalline features that make it a must see if you are visiting The Black Hills.  I found this video online from National Public Radio about a spelunking adventure at Jewel:

What If You’re Wrong?

March 2nd, 2010

Non-Believers Giving Aid

March 1st, 2010

If you haven’t noticed I support Non-Believers Giving Aid, a great, new charitable organization that is designed to provide aid to the victims of the Haiti earthquake and beyond.  Please give if you can.  Currently the money donated is split 50/50 between Doctors Without Borders and The Red Cross.  And you can be sure that there aren’t any bibles being bought with the money, and those providing aid aren’t doing so with the caveat that the victims listen to a sermon first.

GivingAid.RichardDawkins.net

Staw Man

March 1st, 2010

Science isn’t about the person, its about the theory and the evidence.  Of course the people matter as they are the ones doing all the work, but at the end of the day our understanding of the universe and the natural world does not rely upon one person being right or wrong, but upon the evidence we find to support specific conclusions.  The theory itself might be changed, by the original author or by many in the scientific community, to more closely agree with the data.  This is a basic tenant of science.  We judge the resulting product based on the evidence, not whether it conveniently falls into a religious or political ideology.

Image if Einstein decided to retract general relativity in the late 1920s, with no reason or evidence justifying this action.  Imagine he simply decided that he no longer supported the idea.  Surely that would have caused a great stir in the scientific world and particularly in the world of theoretical physics.  However, the scientific community, in the end, would not have abandoned general relativity without proof it was wrong.  They would have stood by the theory, since in the 1920s there was already a lot of proof that it was very right.  We don’t need Einstein to agree that the theory is sound; we need evidence to agree that the idea is sound.

Similarly with evolution, Darwin doesn’t really matter other than the fact he first proposed it.  What matters is not what aspects of his original theory are right or wrong, though the vast majority of Darwin’s original theory has survived the test of time and more than one revolution in biology.  What Darwin said or did doesn’t change reality.  The theory, backed with evidence, changes our perceptions.  And that evidence is overwhelming in the cases of General Relativity and Evolution.  An attack on Darwin, or Einstein, is just an attack on a person, not on all the evidence supporting their theories.

A belief in evolution is not a faith.  Its based on the fact that evolution has been proven true by multiple, separate lines of evidence.  Evolution, for all intents and purposes, is a scientific fact.  It doesn’t matter what attacks might be made on the great man.  Those attacks, or anything Darwin said or did, does not change the physical reality that all organisms have evolved to their current states via natural selection.