2010-11-11 73 views
0

在visual studio中,我創建了對Aspose程序集的引用,並在我的代碼中使用了Document類。它在設計時看起來很好,但是當我去編譯時,我得到的錯誤'Type Aspose.Words.Document'沒有定義。'如果我做了任何改變項目文件的事情,比如添加或刪除一個引用或添加一個新文件,這些錯誤就會消失......直到我再次嘗試編譯爲止。錯誤'類型Aspose.Words.Document'未定義。'當試圖編譯

有沒有其他人看到這種奇怪的行爲,並知道如何解決它?這是我的代碼,如果它很重要,但它並沒有變得更簡單:

Module Module1 

    Sub Main() 

     Dim license As New Aspose.Words.License() 
     license.SetLicense("Aspose.Words.lic") 

     Dim files = My.Resources.files.Split() 

     For Each file In files 
      If file <> "" Then 
       Dim changed As Boolean = False 
       Console.Write("Processing " & file & "...") 

       Dim doc = New Aspose.Words.Document(file) 

       If doc.Range.FormFields("CurrDate") IsNot Nothing Then 
        doc.Range.FormFields("CurrDate").TextInputType = Aspose.Words.Fields.TextFormFieldType.RegularText 
        doc.Range.FormFields("CurrDate").TextInputFormat = "" 
        doc.Save(file) 
        Console.WriteLine("done.") 
       Else 
        Console.WriteLine("not applicable.") 
       End If 

      End If 

     Next 
     Console.Read() 
    End Sub 

End Module 

回答

1

我發現它必須是因爲dll的目標是不同於項目中指定的框架。我創建了一個新的控制檯應用程序,目標是3.5而不是4.0,並開始工作。

0

是否有多個庫可供參考?另外,您的進口聲明在哪裏?

+0

只有一個庫,我不需要導入語句,因爲它們是完全限定的,對嗎? – adam0101 2010-11-11 21:56:32

0

檢查您是否引用了正確的Aspose dll(包含Document類的文件)。驗證Document類是否在Aspose.Words名稱空間下。

破解打開dll裏面的Reflector來驗證這個東西。

+0

我使用的是正確的dll。當我第一次添加dll時,文檔類在intellisense中顯示。在我嘗試編譯之後,就像刪除了引用。甚至連「Aspose」命名空間都不再出現在intellisense中。如果我放棄參考並將其添加回來,那麼錯誤消失,智能感知再次看到 - 直到我再次嘗試編譯。 – adam0101 2010-11-11 22:04:37

+0

聽起來像是你的環境問題。這是否與其他dll一起發生? – 2010-11-11 22:53:12

0

確保將組件上的Copy Local設置爲true,並將Embed Intrerop設置爲false。

+0

這些設置在哪裏? – adam0101 2010-11-12 14:12:50

+0

@ adam0101在解決方案資源管理器中,右鍵單擊引用下的程序集,轉至屬性,然後您應該看到那些列表。 – 2010-11-15 07:08:07

相關問題