1

我很难解决这个问题。我仍在向 ServiceStack 介绍自己,并且在尝试将 MySql 数据库添加到我的 Web 应用程序时(这可能与错误完全无关),我遇到了一个错误,使我的应用程序无法运行。我已经撤消了很多步骤,但无法恢复到正常工作的状态。任何帮助将不胜感激。

错误:

Method 'get_IsLocal' in type 
ServiceStack.WebHost.Endpoints.Extensions.HttpRequestWrapper' from assembly 
'ServiceStack, Version=3.9.37.0, Culture=neutral, 
PublicKeyToken=null' does not have an implementation.

源错误:

An unhandled exception was generated during the execution of the current 
web request. Information regarding the origin and location of the exception 
can be identified using the exception stack trace below.

堆栈跟踪:

[TypeLoadException: Method 'get_IsLocal' in type
 'ServiceStack.WebHost.Endpoints.Extensions.HttpRequestWrapper' from assembly
 'ServiceStack, Version=3.9.37.0, Culture=neutral, PublicKeyToken=null' does 
not have an implementation.]
ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory.GetHandler
(HttpContext context, String requestType, String url, String pathTranslated) +0
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.
IExecutionStep.Execute() +346
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +155

我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using ServiceStack.Configuration;
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.MySql;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.Auth;
using ServiceStack.ServiceInterface.Validation;
using ServiceStack.FluentValidation;
using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.ServiceHost;
using ServiceStack.Common.Utils;
using ServiceStack.DataAnnotations;
using ServiceStack.Common;

namespace SampleHello2
{
    public class CustomCredentialsAuthProvider : CredentialsAuthProvider
    {
        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            //Add here your custom auth logic (database calls etc)
            return (userName == "Ian" && password == "pass");
        }

        public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            //Fill the IAuthSession with data which you want to retrieve in the app eg:
            session.FirstName = "Ian Mc Garry";
            //...

            //Important: You need to save the session!
            authService.SaveSession(session, SessionExpiry);
        }
    }


    public class Global : System.Web.HttpApplication
    {
        public class HelloAppHost : AppHostBase
        {
            //Tell Service Stack the name of your application and where to find your web services
            public HelloAppHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }

            public override void Configure(Funq.Container container)
            {
                //Enable Features
                Plugins.Add(new ValidationFeature());
                Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                    new IAuthProvider[] {
                        new CustomCredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
                    }
                ));

                //register any dependencies your services use, e.g:
                container.RegisterValidators(typeof(HelloValidator).Assembly);

                //Database
                //string conn = "Server=host;Port=3306;Database=db;UserId=user;Password=pass;";
                //container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(conn, MySqlDialectProvider.Instance));
            }
        }

        //Initialize your application singleton
        protected void Application_Start(object sender, EventArgs e)
        {
            new HelloAppHost().Init();
        }
    }

}

再次任何帮助将不胜感激。问题可能很清楚,但我无法解决。我自己也没有足够的经验来理解这个问题(错误/堆栈跟踪)。我看到它指的是ServiceStack.WebHost.Endpoints;我正在使用的包,但这是我所能得到的。

非常感谢。

4

1 回答 1

4

听起来您的 .dll 很脏。确保更新所有 NuGet 包,如果问题仍然存在,请清理 NuGet/packages文件夹并重试。

注意MySql OrmLite包的最新版本(截至 2013 年 3 月 6 日)是 v3.9.39。

于 2013-03-06T19:38:38.573 回答