We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Fields.FieldStart'

Hello,

I get the following exception when trying to open the attached document with Aspose:

Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Fields.FieldStart'.

The document can be opened by Word2007 without any exceptions.

This document is a result of applying MailMerge.Execute from Aspose. The original document can be opened by both Word and Aspose.

BR

Hi

Thanks for reporting this problem to us. I managed to reproduce this issue. Could you please attach your template file for testing?

Best regards.

Of corse, here it is.

Hi

I created an issue in our defect database.

Issue #4503 - “System.InvalidCastException” occurs during opening DOCX file.

Please expect a reply before the next hotfix (within 2-3 weeks). We might just fix it by then or provide more information.

Could you tell me this occurs if you use UNC path to open and save document? Also please provide me your code. I tried to use the following code and output document works fine.

Document doc = new Document(@"Test031\in.docx");

string[] names = doc.MailMerge.GetFieldNames();

doc.MailMerge.Execute(names, names);

doc.Save(@"Test031\out.docx", SaveFormat.Docx);

Best regards.

Hello,

Yes everything is happened on UNC path.

The code is pretty simple

Document = New Aspose.Words.Document(_FileName, Aspose.Words.LoadFormat.Docx, String.Empty)

Document.MailMerge.Execute(Names, Values)

Document.MailMerge.DeleteFields()

Document.Save(_FileName, Aspose.Words.SaveFormat.Docx)

But names() and values() arrays contain almost 300 items. If you think that these arrays could be useful for you I canl export these values.

BR,

Olexandr

Hi

I think that this is some issue with permissions, because I can’t reproduce this problem on my side too. Could you please play around this and tell me whether this has any result.

Best regards.

Also try using the following code.

MemoryStream file = new MemoryStream(File.ReadAllBytes(@"\\192.168.0.4\Test\in.docx"));

Document doc = new Document(file);

string[] names = doc.MailMerge.GetFieldNames();

doc.MailMerge.Execute(names, names);

doc.MailMerge.DeleteFields();

MemoryStream output = new MemoryStream();

doc.Save(output, SaveFormat.Docx);

Stream outputDoc = new FileStream(@"\\192.168.0.4\Test\out.docx", FileMode.Create);

output.WriteTo(outputDoc);

outputDoc.Close();

output.Close();

file.Close();

Best regards.

Hello,

I've tried the code and result is the same.

I will try to play around with different network folders and permissions and let you know the result.

BR,

Olexandr

Local folder gives me the same result! The document can't be opened by aspose aftre the first merge.

Hi

Thanks for additional information. Unfortunately, I have no idea why this occurs on your side but doesn’t occur on my side. Do you have any ideas on this subject?

Best regards.

Maybe these two files will help you to reproduce the bug.

Also, notice the merge is done by WebService in this case.

Hello,

I have found what cause the oproblem. It is not Aspose merge!

My application assign some customr properties to the document. These properties are read fine by Word but Aspose fails to open this document when these properties are added.

So, please just let me open this document with Aspose and I'll be happy :)

BR

Hi

It is nice that you found the reason. Why don’t you use Aspose.Words for adding custom properties to the document? You can use the following code.

doc.CustomDocumentProperties.Add("myCustomProperty", "some value");

Best regards.

Hi,

Actually I didn't use Aspose for .docx because previous versions didn't work with custom properties correctly.

Actually, I am testing Aspose and custom properties these days and if everything is fine I'll move my code to use Aspose.

BR

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