0

winform で図面を開くのに問題があります。私が得ているエラーは、NullReferenceException が未処理であり、経路を強調していることを示しています。どんな助けでも大歓迎です。ありがとう

private void button2_Click(object sender, EventArgs e)
    {
        //Open Solidworks Drawing
        ModelDoc2 swModel = default(ModelDoc2);
        DocumentSpecification swDocSpecification = default(DocumentSpecification);
        string sName = null;
        long longstatus = 0;
        long longwarnings = 0;
        // Drawing document path and name         
        swDocSpecification = (DocumentSpecification)swApp.GetOpenDocSpec("C:\\location\\????.slddrw");//File Location
        sName = swDocSpecification.FileName;
        // Sheet name         
        swDocSpecification.SheetName = "BOM"; //Open to the BOM sheet
        swDocSpecification.DocumentType = (int)swDocumentTypes_e.swDocDRAWING;
        swDocSpecification.ReadOnly = true;
        swDocSpecification.Silent = false;
        // Open the specified sheet in the specified drawing document         
        swModel = swApp.OpenDoc7(swDocSpecification);
        longstatus = swDocSpecification.Error;
        longwarnings = swDocSpecification.Warning;
    }
4

2 に答える 2

2
System.Diagnostics.Process.Start("explorer.exe c:\\");

これは助けることができます

于 2011-09-09T16:07:35.197 に答える
1

NullReferenceException が発生する理由については、2 つの可能性があります。

  1. swApp が null であり、呼び出しを含むものは機能しGetOpenDocSpecません
  2. GetOpenDocSpec 内の何かが想定どおりに記述されておらず、正しいチェックを行っていません。そのため、null 例外がスローされます

デバッガーを使用して swApp == null かどうかを確認するのは非常に簡単です。autos または watch ウィンドウを使用し、変数の上にカーソルを置き、コマンド ウィンドウから ?swApp == null などを使用します。

于 2011-09-09T16:08:14.167 に答える