ZainAlabdin Tawfiq ZainAlabdin Tawfiq - 1 year ago 270
ASP.NET (C#) Question

InvalidOperationException: Could not find 'UserSecretsIdAttribute' on assembly

After deploying ASP.NET Core app to azure and opening the site, I get the following error:

InvalidOperationException: Could not find 'UserSecretsIdAttribute' on
assembly '******, Version=, Culture=neutral,

The exception details also include that the error happens at Startup.cs on this line of code:


Thank you

Answer Source

There was an update to the user secrets module just recently. It now requires you specify an assembly-level attribute for the id of the user secrets, or as a fallback, the way it was previously in project.json.

I can't find the article right now about it, but you can add something like this e.g. in Startup.cs:

[assembly: UserSecretsId("aspnet-TestApp-ce345b64-19cf-4972-b34f-d16f2e7976ed")]

Also, you should use:


It will search for that attribute in the assembly of the given type, in this case I used the Startup class.

I checked the source code for the user secrets configuration, and calling AddUserSecrets() without the type does this:

var attribute = entryAssembly.GetCustomAttribute<UserSecretsIdAttribute>();
if (attribute != null)
     return AddUserSecrets(configuration, attribute.UserSecretsId);

// try fallback to project.json for legacy support
     var fileProvider = configuration.GetFileProvider();
     return AddSecretsFile(configuration, PathHelper.GetSecretsPath(fileProvider));
{ }

// Show the error about missing UserSecretIdAttribute instead an error about missing
// project.json as PJ is going away.
throw MissingAttributeException(entryAssembly);

It's trying to find the UserSecretsId attribute on your assembly, and failing that, checking if it could find it in project.json. Then (as commented) returns an error about the missing attribute as they wouldn't want to complain about project.json anymore as it is being deprecated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download