【解決方法】デザイナー モードでウィンドウ フォームを開いているときに、System.Exception 型の例外がスローされました。

プログラミングQA


タイプ System.Exception の例外がスローされました 既に作成されているウィンドウ フォームをデザイナー モードで開こうとしているとき。 この問題は、既に作成したウィンドウ フォームをデザイナー モードで開こうとすると発生します。 このエラーが発生する理由がわかりません。 フォームを編集する必要がありますが、編集できません..助けてください……..

これは、デザイナー モードでのコール スタックの出力です…..

at VSLangProj.Reference.get_Path() at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_FileName() at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.GetMatchIndex(String typeName) at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchNormalEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, Boolean fastSearch) at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName, String typeName, Boolean ignoreCase, Assembly& assembly, ReferenceType refType) at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType) 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 System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager) 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)

以下は、フォームのヘッダー ファイルとその C++ ファイル コードの 1 つです…..

WelcomeWindow.h

C++
#ifndef WELCOMEWINDOW_H
#define WELCOMEWINDOW_H

#pragma once

#include "test_open.h"
namespace open_image {

	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 WelcomeWindow
	/// </summary>
	public ref class WelcomeWindow : public System::Windows::Forms::Form
	{
	public:
		WelcomeWindow(void);

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~WelcomeWindow();

	private: System::Windows::Forms::Label^  label1;
	protected: 
	private: System::Windows::Forms::Button^  continue_btn;
	private: System::Windows::Forms::Button^  exit_btn;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#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)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(WelcomeWindow::typeid));
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->continue_btn = (gcnew System::Windows::Forms::Button());
			this->exit_btn = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::SystemColors::GrayText;
			this->label1->Font = (gcnew System::Drawing::Font(L"Monotype Corsiva", 21.75F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)), 
				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
			this->label1->Location = System::Drawing::Point(0, 0);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(136, 36);
			this->label1->TabIndex = 0;
			this->label1->Text = L"Welcome...";
			// 
			// continue_btn
			// 
			this->continue_btn->BackColor = System::Drawing::SystemColors::GrayText;
			this->continue_btn->Font = (gcnew System::Drawing::Font(L"Bookman Old Style", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->continue_btn->Location = System::Drawing::Point(479, 402);
			this->continue_btn->Name = L"continue_btn";
			this->continue_btn->Size = System::Drawing::Size(81, 32);
			this->continue_btn->TabIndex = 1;
			this->continue_btn->Text = L"Continue";
			this->continue_btn->UseVisualStyleBackColor = false;
			this->continue_btn->Click += gcnew System::EventHandler(this, &WelcomeWindow::continue_btn_Click);
			// 
			// exit_btn
			// 
			this->exit_btn->BackColor = System::Drawing::SystemColors::GrayText;
			this->exit_btn->Font = (gcnew System::Drawing::Font(L"Bookman Old Style", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->exit_btn->Location = System::Drawing::Point(560, 402);
			this->exit_btn->Name = L"exit_btn";
			this->exit_btn->Size = System::Drawing::Size(65, 32);
			this->exit_btn->TabIndex = 2;
			this->exit_btn->Text = L"Exit";
			this->exit_btn->UseVisualStyleBackColor = false;
			this->exit_btn->Click += gcnew System::EventHandler(this, &WelcomeWindow::exit_btn_Click);
			// 
			// WelcomeWindow
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->ClientSize = System::Drawing::Size(630, 441);
			this->Controls->Add(this->exit_btn);
			this->Controls->Add(this->continue_btn);
			this->Controls->Add(this->label1);
			this->Name = L"WelcomeWindow";
			this->Text = L"WelcomeWindow";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void exit_btn_Click(System::Object^  sender, System::EventArgs^  e);
	private: System::Void continue_btn_Click(System::Object^  sender, System::EventArgs^  e);
	};
}
#endif

WelcomeWindow.cpp

C++
#include "stdafx.h"
#include "WelcomeWindow.h"
#include "test_open.h"
namespace open_image
{
	WelcomeWindow::WelcomeWindow(void)
	{
		InitializeComponent();
		//
		//TODO: Add the constructor code here
		//
	}
	WelcomeWindow::~WelcomeWindow()
	{
		if (components)
		{
			delete components;
		}
	}
	public ref class container
	{
		public:
			static test_open^ t = gcnew test_open();
	};
	System::Void WelcomeWindow::exit_btn_Click(System::Object^  sender, System::EventArgs^  e) {
		this->Close();
		exit(1);
	}
	System::Void WelcomeWindow::continue_btn_Click(System::Object^  sender, System::EventArgs^  e) {
		/*test_open^ t = gcnew test_open();*/
		this->Hide();
		container::t->Show();
	}
}

解決策 1

最も可能性の高い原因

Form.Load イベントの問題、Form.Load イベントから呼び出されたもの、または初期化中に呼び出された他のコード (コンストラクター?)

解決

Form.Load イベントは、デザイン モードとプログラム実行時の両方で実行されます。 Form.Load イベントでコードを実行することによって引き起こされるデザイン モードの問題を防ぐには、次の手順を実行します。

Form.Load イベント内のすべてのコードを If 次のようなステートメント:

if (!this->DesignMode) {
//
//
// All of the Form.Load event code goes here
//
//
}

見る DesignMode プロパティ[^] Visual Studio のヘルプで。
備考

DesignMode プロパティは true を返し、コントロールがデザイナーのコンテキストで使用されていることを示します。 カスタム コントロールは、デザイン時の動作が実行時の動作と異なる場合に、このプロパティを使用できます。

解決策 2

vsprojet でファイルを削除します。
後でファイルをリロードしてください。再試行してください。

解決策 3

@OuYangXuChuan: 解決策をありがとう。 本当に助かりました。

解決策 4

プロジェクトに移動します。 次に、プロパティを削除し、重複する参照またはエラーのある参照を削除します。通常は赤い I 表記でマークされています。それらを削除し、デザインをリロードします。問題が解決しない場合は、システムを再起動する必要がある場合があります。

コメント

タイトルとURLをコピーしました