Coder Social home page Coder Social logo

System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. about reportviewercore HOT 12 CLOSED

lkosson avatar lkosson commented on August 17, 2024
System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application.

from reportviewercore.

Comments (12)

lkosson avatar lkosson commented on August 17, 2024 1

Indeed in RSParams control (and some other in WinForms project) there are some indirect references to BinaryFormatter which I have missed.

from reportviewercore.

lkosson avatar lkosson commented on August 17, 2024

BinaryFormatter is indeed disabled by default in AspNetCore 5.0. As a workaround, please add <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization> to your csproj while I explore whether it is possible to replace ResX binary formatted resources with something else.

from reportviewercore.

lkosson avatar lkosson commented on August 17, 2024

I have decided to remove those resources altogether. No need for EnableUnsafeBinaryFormatterSerialization workaround - updated NuGet package coming in a minute.

from reportviewercore.

g136660 avatar g136660 commented on August 17, 2024

Hi, PDF working in last release on Linux?

from reportviewercore.

lkosson avatar lkosson commented on August 17, 2024

Hello. No, on Linux only available exporters are HTML4.0, HTML5, EXCELOPENXML and WORDOPENXML.

from reportviewercore.

tarockx avatar tarockx commented on August 17, 2024

Was this problem actually fixed? I see this issue is closed, but I'm experiencing this with the latest version (15.1.17).

Fortunately the workaround works so it's not really a problem, but I'm confused on whether I'm missing something since the issue is marked as closed...

from reportviewercore.

lkosson avatar lkosson commented on August 17, 2024

It should work without a workaround. If you still get System.NotSupportedException mentioning BinaryFormatter, please post a full stack trace here.

from reportviewercore.

tarockx avatar tarockx commented on August 17, 2024

Thanks for your quick reply, here's the stack trace:

System.NotSupportedException
  HResult=0x80131515
  Message=BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
  Source=System.Runtime.Serialization.Formatters
  StackTrace:
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at System.Resources.Extensions.DeserializingResourceReader.ReadBinaryFormattedObject()
   at System.Resources.Extensions.DeserializingResourceReader.DeserializeObject(Int32 typeIndex)
   at System.Resources.Extensions.DeserializingResourceReader._LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.Extensions.DeserializingResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.Extensions.DeserializingResourceReader.ResourceEnumerator.get_Entry()
   at System.Resources.Extensions.DeserializingResourceReader.ResourceEnumerator.get_Current()
   at System.ComponentModel.ComponentResourceManager.FillResources(CultureInfo culture, ResourceSet& resourceSet)
   at System.ComponentModel.ComponentResourceManager.FillResources(CultureInfo culture, ResourceSet& resourceSet)
   at System.ComponentModel.ComponentResourceManager.FillResources(CultureInfo culture, ResourceSet& resourceSet)
   at System.ComponentModel.ComponentResourceManager.ApplyResources(Object value, String objectName, CultureInfo culture)
   at Microsoft.Reporting.WinForms.RSParams.InitializeComponent()
   at Microsoft.Reporting.WinForms.RSParams..ctor()
   at Microsoft.Reporting.WinForms.ReportViewer.InitializeComponent()
   at Microsoft.Reporting.WinForms.ReportViewer..ctor()

It happens when I do new ReportViewer() (running on .NET 6)

from reportviewercore.

jkrebsbach avatar jkrebsbach commented on August 17, 2024

I can confirm the fix is working - and am currently running 15.1.16 on .net 6.
But I do not instantiate a ReportViewer, but a LocalReport object from the Microsoft.Reporting.NETCore namespace...

from reportviewercore.

lkosson avatar lkosson commented on August 17, 2024

@tarockx Can you reproduce the behavior using ReportViewerCore.Sample.WinForms project from this repo? When I switched it to .NET 6, the component initializes correctly without the workaround.

from reportviewercore.

tarockx avatar tarockx commented on August 17, 2024

@tarockx Can you reproduce the behavior using ReportViewerCore.Sample.WinForms project from this repo? When I switched it to .NET 6, the component initializes correctly without the workaround.

Sorry for the late reply.
I can confirm that @jkrebsbach is correct, if I don't use the ReportViewer but use LocalReport instead I don't have the issue, so I removed the WinForms assembly entirely and only use the LocalReport instead. Thanks for your support.

from reportviewercore.

schtritoff avatar schtritoff commented on August 17, 2024

@tarockx Can you reproduce the behavior using ReportViewerCore.Sample.WinForms project from this repo? When I switched it to .NET 6, the component initializes correctly without the workaround.

Hi @lkosson! In my app when targeting net8.0-windows (.NET 8) it throws BinaryFormatter exception on instantiation (in constructor) - new Microsoft.Reporting.WinForms.ReportViewer(). None of the workarrounds work. When I switch back to net7.0-windows ReportViewer works fine. Do you know what could be the cause? Compile time is OK but instantiation fails ...

EDIT 2
The issue can be reproduced in sample WinForms project - it throws System.NotSupportedException: 'BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.' exception on this line https://github.com/lkosson/reportviewercore/blob/9f0a88b2064c5789f1d52665fa768294c717dc83/Microsoft.ReportViewer.WinForms/Microsoft.Reporting.WinForms/RSParams.cs#L201C10-L201C10 on runtime

EDIT 3
After further debugging it was only needed to add following line to project file:
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
And then it worked - the runtime allows access to BinaryFormatter. This seems to only be workarround for .NET 8 and in .NET 9 it will be completely removed...

from reportviewercore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.