.NET 5 CacheHelper BinaryFormatter

Stimulsoft Reports.WEB discussion
Post Reply
anjung
Posts: 11
Joined: Sun Nov 15, 2020 12:10 pm

.NET 5 CacheHelper BinaryFormatter

Post by anjung »

So after the UTF-7 error is fixed it seems you are using the binaryformatter in
GetCacheDataFromObject and GetObjectFromCacheData
which unfortunatly has also been disabled in .NET 5

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

Code: Select all

   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at Stimulsoft.Report.Web.StiCacheHelper.DataSerializer.Serialize(Object obj)
   at Stimulsoft.Report.Web.StiCacheHelper.GetCacheDataFromObject(Object obj)

Code: Select all

public class StiRedisCache : StiCacheHelper
    {
        private readonly CacheService _cache;

        public StiRedisCache(CacheService cache)
        {
            _cache = cache;
        }

        public override object GetObject(string guid)
        {
            var uid = HttpContext.CoreHttpContext.User.UserId();
            var key = $"stimulsoft.{uid:D}.{guid}";

            var item = _cache.Database.StringGet(key);

            if (item == RedisValue.Null)
                return null;

            return GetObjectFromCacheData(Convert.FromBase64String(item));
        }

        public override void SaveObject(object obj, string guid)
        {
            var uid = HttpContext.CoreHttpContext.User.UserId();
            var key = $"stimulsoft.{uid:D}.{guid}";

            _cache.Database.StringSet(key, 
                Convert.ToBase64String(GetCacheDataFromObject(obj)), 
                TimeSpan.FromMinutes(10));
        }
    }
anjung
Posts: 11
Joined: Sun Nov 15, 2020 12:10 pm

Re: .NET 5 CacheHelper BinaryFormatter

Post by anjung »

"Temporary" workaround - still please consider replacing it - and no json.net cannot replace it wirh your current "object madness" :twisted:

https://github.com/nhibernate/nhibernat ... ssues/2603

Code: Select all

<PropertyGroup>
  <TargetFramework>net5.0</TargetFramework>
  <!-- Warning: Setting the following switch is *NOT* recommended in web apps. -->
  <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: .NET 5 CacheHelper BinaryFormatter

Post by Lech Kulikowski »

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
anjung
Posts: 11
Joined: Sun Nov 15, 2020 12:10 pm

Re: .NET 5 CacheHelper BinaryFormatter

Post by anjung »

Hi,
please do as it seems the EnableUnsafeBinaryFormatterSerialization is not working as it should. (or Binaryformatter is now broken)
There is no longer an exception, but rendering small previews render alot slower and WITHOUT DATA
and larger previews just crash.

this was all working in .NET Core 3.1

for one product wich runs mostly on a single server memorycache works just fine.
Another runs on multiple servers and I do not want to rely on sticky sessions just for stimulsoft when everything else ist stateless/distributed (but may be the only solution for now)
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: .NET 5 CacheHelper BinaryFormatter

Post by Lech Kulikowski »

Hello,

The issue is fixed. The fix will be available in the next release build.

Thank you.
Post Reply