November Happy Hour will be moved to Thursday December 5th.

[.NET 9] PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed

Vote:
 

Hello Guys,

As you guys aware, .NET 9 has been released yesterday. We tried upgrading our client projects and were able to run without any issues until I was on older version of CMS (12.21.7) and Commerce (14.23.0). As soon as I upgraded to latest version of Episerver packages it throws following error. 

EPiServer.Framework.Initialization.InitializationException
  HResult=0x80131500
  Message=Initialize action failed for Initialize on class EPiServer.Initialization.Internal.ModelSyncInitialization, EPiServer, Version=12.22.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
  Source=EPiServer.Framework
  StackTrace:
   at EPiServer.Framework.Initialization.InitializationEngine.InitializeModules()
   at EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions)
   at EPiServer.Framework.Initialization.InitializationEngine.Initialize()
   at EPiServer.Hosting.Internal.EPiServerFrameworkHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<<StartAsync>b__14_1>d.MoveNext()
   at Microsoft.Extensions.Hosting.Internal.Host.<ForeachService>d__17`1.MoveNext()
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__14.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at Dolby.Web.Website.Program.Main(String[] args) in C:\Data\Projects\**********\Program.cs:line 55

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
#332860
Edited, Nov 13, 2024 21:30
Vote:
 

Update: I restarted the upgrade and followed the sequence below and was able to make it work until I upgraded CMS but as soon as I upgraded Commerce, it started throwing error. So the issue is not with EPiserver Framework version but Commerce version.

  • Upgrade EPiServer Find related packages - No issue
  • Upgrade TinyMce and EPiServer Forms - No issue
  • Upgrade EPiServer ServiceAPI and ImageSharp - No issue
  • Upgrade EPiServer and AspnetCore packages from 12.21.7 to 12.22.0 - No issue
  • Upgrade Commerce.UI+Personalization.Commerce+Tracking.Commerce from 14.23 to 14.28 - No issue
  • Upgrade Commerce 14.28.0 to 14.29.0 = Failed with above error
#332910
Edited, Nov 14, 2024 4:26
Vote:
 

Thanks for the report. We are aware Commerce has an old dependency to BinaryFormatter. We know how to remove the dependency but it is some work, especially doing it without breaking changes. I have brought this up for prioritization again, but for now Commerce can only run on .NET 8.

#332911
Nov 14, 2024 7:36
Vote:
 

Thanks @Magnus. 

After failing to make it work with 14.29.0 I tested following two scenarios. Sharing in case someone else encounters and it may help them.

  • If you upgrade from 14.29.0 to 14.30.0 the solution loads without any error.
  • If you upgrade directly from older version of Commerce to 14.30.0, it fails to load the site with expected BinaryFormatter error. 

Conclusion: We will use .NET 8 for the time being. 

#332917
Edited, Nov 14, 2024 15:27
Vote:
 

I noticed too that I sometimes got an error already in startup, in another project I didn't. But you will get an error as soon as you publish a product update (or price update etc). So it is not currently usable on .NET 9.

#332918
Nov 14, 2024 15:29
Vote:
 

There is an official compatibility package available on NuGet: https://www.nuget.org/packages/System.Runtime.Serialization.Formatters

It enabled us to use CMS 12 with .NET 9. But it's great to hear that Optimizely is working on replacing BinaryFormatter with something modern and more secure!

#332980
Nov 15, 2024 13:06
Sujit Senapati - Nov 15, 2024 14:53
You are right. However, Microsoft recommended against it as BinaryFormatter has serious security risks and it is an unsupported package. If someone is upgrading to .NET 9 and cant wait then it can be beneficial but if you can wait, it is recommended to not use the unsupported package.
Vote:
 

Oh, really? Surprised it works as a drop-in replacement without any changes to our code. Thanks for the tip!

We're going to rip it out anyway I think, it isn't actually needed for anything, it is a legacy to send remote events from the time when there was a separate Content Manager application. We can solve the same thing using regular in-process events now.

#332981
Nov 15, 2024 13:09
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.