【发布时间】:2022-08-08 02:58:13
【问题描述】:
Microsoft Visual Studio Community 2019 版本 16.11.8(在本文发布时是最新的)
它是最初使用 .NET 4.5 Framework 创建的 CLR 项目。我不得不将它升级到 4.6.2 但是我发现了一个可能的错误。如果您在System::Windows::Forms::Form 中添加了System::Windows::Forms::Timer 或System::ComponentModel::IContainer,那么升级后Designer 将停止工作。
这是由Visual Studio 生成的虚拟项目,它显示了重现错误所需的内容。
#pragma once
namespace Net45Test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Timer^ timer1;
protected:
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->SuspendLayout();
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Name = L\"MyForm\";
this->Text = L\"MyForm\";
this->ResumeLayout(false);
}
#pragma endregion
};
}
Designer 错误:
C++ CodeDOM parser error: Line: 54, Column: 21 --- Unknown type \'\'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
at Microsoft.VisualC.CppCodeParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
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)
--- End of stack trace from previous location where exception was thrown ---
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)
我是否正确更改了目标框架版本,如下图所示,我应该做其他事情吗?
所以假设我做对了,这里发生了什么? Visual Studio 错误还是别的什么?
标签: .net visual-studio c++-cli clr