使用GAC在AppDomain之间共享数据(System.InvalidCastException)

时间:2015-07-06 21:11:54

标签: c# gac

我创建了一个'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

1 个答案:

答案 0 :(得分:0)

我的猜测是你没有在Project Debug Settings中禁用Visual Studio Hosting过程。 Visual Studio将在AppDomain中托管进程中托管代码,而不进行程序集共享。