C# 自定义设置提供程序设计器

C# 自定义设置提供程序设计器,c#,winforms,visual-studio-2012,windows-forms-designer,C#,Winforms,Visual Studio 2012,Windows Forms Designer,在项目中的每个窗体设计器上获取此错误。我刚刚添加了RegistrySettingsProvider.cs,这就开始发生了。应用程序运行绝对正常,没有任何错误、警告 这个问题很奇怪。在我进行更改时没有发生这种情况,但在我重新启动Visual Studio 2012时它开始显示 发现了相似的线索 但没有解决办法 at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeReso

在项目中的每个窗体设计器上获取此错误。我刚刚添加了RegistrySettingsProvider.cs,这就开始发生了。应用程序运行绝对正常,没有任何错误、警告

这个问题很奇怪。在我进行更改时没有发生这种情况,但在我重新启动Visual Studio 2012时它开始显示

发现了相似的线索 但没有解决办法

at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetType(String name, Boolean throwOnError)
at Microsoft.VisualStudio.Shell.Design.VirtualTypeBuilder.ExecuteExpression(Resolver resolver, CodeExpression expression)
at Microsoft.VisualStudio.Shell.Design.VirtualTypeBuilder.FillAttributes(Resolver resolver, CodeTypeMember member, Attribute[]& customAttributes, MemberAttributes& memberAttributes)
at Microsoft.VisualStudio.Shell.Design.VirtualTypeBuilder.InitializeFromType(ITypeResolutionService typeResolutionService, CodeTypeDeclaration typeDecl, String namespaceName)
at Microsoft.VisualStudio.Shell.Design.VirtualTypeBuilder.InitializeFromType(ITypeResolutionService typeResolutionService, CodeNamespace ns)
at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.BuildType()
at Microsoft.VisualStudio.Editors.SettingsGlobalObjects.SettingsFileGlobalObject.GetObjectType()
at Microsoft.VisualStudio.Shell.Design.GlobalType.get_ObjectType()
at Microsoft.VisualStudio.Shell.Design.GlobalObject.GetHashCode()
at System.Collections.Generic.ObjectEqualityComparer`1.GetHashCode(T obj)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.TrackGlobal(GlobalObjectProvider p, GlobalType g)
at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects(Type baseType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetTypeFromGlobalObjects(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.GetType(String typeName)
at Microsoft.VisualStudio.Design.VSDesignSurface.EnsureExtensions(IComponent component)
at Microsoft.VisualStudio.Design.VSDesignSurface.CreateInstance(Type type)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) 

通过在主窗体中初始化组件方法之后在运行时设置提供程序,解决了我的问题

public FormMain()
{
    InitializeComponent();
    var registrySettingsProvider = new RegistrySettingsProvider();
    Settings.Default.Providers.Add(registrySettingsProvider);
    foreach (SettingsProperty property in Settings.Default.Properties)
    {
        property.Provider = registrySettingsProvider;
    }
}
并确保覆盖设置提供程序中的Name属性

public override string Name
{
    get { return "RegistrySettingsProvider"; }
} 

你提供的链接提供了一个适合我的解决方案。在设置设计器中,对于每个设置的“提供程序”属性,使用完整命名空间限定提供程序的类名。