2016-12-13 2 views
1

내 program.cs 파일에서 Topshelf를 구성하려고하는데이를 실행할 수 없습니다. Topshelf가 dnxcore50에서 돌아갈 수 없다고 생각합니까? 어쩌면 내가 다른 것을 놓친 것일까?dotnet core에서 Topshelf에 문제가 있습니다. 구성 도와주세요

using System; 
using System.Web.Http; 
using CreateDictionary.Memory; 
using Microsoft.Owin; 
using Microsoft.Owin.Hosting; 
using Owin; 
using System.Threading.Tasks; 
using Topshelf; 

    namespace ConsoleApplication 
    { 
     public class Program 
     { 
      public static void Main(string[] args) 
      { 
      Console.WriteLine("Server starting...."); 
      ServerRun.Run(); 
      Console.ReadLine(); 
      } 
     } 
     public class Startup 
     { 
      public void Configuration(IAppBuilder appBuilder) 
      { 
       appBuilder.Use(typeof (ConfigApiMiddleware)); 
       appBuilder.UseWebApi(WebApiConfiguration()); 
      } 
      //Config to connect 
      private static HttpConfiguration WebApiConfiguration() 
      { 
       var config = new HttpConfiguration(); 
       config.Routes.MapHttpRoute(
        "CustomeApi", 
        "api/{controller}/{id}", 
        new { id = RouteParameter.Optional }); 
       return config; 
      } 
     } 
     public class ServerRun 
     { 

      public static void Run() 
      { 

       HostFactory.Run(x => 
       { 
        x.Service<OwinServer>(s => 
        { 
         s.ConstructUsing(name => new OwinServer()); 
         s.WhenStarted(tc => tc.Start()); 
         s.WhenStopped(tc => tc.Stop()); 
        }); 
        x.RunAsLocalSystem(); 
       }); 

       Console.WriteLine("Server running at {0} - press Enter to quit. ", "http://localhost:8383"); 
       Console.ReadLine(); 
      } 

     } 
     public class ConfigApiMiddleware : OwinMiddleware 
     { 
      public ConfigApiMiddleware(OwinMiddleware next):base(next) 
      {} 
      public async override Task Invoke(IOwinContext context) 
      { 
       //Config phần header request tại đây 

       var request = context.Request.Headers; 

       var origin = request["Origin"]; 
       var host = request["Host"]; 
    //   if (origin == null) 
    //   { 
    //    origin = "API version"; 
    //   } 
       Console.WriteLine("Origin:{0}--Host:{1}", origin,host); 

       //Config phần header respond tại đây 

       context.Response.Headers["MachineName"] = Environment.MachineName; 

       context.Response.Headers["Access-Control-Allow-Origin"] = "*"; 
       context.Response.Headers["Content-Type"] = "application/json; charset=utf-8"; 
       context.Response.Headers["Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE,OPTION"; 
       context.Response.Headers["Access-Control-Allow-Credentials"] = "true"; 
       context.Response.Headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept,Authorization"; 

       await Next.Invoke(context); 
      } 
     } 
     public class OwinServer 
     { 
      private IDisposable _webapp; 

      public void Start() 
      { 
       _webapp = WebApp.Start<Startup>("http://localhost:8383");//"http://localhost:8383" 
       MemoryInfor.InitMemory(); 
      } 

      public void Stop() 
      { 
       _webapp.Dispose(); 
      } 
     } 
    } 

project.json 파일 내 구성 :

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "debugType": "portable", 
    "emitEntryPoint": true 
    }, 
    "dependencies": { 
    "System.Data.Common": "4.3.0", 
    "System.Data.SqlClient": "4.3.0", 
    "Microsoft.NETCore.Portable.Compatibility": "1.0.2", 
    "Owin": "1.0.0", 
    "Microsoft.AspNet.WebApi.Owin": "5.2.3", 
    "Microsoft.AspNet.WebApi.OwinSelfHost": "5.2.3", 
    "Topshelf": "4.0.3", 
    "Topshelf.Owin": "1.3.29" 
    }, 
    "frameworks": { 
    "netcoreapp1.1": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.1.0" 
     } 
     }, 
     "imports": [ 
     "dnxcore50", 
     "net452", 
     "net461" 
     ] 
    } 
    } 
} 

내가 명령 dotnet run로를 빌드 할 때 나는이 결과를 받고 있어요 :

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Topshelf.Logging.TypeExtensions' t 
hrew an exception. ---> System.TypeLoadException: Could not load type 'System.Collections.Concurrent.ConcurrentDictio 
nary`2' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. 
    at Topshelf.Caching.ConcurrentCache`2..ctor() 
    at Topshelf.Logging.TypeNameFormatter..ctor(String genericArgumentSeparator, String genericOpen, String genericClo 
se, String namespaceSeparator, String nestedTypeSeparator) 
    at Topshelf.Logging.TypeNameFormatter..ctor() 
    at Topshelf.Logging.TypeExtensions..cctor() 
    --- End of inner exception stack trace --- 
    at Topshelf.Logging.HostLogger.Get(Type type) 
    at Topshelf.HostFactory.Run(Action`1 configureCallback) 
    at ConsoleApplication.ServerRun.Run() in C:\Users\0baut_000\Desktop\OwinServer\Program.cs:line 45 
    at ConsoleApplication.Program.Main(String[] args) in C:\Users\0baut_000\Desktop\OwinServer\Program.cs:line 17 
+0

https://github.com/Topshelf/Topshelf/issues/277 – stuartd

답변

1

하지만 회로 Topshelf이 없습니다 아직 dotnet 코어 지원; 이 계획은 NETStandard 2.0이 출시 될 때 가능할 계획입니다.

관련 문제