Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

<!-- BCL packages -->
<PackageReference Update="System.Buffers" Version="4.5.1" />
<PackageReference Update="System.ClientModel" Version="1.3.0" />
<PackageReference Update="System.ClientModel" Version="1.4.0" />
<PackageReference Update="System.IO.Hashing" Version="8.0.0" />
<PackageReference Update="System.Memory" Version="4.5.5" />
<PackageReference Update="System.Memory.Data" Version="6.0.1" />
Expand Down Expand Up @@ -209,7 +209,7 @@
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250501.3" />
<PackageReference Update="Microsoft.TypeSpec.Generator.Input" Version="1.0.0-alpha.20250501.3" />
<PackageReference Update="Azure.Generator" Version="1.0.0-alpha.20250429.2" />
<PackageReference Update="System.ClientModel" Version="1.3.0" />
<PackageReference Update="System.ClientModel" Version="1.4.0" />
</ItemGroup>

<!--
Expand Down Expand Up @@ -411,7 +411,7 @@
<PackageReference Update="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Update="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Update="PublicApiGenerator" Version="10.0.1" />
<PackageReference Update="System.ClientModel" Version="1.3.0" />
<PackageReference Update="System.ClientModel" Version="1.4.0" />
<PackageReference Update="System.Diagnostics.TraceSource" Version="4.3.0" />
<PackageReference Update="System.IO.Compression" Version="4.3.0" />
<PackageReference Update="System.IO.Pipelines" Version="4.5.1" />
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net462.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public partial struct AccessToken
public override bool Equals(object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class AzureCoreContext : System.ClientModel.Primitives.ModelReaderWriterContext
{
internal AzureCoreContext() { }
public static Azure.Core.AzureCoreContext Default { get { throw null; } }
protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct AzureLocation : System.IEquatable<Azure.Core.AzureLocation>
{
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net472.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public partial struct AccessToken
public override bool Equals(object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class AzureCoreContext : System.ClientModel.Primitives.ModelReaderWriterContext
{
internal AzureCoreContext() { }
public static Azure.Core.AzureCoreContext Default { get { throw null; } }
protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct AzureLocation : System.IEquatable<Azure.Core.AzureLocation>
{
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public partial struct AccessToken
public override bool Equals(object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class AzureCoreContext : System.ClientModel.Primitives.ModelReaderWriterContext
{
internal AzureCoreContext() { }
public static Azure.Core.AzureCoreContext Default { get { throw null; } }
protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct AzureLocation : System.IEquatable<Azure.Core.AzureLocation>
{
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net8.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ public partial struct AccessToken
public override bool Equals(object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class AzureCoreContext : System.ClientModel.Primitives.ModelReaderWriterContext
{
internal AzureCoreContext() { }
public static Azure.Core.AzureCoreContext Default { get { throw null; } }
protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct AzureLocation : System.IEquatable<Azure.Core.AzureLocation>
{
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public partial struct AccessToken
public override bool Equals(object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class AzureCoreContext : System.ClientModel.Primitives.ModelReaderWriterContext
{
internal AzureCoreContext() { }
public static Azure.Core.AzureCoreContext Default { get { throw null; } }
protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct AzureLocation : System.IEquatable<Azure.Core.AzureLocation>
{
Expand Down
14 changes: 14 additions & 0 deletions sdk/core/Azure.Core/src/AzureCoreContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel.Primitives;

namespace Azure.Core
{
/// <summary>
/// Context class used by <see cref="ModelReaderWriter"/> to read and write models in an AOT compatible way.
/// </summary>
public partial class AzureCoreContext : ModelReaderWriterContext
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static RehydrationToken GetRehydrationToken(
{"version":"{{RehydrationTokenVersion}}","id":{{ConstructStringValue(operationId)}},"requestMethod":"{{requestMethod}}","initialUri":"{{startRequestUri.AbsoluteUri}}","nextRequestUri":"{{nextRequestUri}}","headerSource":"{{headerSource}}","finalStateVia":"{{finalStateVia}}","lastKnownLocation":{{ConstructStringValue(lastKnownLocation)}}}
""";
var data = new BinaryData(json);
return ModelReaderWriter.Read<RehydrationToken>(data);
return ModelReaderWriter.Read<RehydrationToken>(data, ModelReaderWriterOptions.Json);
}

private static string? ConstructStringValue(string? value) => value is null ? "null" : $"\"{value}\"";
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/Azure.Core/tests/RehydrationTokenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public void ThrowOnDeserializationWithNullRehydrationToken()
[Test]
public void ThrowOnDeserializationWithRehydrationTokenNullRequiredMember()
{
// net462 doesn't play well with validating debug asserts
#if !NETFRAMEWORK
var data = BinaryData.FromString("{\"requestMethod\": null}");
Assert.That(() => ModelReaderWriter.Read(data, typeof(RehydrationToken)), Throws.Exception);
#endif
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);SCM0001</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using NUnit.Framework;
using System.ClientModel.Primitives;
using System.ClientModel.Tests.Client.ModelReaderWriterTests.Models;
using System.ClientModel.Tests.ModelReaderWriterTests;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.Json;
using NUnit.Framework;

namespace System.ClientModel.Tests.Internal.ModelReaderWriterTests
{
Expand Down Expand Up @@ -148,7 +147,7 @@ public void ConvertWithMissingInfo()
public void ConvertWithBadContext()
{
var options = new JsonSerializerOptions();
var converter = new JsonModelConverter(ModelReaderWriterOptions.Json, new BadContext());
var converter = new JsonModelConverter(ModelReaderWriterOptions.Json, SystemClientModelTestsInternalContext.Default);
options.Converters.Add(converter);
var ex = Assert.Throws<InvalidOperationException>(() => JsonSerializer.Deserialize("{}", typeof(PersistableModel), options));
Assert.IsNotNull(ex);
Expand Down Expand Up @@ -211,33 +210,11 @@ private static Dictionary<string, BinaryData> GetRawData(object model)
return (Dictionary<string, BinaryData>)propertyInfo!.GetValue(model)!;
}

private class BadContext : ModelReaderWriterContext
{
private PersistableModelInfo? _persistableModelInfo;

protected override bool TryGetTypeBuilderCore(Type type, out ModelReaderWriterTypeBuilder? builder)
{
builder = type switch
{
Type t when t == typeof(PersistableModel) => _persistableModelInfo ??= new(),
_ => null
};
return builder is not null;
}

private class PersistableModelInfo : ModelReaderWriterTypeBuilder
{
protected override Type BuilderType => typeof(DoesNotImplementPersistableModel);

protected override object CreateInstance() => new DoesNotImplementPersistableModel();
}
}

private class DoesNotImplementPersistableModel
internal class DoesNotImplementPersistableModel
{
}

private class PersistableModel : IJsonModel<PersistableModel>
internal class PersistableModel : IJsonModel<PersistableModel>
{
public PersistableModel Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => new();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel.Primitives;
using System.Collections.Generic;

namespace System.ClientModel.Tests.Internal.ModelReaderWriterTests
{
internal partial class SystemClientModelTestsInternalContext : ModelReaderWriterContext
{
partial void AddAdditionalFactories(Dictionary<Type, Func<ModelReaderWriterTypeBuilder>> factories)
{
factories.Add(typeof(JsonModelConverterTests.PersistableModel), () => new PersistableModelInfo());
}

private class PersistableModelInfo : ModelReaderWriterTypeBuilder
{
protected override Type BuilderType => typeof(JsonModelConverterTests.DoesNotImplementPersistableModel);

protected override object CreateInstance() => new JsonModelConverterTests.DoesNotImplementPersistableModel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\System.ClientModel.csproj" />
<ProjectReference Include="..\..\gen\System.ClientModel.SourceGeneration.csproj" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="..\client\System.ClientModel.Tests.Client.csproj" />
<ProjectReference Include="..\System.ClientModel.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion sdk/openai/Azure.AI.OpenAI/src/Azure.AI.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<!-- TEMP until Azure.Core is released with updated SCM version -->
<ItemGroup>
<ProjectReference Include="..\..\..\core\System.ClientModel\src\System.ClientModel.csproj" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
-->
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.ClientModel" />
<PackageReference Update="System.ClientModel" VersionOverride="1.4.0-beta.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PackageReference Include="Moq" />
<PackageReference Include="System.ValueTuple" />
<PackageReference Include="System.ClientModel" />
<PackageReference Update="System.ClientModel" VersionOverride="1.4.0-beta.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading