diff --git a/CHANGELOG.md b/CHANGELOG.md
index a2c603034c5..6291dca843b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ and this project does NOT adhere to [Semantic Versioning](https://semver.org/spe
## [Unreleased]
+## [5.16.1-preview] - 2023-01-16
+
+### Changed
+
+- Fixed a regression where passing custom base url would not be reflected in the requests.
+
## [5.16.0-preview] - 2023-01-11
### Changed
diff --git a/src/Microsoft.Graph/GraphServiceClient.cs b/src/Microsoft.Graph/GraphServiceClient.cs
index 7f08707134f..764aa7c952a 100644
--- a/src/Microsoft.Graph/GraphServiceClient.cs
+++ b/src/Microsoft.Graph/GraphServiceClient.cs
@@ -33,12 +33,9 @@ public class GraphServiceClient: BaseGraphServiceClient, IBaseClient
///
/// The custom to be used for making requests
/// The base service URL. For example, "https://graph.microsoft.com/beta"
- public GraphServiceClient(IRequestAdapter requestAdapter, string baseUrl = null): base(requestAdapter)
+ public GraphServiceClient(IRequestAdapter requestAdapter, string baseUrl = null): base(InitializeRequestAdapterWithBaseUrl(requestAdapter,baseUrl))
{
this.RequestAdapter = requestAdapter;
- if (!string.IsNullOrEmpty(baseUrl)) {
- this.RequestAdapter.BaseUrl = baseUrl;
- }
}
///
@@ -96,5 +93,15 @@ public BatchRequestBuilder Batch
return new BatchRequestBuilder(this.RequestAdapter);
}
}
+
+ private static IRequestAdapter InitializeRequestAdapterWithBaseUrl(IRequestAdapter requestAdapter, string baseUrl)
+ {
+ if (!string.IsNullOrEmpty(baseUrl))
+ {
+ requestAdapter.BaseUrl = baseUrl;
+ }
+
+ return requestAdapter;
+ }
}
}
diff --git a/src/Microsoft.Graph/Microsoft.Graph.Beta.csproj b/src/Microsoft.Graph/Microsoft.Graph.Beta.csproj
index 496dc122737..5c7722f72c5 100644
--- a/src/Microsoft.Graph/Microsoft.Graph.Beta.csproj
+++ b/src/Microsoft.Graph/Microsoft.Graph.Beta.csproj
@@ -22,12 +22,10 @@
35MSSharedLib1024.snk
true
-- [Breaking] Renames `CreateXXXRequestInformation` methods to `ToXXXRequestInformation
-- Adds `IAuthenticationProvider` parameter to GraphServiceClient constructor taking a httpClient instance.
-- Latest metadata updates from 12th January 2023 snapshot
+- Fixed a regression where passing custom base url would not be reflected in the requests.
- 5.16.0
+ 5.16.1
diff --git a/tests/Microsoft.Graph.DotnetCore.Test/Models/GraphServiceClientTests.cs b/tests/Microsoft.Graph.DotnetCore.Test/Models/GraphServiceClientTests.cs
new file mode 100644
index 00000000000..c4b3b35eaa0
--- /dev/null
+++ b/tests/Microsoft.Graph.DotnetCore.Test/Models/GraphServiceClientTests.cs
@@ -0,0 +1,39 @@
+// ------------------------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
+// ------------------------------------------------------------------------------
+
+using Microsoft.Graph.Beta;
+using Microsoft.Kiota.Abstractions.Authentication;
+using Xunit;
+
+namespace Microsoft.Graph.DotnetCore.Test.Models;
+
+public class GraphServiceClientTests
+{
+ [Fact]
+ public void InitializesClient()
+ {
+ // Arrange
+ var graphClient = new GraphServiceClient(new AnonymousAuthenticationProvider());
+
+ // Act
+ var userRequestInformation = graphClient.Me.ToGetRequestInformation();
+
+ // Assert
+ Assert.Contains("https://graph.microsoft.com", userRequestInformation.URI.OriginalString);
+ }
+
+ [Fact]
+ public void InitializesClientWithCustomBaseUrl()
+ {
+ // Arrange
+ var customBaseUrl = "https://graph.microsoft-ppe.com";
+ var graphClient = new GraphServiceClient(new AnonymousAuthenticationProvider(), customBaseUrl);
+
+ // Act
+ var userRequestInformation = graphClient.Me.ToGetRequestInformation();
+
+ // Assert
+ Assert.Contains(customBaseUrl, userRequestInformation.URI.OriginalString);
+ }
+}