views:

118

answers:

2

I'm working on a fairly large Silverlight 4 application (42 projects in 1 solution), and I'm wrestling with a really strange issue.

The application works fine in a debug build, and even in release build it runs with the debugger attached (F5), but when it is run without debugging the silverlight xap loads and then shows only a blank page.

I'm handling Application_UnhandledException which is not firing, so it's almost impossible to get any useful information from it, especially since I cannot reproduce this behaviour with the debugger attached.

What differences are there at runtime when the debugger is attached that could possibly cause this problem?

Edit: I should also add that the debug build also runs without the debugger attached.

+1  A: 

It turns out that the problem was the release build performs some optimizations that alter the calling assembly.

We register types in an IoC container using reflection, and in debug Assembly.GetCallingAssembly().GetTypes() always returns the expected assembly. But in release mode the calling assembly is the generated Anonymously Hosted DynamicMethods Assembly, hence our types were not registered in the IoC container, and the app crashes in release mode.

The fix was to use this.GetType().Assembly instead.

What compounds the problem is that Silverlight just shows a blank page when an exception is thrown from the IoC container, so it's very hard to identify the cause of failure. Surely there is some way to alter this behaviour?

Andronicus
+1. Good find and follow up. This question/answer is surely to be of good use to others in the future who run into the issue.
Otaku
A: 

Hi,

We updated to the latest version 4.0.50826.0, getting this error and a blank page randomly [quite often]..

Our app is in production, everything was working good, but, the latest silverlight release mesed it up.

Any thoughts?? Thanks!!

at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize) at System.Windows.FrameworkElement.MeasureOverride(Size availableSize) at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

Niray
the blank page is production is most probably just an unhandled exception. Do you handle the UnhandledException event in App.xaml.cs?
Andronicus