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.

Andronicus
  • 1,799
  • 1
  • 14
  • 28

2 Answers2

2

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,799
  • 1
  • 14
  • 28
  • +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. – Todd Main Sep 08 '10 at 02:09
1

A common reason for blank pages on IIS Deployment is the lack of MIME TYPES definitions. Depending on the kind of silverlight application one has to add one or more of the following types:

.xap application/x-silverlight-app .xaml application/xaml+xml .xbap application/x-ms-xbap

Nikos Tsokos
  • 3,226
  • 2
  • 34
  • 41