2012-09-20 48 views
1

当创建新的类实例时,我得到“在System.Deployment.dll中发生类型'System.Deployment.Application.InvalidDeploymentException'的第一次机会异常”。无效的部署异常

它发生在:

PrinterSettings^ MyPS = gcnew PrinterSettings(); 

一切正常,我也得到一个值,我想要的。

Form1.cpp:

#include "stdafx.h" 
#include "Form1.h" 
#include "Print.h" 
#include <iostream> 

System::Void DPrint::Form1::Form1_Load(System::Object^ sender, System::EventArgs^ e) 
{ 
    PrinterSettings^ MyPS = gcnew PrinterSettings(); 
    System::Windows::Forms::MessageBox::Show("From Class PrinterSettings: " + MyPS->IniFilePath()); 
} 

Print.h:

#ifndef PRINT_H 
#define PRINT_H 

public ref class PrinterSettings 
{ 
private: 
    System::String^ m_strPath; 


public: 
    PrinterSettings() 
    { 
     m_strPath = System::Windows::Forms::Application::UserAppDataPath; 
    } 

    System::String^ IniFilePath() { return m_strPath; }; 

}; 
#endif 

任何想法是怎么回事?谢谢。

回答

0

这是“第一次机会”异常,意味着调试器会观察可能会被处理的异常。在这种情况下,应用程序很可能试图确定应用程序的安装方式,例如通过ClickOnce来确定您的用户应用程序路径是什么。

请参阅What causes an InvalidDeploymentException in a WPF application?一个很好的解释。

+0

因此,我试图获得一个将在未来(部署后)才知道的值?这是否意味着我与它无关?谢谢。 编辑:我知道这只是一个调试问题。 – Nikonation

+0

@Nikonation如果只是第一次机会例外,用户将永远不会看到它。假设没有其他问题,你应该没问题。 – akton

+0

非常感谢! – Nikonation