Page 1 of 1

.NET 5 CacheHelper BinaryFormatter

Posted: Thu Nov 26, 2020 9:53 pm
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));
        }
    }

Re: .NET 5 CacheHelper BinaryFormatter

Posted: Thu Nov 26, 2020 10:20 pm
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>

Re: .NET 5 CacheHelper BinaryFormatter

Posted: Fri Nov 27, 2020 2:10 pm
by Lech Kulikowski
Hello,

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

Thank you.

Re: .NET 5 CacheHelper BinaryFormatter

Posted: Sun Nov 29, 2020 8:48 pm
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)

Re: .NET 5 CacheHelper BinaryFormatter

Posted: Mon Nov 30, 2020 2:18 pm
by Lech Kulikowski
Hello,

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

Thank you.