dotnet / dotnet/runtime

No dependency from System.Security.Cryptography.Pkcs to Microsoft.Bcl.Cryptography causes X509CertificateLoader issues in .Net 10

Open
#126,072 2 comments 0 reactions 0 assignees View on GitHub
area-System.Security
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

System.Security.Cryptography.Pkcs 10.0.2 (and other 10.x.x versions) has a dependency on Microsoft.Bcl.Cryptography in versions before net10.0 but has no dependencies in net10.0 as a result any code written in a library using Microsoft.Bcl.Cryptography via a transitive dependency and compiled as pre-net10 and then used via projectreference in a net10 project fails due to `System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Bcl.Cryptography'`

### Reproduction Steps

1) Make ClassLibrary1 project targeting net8 and ``
2) Add the Utilities.cs below to ClassLibrary1
```
namespace ClassLibrary1
{
using System;
using System.Security.Cryptography.X509Certificates;

public static class Utilities
{
public static X509Certificate2 Parse(string clientSecret)
{
return X509CertificateLoader.LoadCertificate(Convert.FromBase64String(clientSecret));
}
}
}
```
3) Make ConsoleApp1 project targeting net10 and ProjectReference to ClassLibrary1
4) Update program.cs in ConsoleApp1 below
```
namespace ConsoleApp1
{
using ClassLibrary1;

class Program
{
static void Main(string[] args)
{
// Self-Signed cert, not a secret
var cert = Utilities.Parse("MIICtTCCAZ2gAwIBAgIJAIBtw/Sm5KB2MA0GCSqGSIb3DQEBCwUAMBoxGDAWBgNVBAMTD1Rlc3RDZXJ0aWZpY2F0ZTAeFw0yNjAzMjUwMzI0MjlaFw0yNzAzMjUwMzI0MjlaMBoxGDAWBgNVBAMTD1Rlc3RDZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKoHhZk4TDwumRR3zJmL398aCwwgKC2PJOxhR9WKf0DxAwnFLKMtAnX3SOBh5evzH98J7Bpd3yPmwxCafjM3tp6N3V7CBK0mWkIRSUIXLi0+K+DyH2cXnPqSt71TVik9xGIIyjrKMDUrD70BvHwqR0IRTvLHfUSSjbosbprRYLjj+1eFRRapMWSi1HRZqvIvp1qtqKdMawp01qUIuARYCbHsCKmrlMCSd+CrvaiioZJcpBJqkNtqwaOgmzyE3iG6fpR04g+m+xE/ZATHaTyqc25HDu0bes/NrU62s0oFbPreWv4nKBOHVUGlhBnHTrKPLbB3AAZvtFgSGVt4LOKI7xkCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAfjmzmwf+nXaUjk9YLuxnDKOu5C9N/sQr/F5F1a11D1Ml9K/0q2gv0U4whbT+OB3oTj7RP8ONXTghd9OHiygxYWXe+rEF7xayoAlsC9BAEvl4ZjWxBnUKi8sEnMKhugmptc5ltXk4t1H8Kp+I6gwT85Y1yH99zJbrDvd5BEQRvsNabvnBvjYeIX+tAHiKLJ0fxzf8gM/vhEf1dn+RrXoVL6O2KxJho9S/avnN+lRGyOdWG9ZhVbjZGTTllQwJzycanb+VRFTh0ugidYcFj/MdW9hlOtnyHTFoGStvhfS8FK9x2ZwjBNQd1unRvdh0VHXD2KM5IWuPgyMH2bTuG04dOA==");
}
}
}
```
5) Run app and see 'Microsoft.Bcl.Cryptography' FileNotFound

### Expected behavior

Microsoft.Bcl.Cryptography.dll used in ClassLibrary1 exists in ConsoleApp1's output folder.

### Actual behavior

Microsoft.Bcl.Cryptography.dll is not copied to ConsoleApp1's output folder as the transitive dependency from System.Security.Cryptography.Pkcs does not apply in net10.0

### Regression?

If ConsoleApp1 is net8 or net9 there are no issues.

### Known Workarounds

Add an explicit dependency in either ConsoleApp1 or ClassLibrary1 to Microsoft.Bcl.Cryptography 10.0.2

### Configuration

Net SDK 10.0.105
Windows 11
x64

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.