无法转换透明代理以从AppDomain输入 [英] Unable to cast transparent proxy to type from AppDomain

查看:202
本文介绍了无法转换透明代理以从AppDomain输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在appdomain中创建一个对象:

I'm trying to create an object in an appdomain:

var type = typeof (CompiledTemplate);
var obj = (CompiledTemplate) domain.CreateInstanceAndUnwrap (
    type.Assembly.FullName, type.FullName);

但是,我总是遇到以下错误:

However, I always get the following error:

无法强制转换透明代理以键入"Mono.TextTemplating.CompiledTemplate".

尽管名称空间可能显示了建议,但我还是在.NET 4.0而不是Mono上运行:)

I'm running on .NET 4.0, not Mono, despite what the namespace might suggest :)

据我所知,当.NET认为Type&程序集在两个域中不完全匹配.但是,调试时,FullName和Location是相同的.只有Assembly.Codebase属性有所不同-在子AppDomain中,由于某种原因,其扩展名大写为"DLL".

As far as I know, this error happens when .NET thinks that the Type & Assembly do not exactly match in the two domains. However, when debugging, the FullName and Location are identical. Only the Assembly.Codebase property differs - in the child AppDomain its extension is uppercased to "DLL" for some reason.

我尝试将AssemblyResolve处理程序添加到AppDomain,该处理程序使用Assembly.LoadFrom显式加载文件名,但是CodeBase的扩展名仍然大写.由于原始程序集也已通过Assembly.LoadFrom(通过Mono.Addins)加载,因此CodeBase值之间的差异似乎很奇怪.

I've tried adding an AssemblyResolve handler to the AppDomain, which uses Assembly.LoadFrom to load the filename explicitly, but the CodeBase's extension still gets uppercased. Since the original assembly was also loaded with Assembly.LoadFrom (via Mono.Addins), the difference between the CodeBase values seems very strange.

有任何解决或解决此问题的建议吗?

Any suggestions for fixing or working around this problem?

推荐答案

您是否遇到程序集加载上下文问题? (例如,请参见此处) 您的类型显然在装入上下文中(因为您使用的是typeof(CompiledTemplate)),但是您是说辅助AD中的类型已装入到装入源上下文中.

Could you be running into an issue with assembly load contexts? (e.g. see here) You have a type that's clearly in the load context (because you're using typeof(CompiledTemplate)), but you're saying that the type in the secondary AD is loaded into the load-from context...

您是否已使用 fuslogvw 检查以确定确切的程序集装? fuslog跟踪还将告诉您是否将程序集加载到不同的上下文中.

Did you check with fuslogvw to determine exactly what assemblies are being loaded? The fuslog trace will also tell you if the assemblies are being loaded into different contexts.

这篇关于无法转换透明代理以从AppDomain输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆