Document style added when checking if style exist

Hi Aspose team,

I’ve found an issue with handling styles, that is causing problems on our side. Looks like for some style names the style is added to document when checking if it exists.
Example code:

    [Test]
    public void Should_NotAddStyle_When_CheckingIfStyleExist()
    {
        var doc = new Document();
        var builder = new DocumentBuilder(doc);

        Assert.AreEqual(4, doc.Styles.Count);
        bool exist = builder.Document.Styles["Title"] == null;
        Assert.AreEqual(4, doc.Styles.Count);
    }

Second assertion fails, as new Style is added. Additionally, this style seems to have different than default formatting (Bold). Could you please suggest how to approach this?

Thanks,
Mateusz

@acturisaspose,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of any corrections in Aspose.Words API, we have logged this problem in our issue tracking system with ID WORDSNET-21699. We will further look into the details of this problem and will keep you updated on the status of linked issue. We apologize for your inconvenience.

Hi,

I see that this only occurs for some style names (probably some default word styles) - will it be possible for you to provide me with the list of affected ones so I can implement temporary workaround in my code?

Thanks,
Mateusz

@acturisaspose,

According to the documentation of StyleCollection: “If this is an English name of a built in style that does not yet exist, automatically creates it.”. So, this is an expected behavior.

We will close WORDSNET-21699 with ‘not a bug’ status.