【问题标题】:Error 'Type Aspose.Words.Document' is not defined.' when trying to compile错误“未定义类型 Aspose.Words.Document”。尝试编译时
【发布时间】:2010-11-11 19:30:01
【问题描述】:

在 Visual Studio 中,我创建了对 Aspose 程序集的引用,并在我的代码中使用了 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

【问题讨论】:

    标签: .net visual-studio assemblies reference aspose


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      是否有多个库可供参考?另外,您的导入声明在哪里?

      【讨论】:

      • 只有一个库,我不需要导入语句,因为它们是完全合格的,对吧?
      【解决方案3】:

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

      破解打开Reflector里面的dll来验证这个东西。

      【讨论】:

      • 我正在使用正确的 dll。当我第一次添加 dll 时,文档类以智能感知显示。在我尝试编译后,就像引用被删除了一样。甚至“Aspose”命名空间都不再出现在智能感知中。如果我删除引用并将其添加回来,错误就会消失并且智能感知会再次看到它 - 直到我再次尝试编译。
      • 听起来您的环境有问题。其他 dll 是否也会发生这种情况?
      【解决方案4】:

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

      【讨论】:

      • @adam0101 在解决方案资源管理器中右键单击引用下的程序集,转到属性,您应该会看到那里列出的那些。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      相关资源
      最近更新 更多