错误“类型 Aspose.Words.Document”未定义。'当尝试编译时

发布于 2024-10-02 03:37:21 字数 1208 浏览 2 评论 0原文

在 Visual Studio 中,我创建对 Aspose 程序集的引用并在代码中使用 Document 类。它在设计时看起来很好,但是当我进行编译时,我收到错误“Type 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

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 defined.' 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请爱~陌生人 2024-10-09 03:37:21

我发现这一定是因为 dll 的目标框架与项目中指定的框架不同。我创建了一个新的控制台应用程序,目标是 3.5 而不是 4.0,它开始工作。

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.

似最初 2024-10-09 03:37:21

是否有多个库可供参考?另外,你的进口声明在哪里?

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

姐不稀罕 2024-10-09 03:37:21

检查您是否引用了正确的 Aspose dll(包含 Document 类的 dll)。验证 Document 类位于 Aspose.Words 命名空间下。

破解Reflector内的dll来验证这个东西。

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.

枯叶蝶 2024-10-09 03:37:21

确保将程序集上的Copy Local 设置为 true,并将 Embed Intrerop 设置为 false。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文