# Solace .net libraries possibly using no-longer-supported binaryformatter (also, .net5)

**URL:** <https://community.solace.com/t/solace-net-libraries-possibly-using-no-longer-supported-binaryformatter-also-net5/964>\
**Category:** General Discussions\
**Tags:** c\
**Created:** [September 29, 2021, 3:56am UTC](https://community.solace.com/t/solace-net-libraries-possibly-using-no-longer-supported-binaryformatter-also-net5/964 "2021-09-29T03:56:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![allmhhuran](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/allmhhuran/32/2272_2.png) [@allmhhuran](https://community.solace.com/u/allmhhuran)\
**Post date:** [September 29, 2021, 3:56am UTC](https://community.solace.com/t/solace-net-libraries-possibly-using-no-longer-supported-binaryformatter-also-net5/964/1 "2021-09-29T03:56:24Z")

</div>

In a [question thread](https://community.solace.com/discussion/comment/1660#Comment_1660) created late last year, forum user @Anton was asking about a binary formatter exception in relation to his attempt to use .net5.

I have just run into a similar issue. But interestingly, at around the same time that previous thread was resolved, microsoft issued a notice:

[BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps](https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/binaryformatter-serialization-obsolete)

> Due to security vulnerabilities in BinaryFormatter, the following methods are now obsolete and produce a compile-time warning with ID SYSLIB0011. Additionally, in [ASP.NET](http://ASP.NET) Core 5.0 and later apps, they will throw a NotSupportedException, unless the web app has re-enabled BinaryFormatter functionality. `BinaryFormatter.Serialize``BinaryFormatter.Deserialize`

Additionally, it is now coming up to almost a year since that original thread asked about .net5, and .net6 is coming into view pretty rapidly. The [performance improvements in .net5](https://www.youtube.com/watch?v=Ehvr9wXJNEM) are very significant in many cases.

Can we get .net5 support some time soon? Or at least, remove the `binaryformatter` dependency? I have been developing code using .net5 and it has been working fine via visual studio, but it failed when I attempted to deploy to an azure VM. As it happens I am not writing [ASP.NET](http://ASP.NET), my code is a worker service deployed as a windows service, and I am getting a type initialization exception, not a not supported exception. But I believe this particular component is still the only reason why I can’t use .net5 with the solace .net API, at least when deployed to the VM.

Honestly I’m not sure why it works in visual studio, but the fix seems to be the same in both cases: get .net5 support into solace and nix their BinaryFormatter.

My own code is serializing the message payload using [protobuf.net](http://protobuf.net), which is [much much faster](https://theburningmonk.com/2011/08/performance-test-binaryformatter-vs-protobuf-net/) anyway.

Downgrading to .net 3.1 was painful (since I was using .net5 / c# 9 features), but it did succeed. But I would say it’s “about time” we got up to current state with .net, and the binary formatter obsolescence does seem to force the issue.

---

<div class="post-metadata">

**Author:** ![amackenzie](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/amackenzie/32/1168_2.png) [@amackenzie](https://community.solace.com/u/amackenzie)\
**Post date:** [September 29, 2021, 3:12pm UTC](https://community.solace.com/t/solace-net-libraries-possibly-using-no-longer-supported-binaryformatter-also-net5/964/2 "2021-09-29T15:12:44Z")

</div>

We are going to be delivering .Net 5 support in Dec and it will remove the use of `binaryFormatter`.

In the meantime, you don’t have to downgrade .Net, you could configure the API to allow for its use as per the page you linked above:

> To continue using BinaryFormatter in [ASP.NET](http://ASP.NET) apps, you can re-enable it in the project file. However, it’s strongly recommended not to do this. For more information, see BinaryFormatter security guide.

```auto
<PropertyGroup>
  <TargetFramework>net5.0</TargetFramework>
  <!-- Warning: Setting the following switch is *NOT* recommended in web apps. -->
  <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

```

---

<div class="post-metadata">

**Author:** ![allmhhuran](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/allmhhuran/32/2272_2.png) [@allmhhuran](https://community.solace.com/u/allmhhuran)\
**Post date:** [September 29, 2021, 3:56pm UTC](https://community.solace.com/t/solace-net-libraries-possibly-using-no-longer-supported-binaryformatter-also-net5/964/3 "2021-09-29T15:56:13Z")

</div>

That will eliminate the not supported exception experienced by Anton, but the documentation doesn’t indicate that it would eliminate a type initialization exception. I don’t fully understand _why_ I am getting a type initialization exception rather than a not supported exception, that scenario isn’t mentioned by the documentation. Reading between the lines, the fact that [ASP.NET](http://ASP.NET) is specifically mentioned might be relevant. The whole world seems to to think that the only code is web code, and so everything on the internet is typically phrased in terms of [ASP.NET](http://ASP.NET). But I think, in this particular case, the difference might be important.

Since .net5 is coming to solace soon, the simplest answer seems to be to just hold out until then - which is happily something I can get away with doing.
