gpt4 book ai didi

asp.net - 集成测试 : MembershipProvider - TypeLoadException

转载 作者:行者123 更新时间:2023-12-04 02:28:05 24 4
gpt4 key购买 nike

我正在尝试使用 CustomMembershipProvider 编写一些创建/删除/更改用户的测试。 CustomMembershipProvider 是 WebApp 程序集的一部分。

当我运行测试时,出现以下异常:

System.TypeLoadException : Could not load type 'WebApp.Framework.CustomMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, ref StackCrawlMark stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at System.Web.Security.Membership.InitializeSettings(Boolean initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings)
at System.Web.Security.Membership.Initialize()
at System.Web.Security.Membership.get_Providers()
at System.Web.Security.MembershipUser..ctor(String providerName, String name, Object providerUserKey, String email, String passwordQuestion, String comment, Boolean isApproved, Boolean isLockedOut, DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate, DateTime lastPasswordChangedDate, DateTime lastLockoutDate)
at BusinessLayer.Users.UserRepository.Add(User user, ref MembershipCreateStatus status) in UserRepository.cs: line 43
at WebApp.Framework.CustomMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, ref MembershipCreateStatus status) in CustomMembershipProvider.cs: line 86
at Tests.Framework.CustomMembershipProviderTests.CreateUser() in CustomMembershipProviderTests.cs: line 22

当我执行这行代码时抛出异常:

        return new MembershipUser(
"MyMembershipProvider",
user.Name,
null,
user.EmailAddress,
string.Empty,
string.Empty,
true,
false,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue);

在我的测试项目中,以下几行被添加到我的 app.conf 中:

成员定义:

  <system.web>
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear/>
<add name="MyMembershipProvider" type="WebApp.Framework.CustomMembershipProvider" connectionStringName="DefaultConnection"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
</system.web>

数据库连接:

  <connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=WS050129\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

对我来说看起来不错,但显然有些不对劲 :)。有人能指出我正确的方向吗?这里有点无能为力。

非常感谢。

最佳答案

尝试改变这个:

<add name="MyMembershipProvider" type="WebApp.Framework.CustomMembershipProvider"       connectionStringName="DefaultConnection"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />

...为此:

<add name="MyMembershipProvider" type="WebApp.Framework.CustomMembershipProvider, WebApp" connectionStringName="DefaultConnection"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />

您可能需要稍微调整一下。但看起来问题在于,缺少有关类型所在程序集的信息,框架正在查找 System.Web。充实该标签上的类型定义属性。

关于asp.net - 集成测试 : MembershipProvider - TypeLoadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14324307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com