Skip to content

Fix missing BaseAddress on OData HttpClient#79

Merged
Mikeoso merged 1 commit intomainfrom
fix/odata/set-httpclient-base-address
Apr 1, 2026
Merged

Fix missing BaseAddress on OData HttpClient#79
Mikeoso merged 1 commit intomainfrom
fix/odata/set-httpclient-base-address

Conversation

@Mikeoso
Copy link
Copy Markdown
Owner

@Mikeoso Mikeoso commented Apr 1, 2026

Summary

  • Set HttpClient.BaseAddress from ODataSettings.Url during OData client registration
  • PanoramicData.OData.Client passes relative URIs to HttpClient.SendAsync internally, which requires BaseAddress to be set — without it, an InvalidOperationException is thrown at runtime

Test plan

  • dotnet build passes (0 errors)
  • All 220 tests pass
  • Verify OData calls succeed in consumer project (INW.Integration.COOR)

🤖 Generated with Claude Code

PanoramicData.OData.Client passes relative URIs to HttpClient.SendAsync
internally. Without BaseAddress set on the HttpClient, this causes an
InvalidOperationException at runtime even though ODataClientOptions.BaseUrl
is configured correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 1, 2026 08:10
@Mikeoso Mikeoso merged commit ddf7646 into main Apr 1, 2026
4 checks passed
Copy link
Copy Markdown
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 updates the OData client DI registration to set HttpClient.BaseAddress from ODataSettings.Url, preventing runtime InvalidOperationException when the PanoramicData OData client sends relative URIs.

Changes:

  • Set HttpClient.BaseAddress during OData client registration based on ODataSettings.Url.
Comments suppressed due to low confidence (2)

IntegratoR.OData/Common/Extensions/ApplicationDependencyInjection.cs:122

  • HttpClient.BaseAddress URI resolution is sensitive to a trailing slash. With a configured URL like https://.../data (no trailing /, as used in tests), resolving a relative request URI like $metadata or Customers will drop the data segment and produce https://.../$metadata / https://.../Customers. Consider normalizing BaseAddress to ensure it ends with / (and keep ODataClientOptions.BaseUrl consistent) so relative OData paths stay under the intended /data/ endpoint.
            httpClient.BaseAddress = new Uri(settings.Url);

            var options = new ODataClientOptions
            {
                BaseUrl = settings.Url,
                HttpClient = httpClient

IntegratoR.OData/Common/Extensions/ApplicationDependencyInjection.cs:123

  • This change introduces important runtime behavior (ensuring relative URIs can be sent via HttpClient), but there’s no unit test asserting the ODataClient’s underlying HttpClient has a BaseAddress set (or that a relative request no longer throws InvalidOperationException). Consider adding a focused DI test that resolves ODataClient and verifies it can issue a relative request without throwing (using a fake HttpMessageHandler), to prevent regressions.
            httpClient.BaseAddress = new Uri(settings.Url);

            var options = new ODataClientOptions
            {
                BaseUrl = settings.Url,
                HttpClient = httpClient
            };

Comment on lines 116 to 118
httpClient.Timeout = TimeSpan.FromSeconds(settings.Timeout);
httpClient.BaseAddress = new Uri(settings.Url);

Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

new Uri(settings.Url) will throw (UriFormatException/ArgumentNullException) if ODataSettings.Url is empty or malformed. Since ODataSettings.Url defaults to string.Empty and there’s no options validation in this registration path, consider validating with Uri.TryCreate(..., UriKind.Absolute, out var uri) and throwing a clearer configuration error (e.g., indicating ODataSettings:Url must be a valid absolute URL).

Copilot uses AI. Check for mistakes.
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