无法将透明代理转换为来自 AppDomain 的类型 [英] Unable to cast transparent proxy to type from AppDomain

查看:28
本文介绍了无法将透明代理转换为来自 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.

我已尝试向 AppDomain 添加一个 AssemblyResolve 处理程序,该处理程序使用 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天全站免登陆