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

Free Support Forum - aspose.com

Error copying font


I’m using an IReplacingCallback to replace some text in a document. As part of this I’m cloning the Font of a Node. Occasionally an exception is thrown when cloning the font’s StyleIdentifier:

current.Font.StyleIdentifier = copy.StyleIdentifier;

The exception is:

System.ArgumentException: Cannot return user defined styles by style identifier.
at Aspose.Words.StyleCollection.xf21e14e2c9db279a(StyleIdentifier xa3be2ccad541ab25, Boolean x988fcf605f8efa7e)
at Aspose.Words.StyleCollection.x590d8ef356786501(StyleIdentifier xa3be2ccad541ab25)
at Aspose.Words.Font.set_StyleIdentifier(StyleIdentifier value)

Why is this exception thrown and how should I avoid it? Thanks


Thanks for your request. Could you please attach a sample document and provide a simple code that will allow us to reproduce the problem? We will check the issue and provide you more information.

Best regards,

Thanks, I’ll send you on sample code and a sample document.


I will wait for your inputs.

Best regards,

Hi, you should have the sample code and document now (by email).

Hi James,

Thanks for your request. Unfortunately, I did not receive any emails. Could you please simply attach the inputs here n the forum. It is safe to attach files in the forum. Only you and Aspose staff can download the attached files.

Best regards,

Hi, see attached zip file for sample document and code. Thanks.


Thank you for additional information. You should modify your code as shown below (see my comments in the code):

// You cannot set StyleIdentifier.User this identified does nto correspond to any specific style.

// This identified means that style is not standard and created by user, this can be any style created by user.

if (copy.StyleIdentifier != StyleIdentifier.User)

current.Font.StyleIdentifier = copy.StyleIdentifier;

// You have to check whether the style exists in the document, if not, you cannot use it.

if (current.Document.Styles[copy.StyleName] != null)

current.Font.StyleName = copy.StyleName;

Best regards,