Skip to content

Conversation

@ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Jan 24, 2026

Contributes to #5305

Description

Reintroduces code in Factory.CreateTextAnalyzer that I inadvertently removed when migrating from C++/CLI to C# in #6171. IDWriteFactory.CreateTextAnalyzer doesn't do much so the chance of it returning an error is low. Still, it's better to throw early than to let Factory.CreateTextAnalyzer succeed and throw NullReferenceException when using the resulting TextAnalyzer.

This also makes the tests in #11381 that validate that Factory.CreateTextAnalyzer succeeds more meaningful.

Original C++/CLI code:

__declspec(noinline) TextAnalyzer^ Factory::CreateTextAnalyzer()
{
IDWriteTextAnalyzer* textAnalyzer = NULL;
HRESULT hr = _pFactory->CreateTextAnalyzer(&textAnalyzer);
System::GC::KeepAlive(this);
ConvertHresultToException(hr, "TextAnalyzer^ Factory::CreateTextAnalyzer");
return gcnew TextAnalyzer(textAnalyzer);
}

Customer Impact

I think the impact is very low, we now get proper exceptions when creating the TextAnalyzer instead of getting a NullReferenceException when using the TextAnalyzer.

Regression

Yes, was introduced in .Net 9.0 though it has very low impact.

Testing

Tested locally with the tests from #11381.

Risk

Low, reintroduces code that was removed.

@ThomasGoulet73 ThomasGoulet73 requested a review from a team January 24, 2026 03:35
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant