If you created a custom type derived from System.Exception, consider whether you really need it to be serializable. It's likely that you don't need it to be serializable, as exception serialization is primarily intended to support remoting, and support for remoting was dropped in .NET Core 1.0.
BinaryFormatter removed from .NET 9
SYSLIB0051: Legacy serialization support APIs are obsolete