错误“类型 Aspose.Words.Document”未定义。'当尝试编译时
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现这一定是因为 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.
是否有多个库可供参考?另外,你的进口声明在哪里?
Are there multiple libraries to reference? Also, where is your imports statement?
检查您是否引用了正确的 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.
确保将程序集上的
Copy Local
设置为 true,并将Embed Intrerop
设置为 false。Make sure you have the
Copy Local
on the assembly set to true andEmbed Intrerop
is set to false.