1

I have a solution that utilises Grapevine to start a server within the Program class. For some reason though, as soon as I start the program, it crashes when server.Start() is called. No other parts of the solution are running at this point, so I don't know how that could be happening?

Running in Visual Studio 15, as Administrator, on Windows 10.

Program.cs

using System;
using System.Threading;
using Grapevine.Server;
using QuantConnect.Logging;

namespace QuantConnect.Services
{
    class Program
    {
        /// <summary>
        /// QuantConnect C# Services Server:
        /// </summary>
        static void Main(string[] args)
        {
            var server = new RESTServer
            {
                //Host = Configuration.Config.Get("grapevine-host"),
                //Port = Configuration.Config.Get("grapevine-port")
                Host = Configuration.Config.Get("grapevine-host", "localhost"),
                Port = Configuration.Config.Get("grapevine-port", "80")
            };

            Log.Trace(string.Format("Starting Server On {0}:{1}", server.Host, server.Port));
            server.Start(); // Exception occurs here

            while (server.IsListening)
            {
                Thread.Sleep(300);
            }

            Log.Trace("Server stopped. Press key to continue...");
            Console.ReadLine();
        }
    }
}

Error and stacktrace:

An unhandled exception of type 'System.Net.HttpListenerException' occurred in Grapevine.dll

System.Net.HttpListenerException was unhandled
  ErrorCode=32
  HResult=-2147467259
  Message=The process cannot access the file because it is being used by another process
  NativeErrorCode=32
  Source=System
  StackTrace:
       at System.Net.HttpListener.AddAllPrefixes()
       at System.Net.HttpListener.Start()
       at Grapevine.Server.RESTServer.Start()
       at QuantConnect.Services.Program.Main(String[] args) in C:\Users\RichardsPC\Source\Repos\Lean\Services\Program.cs:line 29
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
3therk1ll
  • 2,056
  • 4
  • 35
  • 64
  • While this would not have resolved your issue at all, I would recommend updating to the latest version of Grapevine 4.x. Good stuff there! And thanks for using Grapevine. – Scott Offen Sep 17 '16 at 19:55
  • Hi Scott, issue was I had to use 3.1. Just the hand I was dealt in this scenario – 3therk1ll Sep 17 '16 at 20:08

1 Answers1

1

So I figured out what the issue was. I set Grapevine to use port 80.

Port = Configuration.Config.Get("grapevine-port", "80")

Issue was that there was another service on my machine using this port, I changed it to use 8080 and it works fine now.

Port = Configuration.Config.Get("grapevine-port", "8080")

3therk1ll
  • 2,056
  • 4
  • 35
  • 64