ERRMSG: BinaryFormatter serialization and deserialization are disabled within this application


Error:

Some users in .NET 8 with locked down settings are getting the following exception:

BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.

stack trace:
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at Atalasoft.Licensing.AtalaLicenseContext.Deserialize(Stream o, String cryptoKey, AtalaLicenseContext context)
at Atalasoft.Licensing.AtalaLicenseContext.GetSavedLicenseKey(Type type, Assembly resourceAssembly)
at Atalasoft.Licensing.AtalaLicenseProvider.xl2H2YtVq(String , Type , LicenseContext , String& , Boolean& , Boolean& , String& , Boolean , Boolean )
at Atalasoft.Licensing.AtalaLicenseProvider.GetLicense(LicenseContext context, Type type, Object instance, Boolean allowExceptions)
at System.ComponentModel.LicenseManager.ValidateInternalRecursive(LicenseContext context, Type type, Object instance, Boolean allowExceptions, License& license, String& licenseKey)
at System.ComponentModel.LicenseManager.IsValid(Type type, Object instance, License& license)
at Atalasoft.Imaging.AtalaImage.ValidateLicense()
at Atalasoft.Licensing.AtalaLicenseHelpers.SetLicenseShared(Action validationMethod)
at Atalasoft.Imaging.AtalaImage.SetLicense()
at Atalasoft.Imaging.AtalaImage..ctor()
at Atalasoft.Imaging.ImageSource..ctor()
at Atalasoft.Imaging.RandomAccessImageSource..ctor()
at Atalasoft.Imaging.FileSystemImageSource..ctor(String path, String pattern, Boolean doAllFrames)
at Atalasoft.Imaging.FileSystemImageSource..ctor(String path, Boolean doAllFrames)

Fix:

 If your application / environment disables BinaryFormatter for security reasons - it must be enabled or you won't be able to use DotImage

Also please ensure your CSPROJ/VBPROJ have
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>