問題是:當我刪除第一個消息框行時,我的程序不運行並在if語句行中拋出「異常已被調用的目標拋出」。但是,當我離開郵箱時,它運行良好。有人可以向我解釋爲什麼會發生這種情況,我能做些什麼來解決它?順便說一句,我對WPF相當陌生,任何幫助將不勝感激。WPF程序拋出無法解釋的調用異常
public BrowserMode() {
InitializeComponent();
MessageBox.Show("Entering Browser Mode");
if (webBrowser1.Source.Scheme == "http")
{
//cancel navigation
//this.NavigationService.Navigating += new NavigatingCancelEventHandler(Cancel_Navigation);
qd = new QuestionData();
// code where stuff happens
var url = webBrowser1.Source;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
// from h.RequestUri = "webcam://submit?question_id=45"
var parseUrl = request.RequestUri; //the uri that responded to the request.
MessageBox.Show("The requested URI is: " + parseUrl);
你有沒有抓到TargetInvocationException,看着的InnerException?看看http://stackoverflow.com/questions/2658908/why-is-targetinvocationexception-treated-as-uncaught-by-the-ide尋求幫助。 – user7116
好吧,我註釋了MessageBox.show(「輸入瀏覽器模式)代碼,並通過try/catch塊包圍了代碼塊。消息說:」對象引用未設置爲對象的實例「爲什麼? – Sixers17
'webBrowser1.Source'可能是'null'。無論如何,你應該把它移到'Loading',我會給出一個答案建議。 – user7116