我正在尝试编写一些使用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>它看起来不错,但显然有些东西是关闭的:)。 有人能指出我的方向吗? 这里有点无知。
非常感谢。
Am trying to write some tests that create/remove/change users using a CustomMembershipProvider. The CustomMembershipProvider is part of the WebApp assembly.
When I run my test I get the following exception:
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 22The exception is thrown when I execute this line of code:
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);In my test project the following lines are added to my app.conf:
the membership definition:
<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>the database connection:
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=WS050129\SQLEXPRESS;Initial Catalog=Users;Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings>It looks good to me, but apparently something is off :). Could anybody point me in the right direction? Kinda clueless here.
Many thanks.
最满意答案
尝试改变这一点:
<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 。 充实该标签上的类型定义属性。
Try changing this:
<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="/" />... to this:
<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="/" />You may need to tweak that a little. But it looks like the problem is that, lacking information about what assembly the type is in, the framework is looking in System.Web. Flesh out the type definition attribute on that tag.
更多推荐
发布评论