BinaryFormatter serialization and deserialization are disabled within this application

1 Answer 150 Views
.NET Core Report Viewer - HTML5
John
Top achievements
Rank 2
Iron
Iron
Iron
John asked on 27 Oct 2022, 01:07 PM

I have a .NET 6 solution with a reports project that is .NET Framework 4.8 using Telerik Reporting version R1_2022_SP1_16_0_22_225.

On this line of code in the report designer, which is for a picturebox in the report

this.pictureBox1.Value = ((object)(resources.GetObject("pictureBox1.Value")))

it's throwing an exception -> 

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

This url indicates the problem was fixed in the Telerik Reporting R1 2021, but I am getting the exception.

BinaryFormatter serialization and deserialization are disabled within this application is thrown in .NET5 - Telerik Reporting

I've tried the workaround below but that also does not work and I still get the exception.

<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>

 

 

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Ivan Ivanov
Telerik team
answered on 01 Nov 2022, 10:28 AM

Hello John,

Generally, setting the csproj property should do the trick, but as this is a compatibility option Microsoft tend to share only limited information on its actual functionality. My current assumption is that it might be a build related behavior. Still, before delving deeper into debugging it, I would suggest an alternative workaround:

AppContext.SetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", true);

This options sets an applicationwide flag at run-time, which should act similar to the csproj option. If I remember correctly, the method that throws the exception in .NET, actually checks this particular switch just before throwing, so this solution might actually be more explicit and reliable.

Regards,
Ivan Ivanov
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
John
Top achievements
Rank 2
Iron
Iron
Iron
commented on 01 Nov 2022, 12:23 PM

There is nowhere to set that in the report files that I know of since you can't modify the generated .cs code.  I tried using AppContextSwitchOverrides in the app.config file in the report project (.NET Framework 4.8) but it doesn't seem to make a difference as I'm still getting the exception.

I'm not sure how to apply this setting to the web project Program.cs which is probably where it needs to be since that is where I run the reports from.  The web project is .NET 6 and I don't believe .NET Core supports these types of switches.

<configuration>
	<runtime>
		<AppContextSwitchOverrides value="System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true" />
	</runtime>
</configuration>

 

 

Ivan Ivanov
Telerik team
commented on 04 Nov 2022, 10:57 AM

NET 6 supports AppContext.SetSwitch at run time, but I believe that setting them as AppCоntextSwitchOverrides, in configuration file, is only supported in Net Framework. Thus I suggest sticking to the run time approach, by executing the following line in your application code, in the beginning of the application lifecycle:

AppContext.SetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", true);

John
Top achievements
Rank 2
Iron
Iron
Iron
commented on 04 Nov 2022, 03:05 PM

I added that to Program.cs and I'm no longer getting the exception.  Thank you.
Tags
.NET Core Report Viewer - HTML5
Asked by
John
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Ivan Ivanov
Telerik team
Share this question
or