Confusing behavior with Workbook.CalculateFormula (.Net)

I’m running in to an issue with calculations where a formula that should produce a valid result is giving me a #NAME? error instead. For some reason, setting the formula again after the calculation and calculating again resolves this.

Basically the following happens:

Workbook.CalculateFormula()
Cell.Value is #NAME?
Cell.Formula = Cell.Formula
Workbook.CalculateFormula()
Cell.Value is 4500

I’ve attached a sample project which reproduces this behavior. Is there some change I can make to get CalculateFormula to work the first time?

Edit: I did some more testing and discovered that filling the primaryDataSet after the other sets resolves this issue. This is an acceptable workaround for me. However, I feel that if manual calculation is specified, this should not be a problem in the first place.

AsposeTester.zip (5.5 MB)

@Donnager,
Issue is reproduced here however we need to analyze it more. We have logged this issue in our database for further investigation and you will be notified once any update is ready to share.

This issue is logged as:
CELLSNET-47587 - Workbook.CalculateFormula() produces result when formula is set again

@Donnager,
About “filling the primaryDataSet after the other sets resolves this issue”, in fact it is the correct sequence and the original logic is incorrect. In the original code, when setting formulas, the referenced worksheet May01 and named range have not been created yet, so the reference becomes #NAME?. And you will get the same result when you set the formula in same sequence.