首页 > 解决方案 > 安装在 Windows Server 中时,OWIN SelfHosted 在 Windows 服务项目中出现异常

问题描述

我有一个在 Windows 10 中运行良好的 Winodws 服务解决方案,但它不能在 Windows Server 2012R2 或 Windows Server 2018 中启动

如果我在 Windows 事件中寻找,我会得到这个 FileNotFoundExceptionError:

应用程序:ServicioWindowsPrueba.exe 框架版本:v4.0.30319 描述:el proceso terminó debido a una excepción no controlada。异常信息:System.IO.FileNotFoundException en Microsoft.Owin.Hosting.Services.ServicesFactory.DoCallback(System.Action 2<System.Type,System.Type>) en Microsoft.Owin.Hosting.Services.ServicesFactory.DoCallback(System.Collections.Generic.IDictionary2<System.String,System.String>, System.Action2<System.Type,System.Type>) en Microsoft.Owin.Hosting.Services.ServicesFactory.Create(System.Collections.Generic.IDictionary2<System.String,System.String>, System.Action`1<Microsoft.Owin.Hosting.Services.ServiceProvider>) zh Microsoft.Owin.Hosting.WebApp.BuildServices(Microsoft.Owin.Hosting.StartOptions) zh Microsoft。 Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions) en Microsoft.Owin.Hosting.WebApp.Start[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089] en RestOwin。 RestOwinServidor.Start() zh System.Threading.ThreadHelper.ThreadStart_Context(System.Object) zh System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) zh System.Threading。 ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) en System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback, System.Object) 和 System.Threading.ThreadHelper.ThreadStart()

这是我的启动课:

using Owin;
using System.Web.Http;

namespace RestOwin
{
    public class Startup
    {
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host. 
            HttpConfiguration config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}"
            //routeTemplate: "{controller}/{id}",
            //defaults: new { id = RouteParameter.Optional }
            );

            appBuilder.UseWebApi(config);
        }
    }
}

这是我的服务器类:

using System;
using Microsoft.Owin.Hosting;
using System.Net.Http;

namespace RestOwin
{
    public class RestOwinServidor
    {
        //Puerto de escucha
        public int port { get; set; }

        public void Start()
        {

            //try
            //{

            string baseAddress = "http://127.0.0.1:" + port + "/";

            // Start OWIN host 
            WebApp.Start<Startup>(url: baseAddress);

        }
    }
}

标签: c#.netowin

解决方案


解决了。这是我的错,我只是将 .dll 和 .exe 文件复制到 Windows Server,剩下的文件也很重要


推荐阅读