Skip to content

Use HttpClient in PictureBox #11544

@lonitra

Description

@lonitra

ServicePointManager and WebClient are obselete, but are being used in PictureBox

private void LoadImageViaWebClient()
{
Image img;
Uri uri = CalculateUri(_imageLocation!);
if (uri.IsFile)
{
_localImageStreamReader = new StreamReader(uri.LocalPath);
img = Image.FromStream(_localImageStreamReader.BaseStream);
}
else
{
if (LocalAppContextSwitches.ServicePointManagerCheckCrl)
{
ServicePointManager.CheckCertificateRevocationList = true;
}
#pragma warning disable SYSLIB0014 // Type or member is obsolete
using WebClient webClient = new(); // lgtm[cs/webrequest-checkcertrevlist-disabled] - Having ServicePointManager.CheckCertificateRevocationList set to true has a slim chance of resulting in failure. We have an opt-out for this rare event.
#pragma warning restore SYSLIB0014 // Type or member is obsolete
_uriImageStream = webClient.OpenRead(uri.ToString());
img = Image.FromStream(_uriImageStream);
}
InstallNewImage(img, ImageInstallationType.FromUrl);
}

We needed to suppress SYSLIB0014 warning in #11540 to unblock depdency flow, but we should update this code to use HttpClient

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions