Service Stack Hello World教程:exception EndpointHost.Config为空

本文关键字:exception EndpointHost Config 为空 教程 Stack Hello World Service | 更新日期: 2023-09-27 18:09:26

我正在遵循http://www.servicestack.net/ServiceStack.Hello/的服务堆栈"Hello World"教程。但是当我试图启动asp.net应用程序时,它说"值不能为空。参数名称:EndpointHost.Config"。

完整的异常文本是:

[ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: EndpointHost.Config]
[ConfigurationErrorsException: ServiceStack: AppHost does not exist or has not been initialized. Make sure you have created an AppHost and started it with 'new AppHost().Init();' in your Global.asax Application_Start()]
   ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory..cctor() in C:'src'ServiceStack'src'ServiceStack'WebHost.EndPoints'ServiceStackHttpHandlerFactory.cs:45
[TypeInitializationException: Der Typeninitialisierer für "ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory" hat eine Ausnahme verursacht.]
[TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Web.Configuration.HttpHandlerAction.Create() +57
   System.Web.Configuration.HandlerFactoryCache..ctor(HttpHandlerAction mapping) +19
   System.Web.HttpApplication.GetFactory(HttpHandlerAction mapping) +96
   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +125
   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

全局类是:

public class Global : System.Web.HttpApplication
    {
        /// Web Service Singleton AppHost
        public class InfoAppHost : AppHostBase
        {
            //Tell Service Stack the name of your application and where to find your web services
            public InfoAppHost()
                : base("Services", typeof(InfoService).Assembly) { }
            public override void Configure(Funq.Container container) { }
        }
        protected void Application_Start(object sender, EventArgs e)
        {
            //Initialize your application
            var appHost = new InfoAppHost();
            appHost.Init();
        }
    }

但是它似乎从来没有被调用过。从主页编译的例子项目工作得很好-但我想从主页的例子。有什么好办法吗?

Service Stack Hello World教程:exception EndpointHost.Config为空

我已经删除了我的测试项目,并再次尝试教程。

创建Global。我已经删除了整个类,并在这个文件中创建了另一个类Global。似乎Application_Start在这个类中从未被调用过。

您可能已经猜到了问题是appHost.Init()没有运行。尝试将其包装在Try/catch中,并记录可能抛出的任何错误。

我们遇到了同样的问题,并通过在扩展的ApplicationPool设置中将"Activate 32-bit-applications"设置为true来解决它。(对不起,只有德语窗口,所以设置名称是粗略的猜测)

我花了一段时间才弄清楚我做错了什么导致这个问题…

发生在我身上是因为我不小心拖拽了全局。

我发现这个错误是由WebApiConfig。这个例子使用的是ServiceStack,不需要ASP。. NET Web API。这一行需要在global .asax.cs文件中被注释掉。

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        // ** comment out ** WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        new ProteinTrackerAppHost().Init();
    }