Skip to content

Conversation

@tarikkirsanli
Copy link
Contributor

Description

This PR fixes a NullReferenceException that occurs in AbstractionMapper.ToChatResponseUpdate method when processing streaming responses.

Problem

When the Ollama API returns a response where response or response.Message is null, the current implementation throws a NullReferenceException at:

ToAbstractionRole(response.Message.Role)

Solution

Added null-safe navigation operators to handle null responses gracefully:
ToAbstractionRole(response?.Message?.Role)

Testing

  • Tested with various streaming scenarios including empty responses
  • No breaking changes introduced

Related Issues

This issue was discovered while using OllamaSharp with Microsoft.Extensions.AI in production environments where occasional null responses from the Ollama API caused application crashes.

@awaescher awaescher merged commit 95e1d08 into awaescher:main Nov 14, 2025
1 check passed
@awaescher
Copy link
Owner

Nice find, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants