Skip to content

Commit db29c24

Browse files
adegeogewarren
andauthored
Add info about PictureBox behavior changes (#9591)
* Add info about PictureBox behavior changes * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> * Change to include file --------- Co-authored-by: Genevieve Warren <[email protected]>
1 parent 2793ea8 commit db29c24

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Starting with .NET 8, the behavior of how a `PictureBox` control loads a remote image changed. By default, the <xref:System.Net.ServicePointManager.CheckCertificateRevocationList?displayProperty=fullName> property is set to `true` before a remote image is downloaded through <xref:System.Net.WebClient>. This setting ensures that servers with certificates have those certificates checked against the certificate authority revocation list (CRL) as part of the validation process.
2+
3+
> [!WARNING]
4+
> As soon as a remote image is loaded, `CheckCertificateRevocationList` is changed to `true` for the lifetime of the app. You can revert back to `false` manually if required, but as soon as another remote image is loaded, `CheckCertificateRevocationList` is set to `true`.
5+
6+
A previously working remote resource might fail to load when the locally cached CRL is out-of-date and an update can't be retrieved. This can happen when the network the app is running on is restricted and the CRL location isn't on the allowlist.
7+
8+
It's also possible that the delay in checking the CRL negatively affects the app's ability to function.
9+
10+
You can opt out of this behavior by setting the `System.Windows.Forms.ServicePointManagerCheckCrl` option for the app, in one of the following ways:
11+
12+
- Set the property to `false` in the [_\[app\].runtimeconfig.json_](/dotnet/core/runtime-config/#runtimeconfigjson) configuration file:
13+
14+
```json
15+
{
16+
"configProperties": {
17+
"System.Windows.Forms.ServicePointManagerCheckCrl": false
18+
}
19+
}
20+
```
21+
22+
- Add a `<RuntimeHostConfigurationOption>` item in the project file to disable it:
23+
24+
```xml
25+
<ItemGroup>
26+
<RuntimeHostConfigurationOption Include="System.Windows.Forms.ServicePointManagerCheckCrl" Value="false" />
27+
</ItemGroup>
28+
```

xml/System.Windows.Forms/PictureBox.xml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,13 @@
11921192
<Parameters />
11931193
<Docs>
11941194
<summary>Displays the image specified by the <see cref="P:System.Windows.Forms.PictureBox.ImageLocation" /> property of the <see cref="T:System.Windows.Forms.PictureBox" />.</summary>
1195-
<remarks>To be added.</remarks>
1195+
<remarks>
1196+
<format type="text/markdown"><![CDATA[
1197+
1198+
[!INCLUDE[drawing](~/includes/System.Windows.Forms.PictureBox/load-behavior-changes.md)]
1199+
1200+
]]></format>
1201+
</remarks>
11961202
<exception cref="T:System.InvalidOperationException">
11971203
<see cref="P:System.Windows.Forms.PictureBox.ImageLocation" /> is <see langword="null" /> or an empty string.</exception>
11981204
<altmember cref="Overload:System.Windows.Forms.PictureBox.LoadAsync" />
@@ -1228,7 +1234,12 @@
12281234
<format type="text/markdown"><![CDATA[
12291235
12301236
## Remarks
1231-
If the `url` parameter indicates a local file, the recommended format is a local file path. For example, an image file named myPicture.jpglocated atc:\ would be accessed by passing **c:\myPicture.jpg** for the `url` parameter. A full path, such as `http://www.contoso.com/path/images/image.jpg`, or a relative path, such as **./images/image.jpg**, can be used. If a relative path is used, it will be considered relative to the working directory. A call to the <xref:System.Windows.Forms.PictureBox.Load%2A> method sets the <xref:System.Windows.Forms.PictureBox.ImageLocation%2A> property to the value of `url`.
1237+
1238+
If the `url` parameter indicates a local file, the recommended format is a local file path. For example, an image file named _myPicture.jpg_ located at _c:\\_ would be accessed by passing `c:\myPicture.jpg` for the `url` parameter. A full path, such as `http://www.contoso.com/path/images/image.jpg`, or a relative path, such as **./images/image.jpg**, can be used. If a relative path is used, it will be considered relative to the working directory. A call to the <xref:System.Windows.Forms.PictureBox.Load%2A> method sets the <xref:System.Windows.Forms.PictureBox.ImageLocation%2A> property to the value of the `url` parameter.
1239+
1240+
### Load behavior changes
1241+
1242+
[!INCLUDE[drawing](~/includes/System.Windows.Forms.PictureBox/load-behavior-changes.md)]
12321243
12331244
]]></format>
12341245
</remarks>
@@ -1279,9 +1290,14 @@
12791290
<format type="text/markdown"><![CDATA[
12801291
12811292
## Remarks
1282-
Besides calling the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method, the <xref:System.Windows.Forms.PictureBox.WaitOnLoad%2A> property must be set to `false` to load an image asynchronously. When you load an image asynchronously, you can handle the <xref:System.Windows.Forms.PictureBox.LoadProgressChanged> event to determine the progress of an image load or the <xref:System.Windows.Forms.PictureBox.LoadCompleted> event to determine when an image load has completed.
12831293
1284-
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.Windows.Forms.PictureBox.Load>.
1294+
Besides calling the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method, the <xref:System.Windows.Forms.PictureBox.WaitOnLoad%2A> property must be set to `false` to load an image asynchronously. When you load an image asynchronously, you can handle the <xref:System.Windows.Forms.PictureBox.LoadProgressChanged> event to determine the progress of an image load or the <xref:System.Windows.Forms.PictureBox.LoadCompleted> event to determine when an image load has completed.
1295+
1296+
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.Windows.Forms.PictureBox.Load>.
1297+
1298+
### Load behavior changes
1299+
1300+
[!INCLUDE[drawing](~/includes/System.Windows.Forms.PictureBox/load-behavior-changes.md)]
12851301
12861302
]]></format>
12871303
</remarks>
@@ -1317,17 +1333,23 @@
13171333
<format type="text/markdown"><![CDATA[
13181334
13191335
## Remarks
1320-
If the `url` parameter indicates a local file, the recommended format is a local file path. For example, an image file named myPicture.jpglocated atc:\ would be accessed by passing **c:\myPicture.jpg** for the `url` parameter. A full path, such as `http://www.contoso.com/path/images/image.jpg`, or a relative path, such as **./images/image.jpg**, can be used. If a relative path is used, it will be considered relative to the working directory. A call to the <xref:System.Windows.Forms.PictureBox.Load%2A> method sets the <xref:System.Windows.Forms.PictureBox.ImageLocation%2A> property to the value of `url`.
13211336
1322-
A call to the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method sets the <xref:System.Windows.Forms.PictureBox.ImageLocation%2A> property to the value of `url`. Besides calling the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method, you must set the <xref:System.Windows.Forms.PictureBox.WaitOnLoad%2A> property to `false` to load an image asynchronously. When you load an image asynchronously, you can handle the <xref:System.Windows.Forms.PictureBox.LoadProgressChanged> event to determine the progress of an image load or the <xref:System.Windows.Forms.PictureBox.LoadCompleted> event to determine when an image load has completed. If an error occurs during an asynchronous image-loading operation, it will be caught and reported by the <xref:System.ComponentModel.AsyncCompletedEventArgs.Error%2A> property of the <xref:System.ComponentModel.AsyncCompletedEventArgs>.
1337+
If the `url` parameter indicates a local file, the recommended format is a local file path. For example, an image file named _myPicture.jpg_ located at _c:\\_ would be accessed by passing `c:\myPicture.jpg` for the `url` parameter. A full path, such as `http://www.contoso.com/path/images/image.jpg`, or a relative path, such as **./images/image.jpg**, can be used. If a relative path is used, it will be considered relative to the working directory. A call to the <xref:System.Windows.Forms.PictureBox.Load%2A> method sets the <xref:System.Windows.Forms.PictureBox.ImageLocation%2A> property to the value of the `url` parameter.
1338+
1339+
A call to the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method sets the <xref:System.Windows.Forms.PictureBox.ImageLocation%2A> property to the value of `url`. Besides calling the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method, you must set the <xref:System.Windows.Forms.PictureBox.WaitOnLoad%2A> property to `false` to load an image asynchronously. When you load an image asynchronously, you can handle the <xref:System.Windows.Forms.PictureBox.LoadProgressChanged> event to determine the progress of an image load or the <xref:System.Windows.Forms.PictureBox.LoadCompleted> event to determine when an image load has completed. If an error occurs during an asynchronous image-loading operation, it will be caught and reported by the <xref:System.ComponentModel.AsyncCompletedEventArgs.Error%2A> property of the <xref:System.ComponentModel.AsyncCompletedEventArgs>.
1340+
1341+
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.Windows.Forms.PictureBox.Load(System.String)>.
13231342
1324-
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.Windows.Forms.PictureBox.Load(System.String)>.
1343+
### Load behavior changes
1344+
1345+
[!INCLUDE[drawing](~/includes/System.Windows.Forms.PictureBox/load-behavior-changes.md)]
13251346
13261347
## Examples
1327-
The following code example demonstrates how to use the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method. To run this example, paste the following code into a Windows Form that contains a <xref:System.Windows.Forms.PictureBox> named `pictureBox1` and a <xref:System.Windows.Forms.Button> named `startLoadButton`. Make sure that the <xref:System.Windows.Forms.Control.Click> event for the button is associated with the `startLoadButton_Click` method in this example. You must change the image file path to a path that is valid on your system.
13281348
1329-
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/PictureBox/CancelAsync/Form1.cs" id="Snippet3":::
1330-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.TreeViewPictureBoxWhidbeyMembers/VB/Form1.vb" id="Snippet3":::
1349+
The following code example demonstrates how to use the <xref:System.Windows.Forms.PictureBox.LoadAsync%2A> method. To run this example, paste the following code into a Windows Form that contains a <xref:System.Windows.Forms.PictureBox> named `pictureBox1` and a <xref:System.Windows.Forms.Button> named `startLoadButton`. Make sure that the <xref:System.Windows.Forms.Control.Click> event for the button is associated with the `startLoadButton_Click` method in this example. You must change the image file path to a path that is valid on your system.
1350+
1351+
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/PictureBox/CancelAsync/Form1.cs" id="Snippet3":::
1352+
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.TreeViewPictureBoxWhidbeyMembers/VB/Form1.vb" id="Snippet3":::
13311353
13321354
]]></format>
13331355
</remarks>

0 commit comments

Comments
 (0)