Skip to content

Commit 4d6eb90

Browse files
Merge pull request #42774 from dotnet/main
Merge main into live
2 parents f70e064 + 7e3c17a commit 4d6eb90

File tree

13 files changed

+124
-22
lines changed

13 files changed

+124
-22
lines changed

docs/azure/includes/dotnet-all.md

Lines changed: 10 additions & 9 deletions
Large diffs are not rendered by default.

docs/azure/includes/dotnet-new.md

Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.

docs/azure/sdk/protocol-convenience-methods.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ The preceding code demonstrates the following `System.ClientModel` convenience m
9595

9696
The following code uses a `ChatClient` to call the `CompleteChat` protocol method:
9797

98-
:::code source="snippets/protocol-convenience-methods/SCM/Protocol/Program.cs" highlight="26-31":::
98+
:::code source="snippets/protocol-convenience-methods/SCM/Protocol/Program.cs" highlight="31-34":::
9999

100100
The preceding code demonstrates the following `System.ClientModel` protocol method patterns:
101101

@@ -129,6 +129,20 @@ PipelineResponse response = result.GetRawResponse();
129129

130130
---
131131

132+
## Handle exceptions
133+
134+
When a service call fails, the service client throws an exception that exposes the HTTP status code and the details of the service response, if available. A `System.ClientModel`-dependent library throws a <xref:System.ClientModel.ClientResultException>, while an `Azure.Core`-dependent library throws a <xref:Azure.RequestFailedException>.
135+
136+
# [System.ClientModel exceptions](#tab/system-clientmodel)
137+
138+
:::code source="snippets/protocol-convenience-methods/AzureCore/ExceptionHandling/Program.cs" highlight="21-24":::
139+
140+
# [Azure.Core exceptions](#tab/azure-core)
141+
142+
:::code source="snippets/protocol-convenience-methods/SCM/ExceptionHandling/Program.cs" highlight="17-20":::
143+
144+
---
145+
132146
## Protocol and convenience method usage guidance
133147

134148
Although the Azure SDK for .NET client libraries provide the option to use either protocol or convenience methods, prioritize using convenience methods in most scenarios. Convenience methods are designed to improve the development experience and provide flexibility for authoring requests and handling responses. However, both method types can be used in your app as needed. Consider the following criteria when deciding which type of method to use.

docs/azure/sdk/snippets/protocol-convenience-methods/AzureCore/Convenience/AzureCoreConvenience.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Azure.AI.ContentSafety" />
12+
<PackageReference Include="Azure.Identity" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Azure.AI.ContentSafety;
2+
using Azure.Identity;
3+
using Azure;
4+
5+
// Create the client
6+
ContentSafetyClient client = new(
7+
new Uri("https://contentsafetyai.cognitiveservices.azure.com/"),
8+
new DefaultAzureCredential());
9+
10+
try
11+
{
12+
// Call the convenience method
13+
AnalyzeTextResult result = client.AnalyzeText("What is Microsoft Azure?");
14+
15+
// Display the results
16+
foreach (TextCategoriesAnalysis item in result.CategoriesAnalysis)
17+
{
18+
Console.WriteLine($"{item.Category}: {item.Severity}");
19+
}
20+
}
21+
catch (RequestFailedException ex)
22+
{
23+
Console.WriteLine($"Error: {ex.Message}");
24+
}

docs/azure/sdk/snippets/protocol-convenience-methods/AzureCore/Protocol/AzureCoreProtocol.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using OpenAI.Chat;
2+
using System.ClientModel;
3+
4+
// Create the client
5+
ChatClient client = new(
6+
model: "gpt-4o-mini",
7+
credential: Environment.GetEnvironmentVariable("OPENAI_API_KEY")!);
8+
9+
try
10+
{
11+
// Call the convenience method
12+
ChatCompletion completion = client.CompleteChat("What is Microsoft Azure?");
13+
14+
// Display the results
15+
Console.WriteLine($"[{completion.Role}]: {completion}");
16+
}
17+
catch (ClientResultException ex)
18+
{
19+
Console.WriteLine($"Error: {ex.Message}");
20+
}
21+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="OpenAI" />
12+
</ItemGroup>
13+
14+
</Project>

docs/azure/sdk/snippets/protocol-convenience-methods/SCM/Protocol/Program.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
"""u8.ToArray());
2323
using BinaryContent content = BinaryContent.Create(input);
2424

25+
var requestOptions = new RequestOptions();
26+
27+
requestOptions.AddHeader("CustomHeader", "CustomHeaderValue");
28+
requestOptions.ErrorOptions = ClientErrorBehaviors.NoThrow;
29+
2530
// Call the protocol method
2631
ClientResult result = client.CompleteChat(
2732
content,
28-
new RequestOptions
29-
{
30-
ErrorOptions = ClientErrorBehaviors.NoThrow,
31-
});
33+
requestOptions
34+
);
3235

3336
PipelineResponse response = result.GetRawResponse();
3437

docs/azure/sdk/snippets/protocol-convenience-methods/SCM/Protocol/SCMProtocol.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

docs/core/docker/build-container.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ If you pass a number on the command line to the app, it will only count up to th
126126
127127
## Publish .NET app
128128

129-
Before adding the .NET app to the Docker image, first it must be published. It's best to have the container run the published version of the app. To publish the app, run the following command:
129+
In order for the app to be suitable for an image creation it has to be built. The `dotnet publish` command is most apt for this, as it builds and publishes the app. For an in-depth reference, see [dotnet build](/dotnet/core/tools/dotnet-build) and [dotnet publish](/dotnet/core/tools/dotnet-publish) commands documentation.
130130

131131
```dotnetcli
132132
dotnet publish -c Release
@@ -141,6 +141,9 @@ This command compiles your app to the *publish* folder. The path to the *publish
141141

142142
This command compiles your app to the *publish* folder. The path to the *publish* folder from the working folder should be `.\App\bin\Release\net7.0\publish\`.
143143

144+
> [!NOTE]
145+
> Application publishing is needed for image creation but this is rather orchestrated by the _Dockerfile_. See [Create the Dockerfile](#create-the-dockerfile).
146+
144147
:::zone-end
145148

146149
#### [Windows](#tab/windows)

docs/core/tools/dotnet-tool-install.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Global tools are installed in the following directories by default when you spec
6363

6464
Executables are generated in these folders for each globally installed tool, although the actual tool binaries are nested deep into the sibling `.store` directory.
6565

66+
> [!NOTE]
67+
> On Linux after installing a command-line tool with `dotnet tool`, the tool can be executed only from the `$HOME/.dotnet/tools` path.
68+
> To make the tool executable from any directory, update the `PATH` environment variable.
69+
> To make the updated `PATH` environment variable permanent in your shell, update your shell settings.
70+
> For `Bash`, this is the `$HOME/.bashrc` file.
71+
6672
### `--tool-path` tools
6773

6874
Tools with explicit tool paths are stored wherever you specified the `--tool-path` parameter to point to. They're stored in the same way as global tools: an executable binary with the actual binaries in a sibling `.store` directory.

0 commit comments

Comments
 (0)