Q:

Application closed when using Socket.IO via SocketIO4NET by WCF duplex channel

I use SocketIO4Net for connecting to Socket.IO with C#, but when I try to emit an object to clients, my C# application suddenly gets closed (I have an MVC3 project)
I read Event Viewer and there's 3 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's wrong with my project? Is there any bug in SocketIO4NET?

A:

Finally I found answer, this is because the version of .NET (I use .NET 4) and the WCF duplexChannel.
You should add this attribute on the top of WCF wrapper 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, it turned out, was that ASP.NET uses (by default) a
  little thing called the SynchronizationContext. As near as I can tell
  (I haven't researched this thoroughly, to be honest) one of it's jobs
  it to make sure that any callbacks get run on the UI thread, thereby
  obviating the need to call Control.Invoke like you do in WinForms. In
  my case, that additional lock was giving something fits, and it was
  trying to clean stuff up on a thread that wasn't around any more,
  hence to NullReferenceException.

Special thanks to James

