0

I'm playing around with XSockets.NET, and I've spent way too much time debugging what should be a simple problem. I'm using the standard templates that come with XSockets, which create a project called XSockets.DevServer, and a class within that project called DebugInstance. When I host this DebugInstance class within my web project, all seems to work as expected. However, when I try to host it within the XSockets.Debug.Console project, or when I try to get it to run on my production IIS instance, I get a NullReferenceException in the code below:

    [ImportOne(typeof(IXBaseServerContainer))]
    public IXBaseServerContainer wss { get; set; }

    public DebugInstance()
    {
        try
        {
            Debug.AutoFlush = true;
            this.ComposeMe();

            // NullReferenceException on the next line - wss apparently never gets set.
            wss.OnServersStarted += wss_OnServersStarted;
            wss.OnServerClientConnection += wss_OnServerClientConnection;
            wss.OnServerClientDisconnection += wss_OnServerClientDisconnection;
            wss.OnError += wss_OnError;
            wss.OnIncommingTextData += wss_OnIncommingTextData;
            wss.OnOutgoingText += wss_OnOutgoingText;
            wss.OnServersStopped += wss_OnServersStopped;
            wss.StartServers();
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Exception while starting server: " + ex);
            Debug.WriteLine("Press enter to quit");
        }
    }

Clearly the problem is happening within this.ComposeMe(), but there's no troubleshooting information, and since XSockets isn't apparently open-sourced, I haven't been able to step through the code to figure out where the problem is.

EDIT: To be clear, I know what a NullReferenceException is. In this case its immediate cause is the fact that wss is null. What I want to know is its proximate cause, i.e., why ComposeMe() doesn’t assign it, even though that's what it's apparently supposed to be doing. Apparently the homegrown IOC that XSockets is using to support its plugin architecture is supposed to find an instance of IXBaseServerContainer, but it's apparently not - and I have no idea why. And not having the source, I'm not even sure what the candidates for IXBaseServerContainer are.

EDIT 2012-11-06: Here's what the appSettings element of my app.config looks like:

<appSettings>
  <add key="XSocketServerStartport" value="4502"/>
  <add key="UsePolicyServer" value="true"/>
  <add key="XSockets.PluginCatalog" value="XSockets\XSocketServerPlugins\"/>
  <add key="XSockets.PluginFilter" value="*.dll"/>
  <add key="XMessageInterceptorsEnabled" value="false"/>
  <add key="XErrorInterceptorsEnabled" value="false"/>
  <add key="XConnectionInterceptorsEnabled" value="false"/>
  <add key="XHandshakeInterceptorsEnabled" value="false"/>
  <add key="XSocketLogPath" value="XSockets\XSocketServerPlugins\Log"/>
  <add key="XBufferSize" value="8192"/>
</appSettings>

I've got all the files mentioned below in both my $(ProjectDir)\XSockets\XSocketServerPlugins\ and my $(TargetDir)\XSockets\XSocketServerPlugins\ folders, e.g.:

10/29/2012  09:53 AM            15,872 XSockets.Core.Communication.dll
10/29/2012  09:53 AM            70,656 XSockets.Core.dll
10/29/2012  09:53 AM             8,192 XSockets.DevelopmentServer.dll
10/29/2012  09:53 AM            11,776 XSockets.Extensibility.Handlers.dll
10/29/2012  09:53 AM            10,240 XSockets.Extensibility.Interceptors.dll
10/29/2012  09:53 AM            23,040 XSockets.External.dll
10/29/2012  09:53 AM            24,064 XSockets.Protocol.dll
10/29/2012  09:53 AM            39,424 XSockets.Server.dll
11/05/2012  05:37 PM            12,288 XSockets.WebRTC.Prototype.Shared.Handlers.dll

Any thoughts?

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • Almost all cases of NullReferenceException are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Nov 06 '12 at 02:28

2 Answers2

1

Ken,

When the plugin framework of XSockets.NET dont find any "plugins" there is nothing to Compose. I think the reason of this is that you don't have the "plugins" deployed in the IIS Production instance of yours?

You will need to add the following elements to your appSettings section of the config file(web.config)

<add key="XSockets.PluginCatalog" value="XSockets\XSocketServerPlugns\" />
<add key="XSockets.PluginFilter" value="*.dll" />

In "my case" i have the XSockets.NET plugins (protocols, handlers/controllers) inside the

/XSockets/XSocketServerPlugns folder in my Website.

you should have the following plugins ( .dll's) in that folder

  1. XSockets.Core.Communication
  2. XSockets.Core
  3. XSockets.Extensibility.Handlers
  4. XSockets.Extensibility.Interceptors
  5. Xsockets.External
  6. XSockets.Protocol
  7. XSockets.Server
  8. XSockets.DevelopmentServer **

** This is the project/class library that contains the server of yours. ( i.e the DebugInstance)

If you want to configure the server , you will need to create a configuration loader class see this url for info http://xsockets.net/api/net-c/creating-custom-configuration-plugin , or just shoot an email to contact@xsockets.net and we will help you out.

If you need further assistance, just let me know.

Kind regards

dathor
  • 36
  • 1
  • Thanks for your suggestions. See my 2012-11-06 edit above for more details. – Ken Smith Nov 06 '12 at 16:55
  • Ken, Shoot me an email magnus[at]xsockets.net, and we can Skype or run or WebRTC conf? is that okej, i think will sort this out faster then! – dathor Nov 06 '12 at 17:52
  • Ken, i can see that you are running the old XSockets.Debug.Console that is a part of the old WebRTC demo found on CodePlex, i recommend you to get the latest package, and add the code from "SignalingHandler.cs" , to that "new" project, i think that it will work... You may also have a look at http://live.xsockets.net/examples/webrtc :-) – dathor Nov 06 '12 at 18:13
  • OK, I think I got it figured out. I think I was having two problems: I still had an old XSockets.DevelopmentServer.dll floating around from an aborted install of https://www.nuget.org/packages/XSockets.DevelopmentServer (and which is different from the generated XSockets.DevServer project); and for whatever reason, XSockets.DevServer.dll wasn't getting copied to all the right places by the build process. I added in the right copy build events, and it looks like things are working. – Ken Smith Nov 06 '12 at 20:16
0

First of all, if you are running a Console Application switch to .NET 4 instead of the default .NET 4 client profile (if not done already).

Second. We will provide a better way of knowing which references to add to the project starting the server. Meanwhile you should be able to run this in the Package Manager Console to see what refs are needed

(Get-Project XSocketHandler).Object.References | Where-Object {$_.CopyLocal -eq $true}

You have my email, so please contact me and we can have a skype meeting or something to talk more about it.

Regards Uffe, Team XSockets

Uffe
  • 2,275
  • 1
  • 13
  • 9