Search code examples
asp.net-mvcasp.net-mvc-4membership-provider

In C# Code first membership provider package, MembershipProvider could not be found error. Reference missing?


I created project with name Sorama.CustomAuthentication in that project I installed a package called c# CodeFirst Membership Provider via nuGet package manager. You can see the reference that has been added to this project here enter image description here

but it is not letting the CodeFirstMembershipProvider class inherit from MembershipProvider. Error says MembershipProvider could not be found. What am I missing?


Solution

  • It looks like you added this to a new Class Library project (i.e. not to the MVC project itself)? If so then most of the references they assume exist for the package (that would be in a template MVC project) are missing from your Class Library references.

    That particular NuGet (currently at v1.0.0) frankly isn't a great package. It seems to be missing dependencies like EntityFramework and some .NET framework references, so once you get past this one you may have others to add as well, which will probably be:

    • From Nuget:
      • EntityFramework.dll, v5.0.0.0 (Install-Package EntityFramework -Version 5.0.0)
    • From the GAC (i.e. use the Add Reference context menu for the project, and in the dialog search in the Assemblies\Framework list for these names)
      • System.Web.dll, v4.0.0.0
      • System.Web.ApplicationServices.dll, v4.0.0.0
      • System.Configuration.dll, v4.0.0.0

    In future you can work this out by asking Visual Studio to build the project, and looking at the build error messages, which will look like:

    The type name 'MembershipProvider' could not be found. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.

    The bit I have highlighted in bold tells you that it thinks the best match for your reference that you need is to System.Web.ApplicationServices, particularly v 4.0.0.0, and gives you the public key token as well.