Can’t find provider capability information for provider [XYZ]

I noticed that there is a problem with using ASP.NET membership providers in EPiServer CMS (5.1.422). When going to edit mode you get the following exception:

[EPiServerException: Can't find provider capability information for provider [XYZ].]
EPiServer.Security.ProviderCapabilities.IsSupported(String providerName, Action action) +117
EPiServer.UI.Edit.UserMembership.EnableFields() +418
EPiServer.UI.Edit.UserMembership.OnLoad(EventArgs e) +1201

The reason is because EPiServer only has hardcoded the capabilites for some of the default providers name like this:

static ProviderCapabilities()
_providerDictionary = new Dictionary();
_providerDictionary.Add("SqlServerMembershipProvider", new ProviderCapabilitySettings(true, true, true, new object[] { "email", true, "comment", true }));
_providerDictionary.Add("WindowsMembershipProvider", new ProviderCapabilitySettings(false, false, false, new object[] { "email", true, "comment", false }));
_providerDictionary.Add("SqlServerRoleProvider", new ProviderCapabilitySettings(true, true, true));
_providerDictionary.Add("WindowsRoleProvider", new ProviderCapabilitySettings(false, false, false));

To get it to work if you have providers with other names you must obviously register them manually (at least until EPiServer provides a better sollution) in Global.asax.cs. This is how I did it:

private void RegisterCapabilitiesOnMembershipProviders()
string defaultMembershipProviderName = ProviderFacade.GetDefaultMembershipProviderName();
string defaultRoleProviderName = ProviderFacade.GetDefaultRoleProviderName();
ProviderCapabilities.AddProvider(defaultMembershipProviderName, new ProviderCapabilitySettings(false, false, false, new object[] { "email", true, "comment", false }));
ProviderCapabilities.AddProvider(defaultRoleProviderName, new ProviderCapabilitySettings(false, false, false));
protected void Application_Start(Object sender, EventArgs e)

Update: This has changed in SP1 so it uses the class type and not the name. So a rename of a provider does not require registration but you must register capabilities if you write your own.