Closed qacha closed 1 month ago
AIUI not all C# 9.0 features require .NET 5.0+. PDFsharp/MigraDoc compile against .NET 4.6.2.
You can set the language level to C# 9.0 (or higher) and use compiler features that do not rely on library support.
There is a NuGet package you can use to make this work: https://github.com/manuelroemer/IsExternalInit
Or you can add this code to your project:
#if !NET5_0_OR_GREATER
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit { }
}
#endif
In v6.2.0-preview-1, PdfSharp.Pdf.Signatures.DigitalSignatureOptions is implemented using init-only properties. Trying to use it from a .NET Framework project:
var options = new DigitalSignatureOptions { ContactInfo = "value" };
Results in this error: error CS8370: Feature 'init-only setters' is not available in C# 7.3. Please use language version 9.0 or greater.
... but C# 9.0 requires .NET 5.0+.
It's possible to work around this using reflection:
var options = new DigitalSignatureOptions(); typeof(DigitalSignatureOptions).GetProperty(nameof(DigitalSignatureOptions.ContactInfo)).SetValue(options, "value");
But this clearly not ideal and the init-only properties don't seem to have any significant advantages in this case.