Silverlight 4 应用程序在发布版本中显示空白页面
我正在开发一个相当大的 Silverlight 4 应用程序(1 个解决方案中有 42 个项目),并且我正在努力解决一个非常奇怪的问题。
该应用程序在调试版本中工作正常,即使在发布版本中,它也可以在附加调试器(F5)的情况下运行,但是当它在没有调试的情况下运行时,silverlight xap 会加载,然后只显示一个空白页面。
我正在处理未触发的 Application_UnhandledException,因此几乎不可能从中获取任何有用的信息,特别是因为我无法使用附加的调试器重现此行为。
当附加调试器时,运行时有哪些差异可能会导致此问题?
编辑:我还应该补充一点,调试构建也可以在没有附加调试器的情况下运行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,问题在于发布版本执行了一些改变调用程序集的优化。
我们使用反射在 IoC 容器中注册类型,并在调试 Assembly.GetCallingAssembly().GetTypes() 中始终返回预期的程序集。但在发布模式下,调用程序集是生成的匿名托管动态方法程序集,因此我们的类型未在 IoC 容器中注册,并且应用程序在发布模式下崩溃。
修复方法是使用 this.GetType().Assembly 代替。
使问题更加复杂的是,当 IoC 容器抛出异常时,Silverlight 只显示一个空白页面,因此很难确定失败的原因。当然有某种方法可以改变这种行为吗?
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?
IIS 部署上出现空白页的常见原因是缺少 MIME 类型定义。
根据 silverlight 应用程序的类型,必须添加以下一种或多种类型:
.xap application/x-silverlight-app
.xaml 应用程序/xaml+xml
.xbap 应用程序/x-ms-xbap
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