0

I'm trying to follow this tutorial to create an ASP.NET Identity system, I've gotten about halfway down the page, however when I get to writing the following code

        public async Task<string> AddUser()
        {
            ApplicationUser user;
            ApplicationUserStore Store = new ApplicationUserStore(new ApplicationDbContext());
            ApplicationUserManager userManager = new ApplicationUserManager(Store);
            user = new ApplicationUser
            {
                UserName = "bla",
                Email = "o@gmail.com",            
            };

            var result = await userManager.CreateAsync(user);

            if (!result.Succeeded)
            {
                return result.Errors.First();
            }
            return "User Added";
        }

I get the error System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.

I've looked online quite a bit for a solution however most of the posts involve .edmx files which neither this tutorial nor my solution contain. The connection string to my server is correct as I've used it on other projects in the past. Where am I going wrong?

My connection string is as follows:

<add name="PEARLEntities" connectionString="metadata=res://*/Models.UsersModel.csdl|res://*/Models.UsersModel.ssdl|res://*/Models.UsersModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=source;initial catalog=PEARL;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

The DbContext is based off the table in this connection string that was created using the following SQL

CREATE TABLE [dbo].[UsersTable](
    [UserID] [int] IDENTITY(1,1) NOT NULL,
    [UserName] [nchar](200) NOT NULL,
    [Email] [nchar](200) NOT NULL,
    [EmailConfirmed] [bit] NOT NULL,
    [Password] [nchar](200) NOT NULL,
    [Hospital] [nchar](200) NOT NULL,
    [Salt] [nvarchar](500) NOT NULL,
 CONSTRAINT [PK_UsersTable] PRIMARY KEY CLUSTERED 
(
    [UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Displaza
  • 75
  • 7
  • Have you looked at this? https://stackoverflow.com/questions/18351898/system-data-metadataexception-unable-to-load-the-specified-metadata-resource – DavidG Jan 27 '20 at 12:30
  • @DavidG I did look at that but it involves .edmx files for the metadata which my project doesn't contain – Displaza Jan 27 '20 at 12:53
  • Well since you haven't shown us anything relating to your context, we can only make guesses. There's not enough information here to answer the question. – DavidG Jan 27 '20 at 12:55
  • What else would you need for my question to have context? I am very new to ASP.NET Identity so I know very little. – Displaza Jan 27 '20 at 12:57
  • Well, how about `ApplicationDbContext` for a start? What config have you given it? What does your connection string look like? – DavidG Jan 27 '20 at 13:04
  • @DavidG I believe I've edited my original post enough so that you can now get a better idea as to what my DbContext is doing. – Displaza Jan 27 '20 at 13:18
  • I think your connection string is wrong, that is the format when you use an EDMX file or a model builder. – DavidG Jan 27 '20 at 13:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206719/discussion-between-displaza-and-davidg). – Displaza Jan 27 '20 at 13:28

0 Answers0