Monday, July 19, 2010

ASP.NET MVC Membership Provider Issues

July 19, 2010 Posted by Jason Irwin , 1 comment

This afternoon I struggled a little with an ASP.NET MVC 2.0 issue. I’m using NHibernate’s export schema capabilities to create my database schema. I have an NUnit project with a bunch of different tests with the sole purpose of re-creating the database and populating some dummy data so that I do not have to do so by hand. I wanted to take this a step further and create some users in my system using Microsoft’s in-built MembershipProvider. Having set up my tests, I received the following message:

'System.TypeLoadException : Could not load type 'OnlineAuctions.Core.Classes.BuyerMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Obviously in this case the system is looking for my provider in the System.Web assembly, not my OnlineAuctions.Core assembly. My config file entry was as follows:

 

<add name="BuyerMembershipProvider" applicationName="OnlineAuctions" connectionStringName="mydevpc" minRequiredNonAlphanumericCharacters="0" passwordFormat="Encrypted" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" encryptionKey="aaavvvvaaabbbb" type="OnlineAuctions.Core.Classes.BuyerMembershipProvider” />

In retrospect this was a simple issue, but it took a little bit of playing before I fixed the issue. Can you see the issue? Yes, I am specifying my type in the type field – but I am not specifying the assembly in which the type resides. Adding the assembly, as in the below example, fixed the issue. Huzzar!

 

<add name="BuyerMembershipProvider" applicationName="OnlineAuctions" connectionStringName="mydevpc" minRequiredNonAlphanumericCharacters="0" passwordFormat="Encrypted" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" encryptionKey="aaavvvvaaabbbb" type="OnlineAuctions.Core.Classes.BuyerMembershipProvider, OnlineAuctions.Core” />

1 comments: