使用GAC (System.InvalidCastException)在AppDomain之间共享数据
本文关键字:AppDomain 之间 共享 数据 GAC System InvalidCastException 使用 | 更新日期: 2023-09-27 18:01:28
我已经创建了一个'StrongNamed' dll并成功地将其安装到GAC。
应用程序正常运行并共享数据;但是,当我在Visual Studio中处于调试模式时,我得到以下InvalidCastException
.
为什么不能正确调试?
相反,我得到以下错误信息:(基于http://geekswithblogs.net/akraus1/archive/2012/07/25/150301.aspx的代码)
Unhandled Exception: System.InvalidCastException: [A]AppDomainTests.CrossDomainData cannot be cast to [B]AppDomainTests.CrossDomainData. Type A originates from 'StrongNamedDomainGateDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=98f280cda3cbf035' in the context 'Default' at location 'C:'Source'WindbgAuto'bin'AnyCPU'Release'StrongNamedDomainGateDll.dll'. Type B originates from 'StrongNamedDomainGateDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=98f280cda3cbf035' in the context 'Default' at location 'C:'Source'WindbgAuto'bin'AnyCPU'Release'StrongNamedDomainGateDll.dll'.
at AppDomainTests.DomainGate.DoSomething(Int32 gcCount, IntPtr objAddress) in C:'Source'WindbgAuto'Tests'AppDomainTests'DomainGate.cs:line 24
at AppDomainTests.DomainGate.DoSomething(Int32 gcCount, IntPtr objAddress)
at AppDomainTests.DomainGate.Send(DomainGate gate, Object o) in C:'Source'WindbgAuto'Tests'AppDomainTests'DomainGate.cs:line 50
at AppDomainTests.Program.Main(String[] args) in C:'Source'WindbgAuto'Tests'AppDomainTests'Program.cs:line 41
我猜您没有在项目调试设置中禁用Visual Studio Hosting进程。Visual Studio将在没有程序集共享的AppDomain的托管进程中托管代码。