在 HTTP 处理程序中实例化 Silverlight 控件,...可能吗?
我在 ASP.Net 项目中有一个 HTTP 处理程序,并且想要基于呈现为位图的 Silverlight 用户控件生成图像。
但是,在 ProcessRequest 中,当我尝试实例化任何 Xaml 控件时,出现以下异常......
{“类型初始值设定项 “MS.Internal.JoltHelper”抛出了一个 例外。”}
...具有以下堆栈跟踪...
在 MS.Internal.JoltHelper.get_ThreadID() 在 MS.Internal.XcpImports.CheckThread()
在 System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex、IntPtr 构造DO)
在 System.Windows.Controls.UserControl..ctor() 在 CaseCard..ctor() 中 C:!WORKING_FOLDER\Trunk\ProActive\ProActive.UI\CaseCard.xaml.vb:line 6 在ServiceLocator.GetCard()中 C:!WORKING_FOLDER\Trunk\ProActive\ProActive.UI\ServiceLocator.vb:line 20 点 ProActive.Host.ImageGeneratorHandler.ProcessRequest(HttpContext 上下文)中 c:!WORKING_FOLDER\Trunk\ProActive\ProActive.Host\App_Code\ImageGeneratorHandler.cs:line 10 点 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,布尔值&同步完成)
...而内部异常是这个...
{“无法加载文件或程序集 'System.Xml,版本=2.0.5.0, 文化=中立, PublicKeyToken=7cec85d7bea7798e' 或 它的依赖项之一。系统 找不到该文件 指定。":"System.Xml, 版本=2.0.5.0,文化=中立, PublicKeyToken=7cec85d7bea7798e"}
现在,..几个月前我继承了这个项目,它的状况很糟糕。我正在努力让它回到正轨,但某个地方确实存在一些问题,所以完全有可能是环境问题 话虽
因为 Silverlight 运行在完全不同的框架上,我真的必须回到 GDI+ 才能完成这项工作吗?
如此,我开始怀疑这是否可能,
I have an HTTP Handler in an ASP.Net project and wanted to produce an image based upon a Silverlight User Control rendered out as a bitmap.
However, in the ProcessRequest
, when I try to instantiate any Xaml control, I get the following exception....
{"The type initializer for
'MS.Internal.JoltHelper' threw an
exception."}
... with the following stacktrace ...
at
MS.Internal.JoltHelper.get_ThreadID()
at
MS.Internal.XcpImports.CheckThread()
at
System.Windows.DependencyObject..ctor(UInt32
nativeTypeIndex, IntPtr constructDO)
at
System.Windows.Controls.UserControl..ctor()
at CaseCard..ctor() in
C:!WORKING_FOLDER\Trunk\ProActive\ProActive.UI\CaseCard.xaml.vb:line
6 at ServiceLocator.GetCard() in
C:!WORKING_FOLDER\Trunk\ProActive\ProActive.UI\ServiceLocator.vb:line
20 at
ProActive.Host.ImageGeneratorHandler.ProcessRequest(HttpContext
context) in
c:!WORKING_FOLDER\Trunk\ProActive\ProActive.Host\App_Code\ImageGeneratorHandler.cs:line
10 at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at
System.Web.HttpApplication.ExecuteStep(IExecutionStep
step, Boolean& completedSynchronously)
... and the inner exception is this ...
{"Could not load file or assembly
'System.Xml, Version=2.0.5.0,
Culture=neutral,
PublicKeyToken=7cec85d7bea7798e' or
one of its dependencies. The system
cannot find the file
specified.":"System.Xml,
Version=2.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e"}
Now,..I inherited this project a couple of months ago and it's 'in awful condition. I'm battling to get it back on track but there are some real issues somewhere so it's entirely possible that something is environmentally amiss.
That said, I'm starting to wonder if this is possible since Silverlight runs on a totally different framework. Do I really have to go back to GDI+ to get this done?
Any and all help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不起作用的原因是因为您的 ASP 代码在完整的 .NET 框架的上下文中运行,并且在尝试实例化 Silverligt 控件时 - 就像异常所示 - 程序集
System.Xml
具有2.0.5.0 版本无法加载/找不到。请注意版本:2.0.5.0。所有 Silverlight 核心 DLL 都具有此版本,而不是“普通”.NET 版本(如 2.0.0.0)。
这并非偶然 - Silverlight 在小型 CLR 的上下文中运行,该小型 CLR 是常规 CLR 的子集。它不是同一个 CLR,尽管其中大部分完全相同,并且 C# 源代码完全相同,但运行时不相同。
目前,您无法将 Silverlight 代码与完整的基于 .NET 的代码(如 ASP.NET)混合。
Microsoft 内部正在进行一些工作,提取常规 .NET 和 Silverlight(实际上是几个库)的公共核心,以便更好地共享,但尚未公开。
另请注意,如果 Silverlight 4.0 库之一的源代码不使用 Silverlight 特定代码,您可以将其加载到常规 .NET 进程中,但反之显然是不可能的(Silverlight 是子集,而不是相反)。
除此之外,您可以通过以下方式实现您的目标:
两者的特殊性都不容易,尽管我倾向于第二个选项,它更干净。
The reason this doesn't work is because your ASP code is running in the context of the full .NET framework and while trying to instantiate Silverligt control - just like the exception says - the assembly
System.Xml
with the version 2.0.5.0 is not loadable/found.Note the version: 2.0.5.0. All of the Silverlight core DLLs have this version instead of 'normal' .NET version like 2.0.0.0.
This is no accident - Silverlight runs inside the context of the small CLR which is a subset of the regular CLR. It's not the same CLR, though most of it is completely identical and while your C# source code is exactly the same, the runtime isn't identical.
At the moment, you can't mix Silverlight code with the full .NET based code like ASP.NET.
There is some work being done inside Microsoft on extracting common core of regular .NET and Silverlight (a couple of libraries actually) for better sharing, but that's not yet publically available.
Also note that if the source code of one of your Silverlight 4.0 libraries does not use Silverlight specific code, you are able to load it into regular .NET process, but the reverse is obviously not possible (Silverlight being the subset, not the other way around).
All this aside, you might achieve your goal by:
Neither is particularity easy, though I'd lean towards the second option it's cleaner.