Free Support Forum - aspose.com

"Specified cast is not valid." Error from aspose words

Hi,

I am using aspose words V6.6.
I do normalization process for word document. After performing few setting using aspose words object, while saving word document i am getting “Specified cast is not valid.” Error.

Herewith i have attached sample document, and code snippet.


Regards,
Karthik

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. In your code you also use ReplaceFieldType and RemoveFieldType methods. Could you please share these method as well? I will check the issue and provide you more information.

Best regards.

Code Snippet:


Sub RemoveField(ByVal fieldStart As FieldStart)
Try
Dim node As Node
Dim nextNode As Node
node = fieldStart
While ((Not node Is Nothing) And (Not node.NodeType = NodeType.FieldEnd))
nextNode = node.NextSibling
node.Remove()
node = nextNode
End While
If (Not node Is Nothing) Then
node.Remove()
End If
Catch ex As Exception

End Try
End Sub

Sub RemoveFieldType(ByVal node As Object, ByVal fType As FieldType)
Try

Dim fields As NodeCollection = node.GetChildNodes(NodeType.FieldStart, True)
Dim field As FieldStart
For Each field In fields
If (field.FieldType = fType) Then
RemoveField(field)
End If
Next
Catch ex As Exception

End Try
End Sub

Sub ReplaceFieldType(ByVal node As Object, ByVal fType As FieldType, ByVal builder As DocumentBuilder, ByRef replaceValue As String)
Try

Dim fields As NodeCollection = node.GetChildNodes(NodeType.FieldStart, True)
Dim field As FieldStart
For Each field In fields
If (field.FieldType = fType) Or (field.FieldType = FieldType.FieldTime) Then
Try
builder.MoveTo(field.ParentNode)
RemoveField(field)
builder.Write(replaceValue)
Catch ex As Exception
Try
If (Not field.PreviousSibling Is Nothing) Then
builder.MoveTo(field.PreviousSibling)
RemoveField(field)
builder.Write(replaceValue)
Else
RemoveField(field)
End If
Catch
RemoveField(field)
End Try
End Try
End If
Next

Catch ex As Exception

End Try
End Sub

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

It seems there is something wrong with your document. If open/save the document in MS Word, the problem disappears.

Best regards.

The issues you have found earlier (filed as 15063) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.