开发者

Error 'Type Aspose.Words.Document' is not defined.' when trying to compile

In visual studio, I create a reference to the Aspose assembly and use the Document class in my code. It looks fine at design-time, but when I go to compile I get the error 'Type Aspose.Words.Document' is not d开发者_开发知识库efined.' If I do anything that changes the project file, like add or drop a reference or add a new file, the errors go away... until I try to compile again.

Has anyone else seen this weird behavior and know how to fix it? Here's my code if it matters, but it doesn't get much simpler:

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


I found that it must be because the dll is targeting a different framework than what was specified in the project. I created a new console app that targeted 3.5 instead of 4.0 and it started working.


Are there multiple libraries to reference? Also, where is your imports statement?


Check that you're referencing the correct Aspose dll (the one containing the Document class). Verify the Document class is under the Aspose.Words namespace.

Crack open the dll inside Reflector to verify this stuff.


Make sure you have the Copy Local on the assembly set to true and Embed Intrerop is set to false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜