I'm working on an upgrade project, the old one is based on .Net 3.5, it look like this:
.Net Remoting Host -> LibraryInterface -> LibraryWorker (wrapper of COM object)
Now the upgraded one is based on .Net 4.0:
WCF 4.0 Host -> LibraryInterface -> LibraryWorker (wrapper of COM object).
When I test it, the WCF host (be it console host or windows service host, it doesn't matter) just crashes (client receives SocketException - An existing connection was forcibly closed by the remote host), and 2 errors in event log on server:
---
Event Type: Error
Event Source: .NET Runtime
Event Category: None
Event ID: 1026
Date: 1/18/2011
Time: 11:30:09 PM
User: N/A
Computer: X
Description:
Application: ConsoleHost.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.MethodAccessException
Stack:
at MS.Internal.PrintWin32Thunk.PrinterDefaults.!PrinterDefaults()
at MS.Internal.PrintWin32Thunk.PrinterDefaults.Dispose(Boolean)
at MS.Internal.PrintWin32Thunk.PrinterDefaults.Finalize()
---
Event Type: Error
Event Source: .NET Runtime 4.0 Error Reporting
Event Category: None
Event ID: 5000
Date: 1/18/2011
Time: 11:29:50 PM
User: N/A
Computer: X
Description:
EventType clr20r3, P1 consolehost.exe, P2 1.0.0.0, P3 4d3685e4, P4 system.printing, P5 4.0.0.0, P6 4ba1f817, P7 a4, P8 0, P9 system.methodaccessexception, P10 NIL.
---
It works fine under .Net 3.5 Remoting, , and the LibraryWorker is pretty much the same in 2 projects. I really have no idea why it fails so deadly in .Net 4.0 WCF... Any help will be great!