更改任何表单区域/功能区属性都会破坏 Visual Studio 编辑器

发布于 2024-09-05 09:43:40 字数 1744 浏览 8 评论 0原文

我的 Visual Studio 2010 和 Outlook Addin 2010 项目(.NET 4 目标)出现问题。我已将表单区域添加到我的项目中,然后将 Localizes 属性更改为 true。现在,如果我关闭表单区域并重新打开它,我会收到此 VS 错误页面:

To prevent possible data loss before loading the designer, the following errors 
must be resolved: 
The variable 'resources' is either undeclared or was never assigned.

如果代码针对 .NET 4,则当我更改表单区域或功能区中的任何属性时,实际上会发生这种情况。在针对 .NET 3.5 的项目中一切都井井有条。 以下是此错误引用的示例代码,由 VS 创建,它是 FormRegion.Designer.cs 的一部分。它在 ApplyResources 行中断(如果我将其注释掉,则一切正常)。

private void InitializeComponent()
{
    System.ComponentModel.ComponentResourceManager resources = 
        new System.ComponentModel.ComponentResourceManager(typeof(FormRegion1));
    this.SuspendLayout();
    // 
    // FormRegion1
    // 
    resources.ApplyResources(this, "$this");
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.Name = "FormRegion1";
    this.FormRegionShowing += 
        new System.EventHandler(this.FormRegion1_FormRegionShowing);
    this.FormRegionClosed += 
        new System.EventHandler(this.FormRegion1_FormRegionClosed);
    this.ResumeLayout(false);
}

如果我选择忽略该错误并强制 VS 加载可视化编辑器,那么我会收到另一个错误:

Cannot open a designer for the file because the class within it does not inherit 
from a class that can be visually designed. 

起初我认为这是我的代码的问题(我的项目是从 VS2008 和 Outlook 2007 迁移的)。但后来我为 VS2010 和 Outlook 2010 创建了一个新项目,我也遇到了同样的问题。

重现它的步骤:

  1. 在 Visual Studio 2010 (.NET 4) 中创建一个新的 Outlook 2010 Addin 项目
  2. 将一个新的 FormRegion 项目添加到项目中(无论您启用哪个项目,也无论它是否启用)相邻或单独的表单区域)
  3. 打开新项目属性并将 Localized 属性更改为 true
  4. 关闭项目并重新打开它

I have a problem with Visual Studio 2010 and Outlook Addin 2010 project (.NET 4 target). I've added a form region to my project and then I've changed Localizable property to true. Now if I close my form region and reopen it, I'm getting this VS error page:

To prevent possible data loss before loading the designer, the following errors 
must be resolved: 
The variable 'resources' is either undeclared or was never assigned.

This actually happens when I change any property in Form Region or Ribbon if the code is targeted for .NET 4. In projects targeted for .NET 3.5 everything is in order.
Here's the example code that this error refers to was created by VS and it's a part of FormRegion.Designer.cs. It breaks on ApplyResources line (if I comment it out then everything is ok).

private void InitializeComponent()
{
    System.ComponentModel.ComponentResourceManager resources = 
        new System.ComponentModel.ComponentResourceManager(typeof(FormRegion1));
    this.SuspendLayout();
    // 
    // FormRegion1
    // 
    resources.ApplyResources(this, "$this");
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.Name = "FormRegion1";
    this.FormRegionShowing += 
        new System.EventHandler(this.FormRegion1_FormRegionShowing);
    this.FormRegionClosed += 
        new System.EventHandler(this.FormRegion1_FormRegionClosed);
    this.ResumeLayout(false);
}

If I choose to ignore the error and force VS to load visual editor then I'm getting another error:

Cannot open a designer for the file because the class within it does not inherit 
from a class that can be visually designed. 

At first I though it's a problem with my code (I have my project migrated from VS2008 and Outlook 2007). But then I created a new project for VS2010 and Outlook 2010 and I have the same problem there.

Steps to reproduce it:

  1. Create a new Outlook 2010 Addin project in Visual Studio 2010 (.NET 4)
  2. Add a new FormRegion item to a project (it doesn't matter for which item you enables it, it also doesn't matter if it's adjoined or separate form region)
  3. Open new item properties and change Localizable property to true
  4. Close item and reopen it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文