自定义设置提供商打破设计器

时间:2012-09-05 11:36:02

标签: c# winforms visual-studio-2012 windows-forms-designer

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

问题很奇怪。当我进行更改时它没有发生,但是当我重新启动Visual Studio 2012时它开始出现。

找到类似的帖子http://social.msdn.microsoft.com/Forums/en-US/vbide/thread/f72f7629-19e3-4ce8-bff7-64a08b114b26/ 但没有解决方案。

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) 

1 个答案:

答案 0 :(得分:2)

通过在主窗体中的IntializeComponent方法之后的运行时设置提供程序来解决我的问题。

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"; }
} 
相关问题