title: ASP.NET MVC3 Custom Membership Provider - The membership provider name specified is invalid
body: <p>I'm implementing a custom membership provider, and everything seems to go swimmingly until I create a MembershipUser object. At that point, I receive the error:</p>
  
  <blockquote>
    <p>The membership provider name specified
    is invalid. Parameter name:
    providerName</p>
  </blockquote>
  
  <p>In <code>web.config</code> the membership key is</p>
  
  <pre><code>&lt;membership defaultProvider="MembersProvider"&gt;
    &lt;providers&gt;
      &lt;clear/&gt;
      &lt;add name="MembersProvider" type="Members.Providers.MembersProvider" connectionStringName="ApplicationServices"
           enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
           maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
           applicationName="DeviceDatabase" /&gt;
    &lt;/providers&gt;
  &lt;/membership&gt;
  </code></pre>
  
  <p>When creating the MembershipUser object from my custom User class:</p>
  
  <pre><code>    public static MembershipUser ToMembershipUser(User user)
      {
          MembershipUser member = new MembershipUser
              ("MembersProvider"
              , user.Name
              , user.Id
              , user.EmailAddress
              , user.PasswordQuestion
              , user.Comment
              , user.IsApproved
              , user.IsLockedOut
              , user.DateCreated
              , user.LastLoginDate ?? DateTime.MinValue
              , user.LastActivityDate ?? DateTime.MinValue
              , user.LastPasswordChangedDate ?? DateTime.MinValue
              , user.LastLockoutDate ?? DateTime.MinValue
              );
  
          return member;
      }
  </code></pre>
  
  <p><em>(I realize I could probably just inherit my User class from MembershipUser, but it's already part of an existing class hierarchy. I honestly think this is the first time I've encountered a legitimate need for for multiple inheritance!)</em></p>
  
  <p>My feeling is that the <code>new MembershipUser(...)</code> providerName parameter is supposed to match what's set in <code>web.config</code>, but, since they match already, I'm at a loss as to how to proceed.</p>
  
  <p>Is there a convenient way to get the name of the active membership provider in code?</p>
  
  <p>I'm starting to think that using the built-in membership system is overkill and more trouble than it's worth.</p>
  
  <p><strong>Edit</strong>
  Not sure if it's relevant, but the custom membership provider class is in a class library, not the main WAP project.</p>
  
  <p><strong>Update</strong>
  Here's the contents of the <code>System.Web.Security.Membership.Provider</code> object as show in the VS2010 command window:</p>
  
  <pre><code>&gt;eval System.Web.Security.Membership.Provider
  {Members.Providers.MembersProvider}
      [Members.Providers.MembersProvider]: {Members.Providers.MembersProvider}
      base {System.Configuration.Provider.ProviderBase}: {Members.Providers.MembersProvider}
      ApplicationName: null
      EnablePasswordReset: true
      EnablePasswordRetrieval: false
      MaxInvalidPasswordAttempts: 5
      MinRequiredNonAlphanumericCharacters: 0
      MinRequiredPasswordLength: 6
      PasswordAttemptWindow: 10
      PasswordFormat: Function evaluation was aborted.
      PasswordStrengthRegularExpression: Cannot evaluate expression because debugging information has been optimized away .
      RequiresQuestionAndAnswer: Cannot evaluate expression because debugging information has been optimized away .
      RequiresUniqueEmail: Cannot evaluate expression because debugging information has been optimized away .
  </code></pre>
  
  <p><strong>Update 2</strong></p>
  
  <p>This just randomly started working, which means I changed something but can't remember what it was. Stupid brain.  I'll accept the only answer that's been posted and update this if I figure out what the problem was.</p>