Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

OllamaSharp supports Native AOT when provided with a JsonSerializerContext, but the Aspire integration did not expose this configuration option.

Changes

  • OllamaSharpSettings: Added JsonSerializerContext property with XML documentation referencing OllamaSharp's AOT docs
  • AspireOllamaSharpExtensions: Updated OllamaApiClient instantiation to use constructor overload accepting JsonSerializerContext and selectedModel
  • Tests: Added unit tests verifying context is properly passed for both keyed and non-keyed client registration scenarios
  • README: Added Native AOT Support section with usage examples

Usage

[JsonSerializable(typeof(ChatRequest))]
[JsonSerializable(typeof(ChatResponseStream))]
public partial class MyCustomJsonContext : JsonSerializerContext { }

builder.AddKeyedOllamaApiClient("embedding", settings => 
    settings.JsonSerializerContext = MyCustomJsonContext.Default)
    .AddEmbeddingGenerator();

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • awaescher.github.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow passing JsonSerializerContext to Ollama</issue_title>
<issue_description>### Related to an existing integration?

Yes

Existing integration

CommunityToolkit.Aspire.OllamaSharp

Overview

OllamaSharp's client is AOT compatible if you pass in a JsonSerializerContext with the type information.

However, Aspire's integration does not allow passing this field in making it impossible to use this package in an AOT environment.

Usage example

builder.AddKeyedOllamaApiClient("embedding", settings => settings.JsonSerializerContext = MySerializerContext.Default)
	.AddEmbeddingGenerator();

basically add in the option to pass the JsonSerializerContext

Breaking change?

No

Alternatives

currently no alternatives exist to make AOT possible

Additional context

OllamaSharp's documentation refers to this:
https://awaescher.github.io/OllamaSharp/docs/native-aot-support.html

Help us help you

Yes, I'd like to be assigned to work on this item</issue_description>

<agent_instructions>Be sure to refer to https://awaescher.github.io/OllamaSharp/docs/native-aot-support.html for an example of how to use this</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 12, 2026 05:11
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to pass JsonSerializerContext to Ollama Add JsonSerializerContext support for Native AOT compatibility in OllamaSharp integration Jan 12, 2026
Copilot AI requested a review from aaronpowell January 12, 2026 05:20
@aaronpowell aaronpowell marked this pull request as ready for review January 12, 2026 05:38
Copilot AI review requested due to automatic review settings January 12, 2026 05:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Native AOT compatibility to the OllamaSharp integration by exposing the JsonSerializerContext configuration option. OllamaSharp requires a custom JsonSerializerContext for Native AOT scenarios, but the Aspire integration previously did not allow passing this configuration.

Changes:

  • Added JsonSerializerContext property to OllamaSharpSettings with XML documentation
  • Updated OllamaApiClient instantiation to use constructor accepting JsonSerializerContext
  • Added comprehensive test coverage for both keyed and non-keyed client scenarios
  • Added Native AOT Support section to README with usage examples

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/CommunityToolkit.Aspire.OllamaSharp/OllamaSharpSettings.cs Added JsonSerializerContext property with XML documentation linking to OllamaSharp's AOT docs
src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs Updated client instantiation to pass SelectedModel and JsonSerializerContext to constructor
tests/CommunityToolkit.Aspire.OllamaSharp.Tests/OllamaApiClientTests.cs Added tests verifying JsonSerializerContext is properly passed for keyed and non-keyed clients, plus test with settings overload
tests/CommunityToolkit.Aspire.OllamaSharp.Tests/ConfigurationTests.cs Added test verifying JsonSerializerContext is null by default
src/CommunityToolkit.Aspire.OllamaSharp/README.md Added Native AOT Support section with example usage and link to OllamaSharp documentation

@aaronpowell aaronpowell merged commit 9c1ca54 into main Jan 13, 2026
115 of 116 checks passed
@aaronpowell aaronpowell deleted the copilot/allow-jsonserializercontext-passing branch January 13, 2026 03:05
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.

Allow passing JsonSerializerContext to Ollama

2 participants