Application closed when using Socket.IO through SocketIO4NET using WCF duplex channel

I use SocketIO4Net to connect to Socket.IO with C #, but when I try to pass an object to clients, my C # application suddenly closes (I have an MVC3 project)

I read Event Viewer and there are three errors:

1)

A Webhost unhandled exception occurred. Sender Information: System.AppDomain/26995560 Exception: System.Runtime.FatalException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. 

2)

 An unhandled exception occurred and the process was terminated. Application ID: /LM/W3SVC/2/ROOT Process ID: 3696 Exception: System.Runtime.FatalException Message: Object reference not set to an instance of an object. 

3)

 Application: w3wp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Runtime.FatalException Stack: at System.Runtime.Fx+IOCompletionThunk.UnhandledExceptionFrame(UInt32, UInt32, System.Threading.NativeOverlapped*) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*) 

What happened to my project? Is there a bug in SocketIO4NET?

+4
source share
1 answer

Finally, I found the answer, this is because the version of .NET (I use .NET 4) and WCF duplexChannel.

You must add this attribute to the top of the WCF shell class:

 [CallbackBehavior(UseSynchronizationContext=false)] 

Thanks to Cauldwell.net for the answer: http://www.cauldwell.net/patrick/blog/CategoryView,category,CodeGen.aspx

From cauldwell.net:

The problem turned out to be that ASP.NET uses (by default) a small thing called SynchronizationContext. As close as possible (I honestly did not investigate this completely), one of them is to make sure that any callbacks are launched in the user interface thread, thereby eliminating the need to call Control.Invoke, as in WinForms. In my case, that an additional lock gave something, and it was trying to put things on a thread that was not around, therefore, to the exception NullReferenceException.

Special thanks to James

0
source

All Articles