Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryFormatter was deprecated/disabled in upcoming .net 5.0 #6805

Closed
fdbeirao opened this issue Oct 27, 2020 · 2 comments
Closed

BinaryFormatter was deprecated/disabled in upcoming .net 5.0 #6805

fdbeirao opened this issue Oct 27, 2020 · 2 comments
Assignees
Labels
stale Issues with no activity for the past 6 months
Milestone

Comments

@fdbeirao
Copy link
Contributor

Hello Orleans team,

I am using Orleans in docker compose. I have an orleans frontend in graphQL in a container/image and my silohost in another container/image.

This is the top of my Dockerfiles, for both frontend and silohost:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src

I have migrated to C# 9 and .net 5.0 earlier this week and things were working fine.

Today I am presented with this exception in my graphQl frontend:

System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at Orleans.Serialization.BinaryFormatterSerializer.Deserialize(Type expectedType, IDeserializationContext context)
   at Orleans.Serialization.BinaryFormatterISerializableSerializer.Deserialize(Type expectedType, IDeserializationContext context)
   at Orleans.Serialization.SerializationManager.DeserializeInner[TContext,TReader](SerializationManager sm, Type expected, TContext context, TReader reader)
   at Orleans.Serialization.BuiltInTypes.DeserializeOrleansResponse(Type expected, IDeserializationContext context)
   at Orleans.Serialization.SerializationManager.DeserializeInner[TContext,TReader](SerializationManager sm, Type expected, TContext context, TReader reader)
   at Orleans.Runtime.Messaging.MessageSerializer.OrleansSerializer`1.Deserialize(ReadOnlySequence`1 input, T& value)
   at Orleans.Runtime.Messaging.MessageSerializer.TryRead(ReadOnlySequence`1& input, Message& message)
   at Orleans.Runtime.Messaging.Connection.ProcessIncoming()
   at Orleans.Internal.OrleansTaskExtentions.<ToTypedTask>g__ConvertAsync|4_0[T](Task`1 asyncTask)
   at GraffQL.Schemas.BackOfficeMutation.<>c__DisplayClass19_0.<<Snipped>b__0>d.MoveNext() in Snipped\GraffQL\Schemas\BackOfficeMutation.cs:line 239
--- End of stack trace from previous location ---
   at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node) in C:\projects\graphql-dotnet\src\GraphQL\Execution\ExecutionStrategy.cs:line 181

My Orleans version is 3.3.0.

I have tried setting up Orleans.Serialization.ProtobufSerializer but the issue remains the same.

For now I will try to address this issue with the solution mentioned in the URL from the exception: adding the EnableUnsafeBinaryFormatterSerialization=true flag to the csproj. Hopefully that will allow me to keep using .net 5.0 (and specially c# 9).

I couldn't find mentions of BinaryFormatter here on Orleans issues, so I would like to know if I am doing anything wrong, or if this is indeed something that the awesome Orleans team needs to pick up.

Cheers and thank you for making Orleans a reality 🙏🏻

@ReubenBond ReubenBond self-assigned this Oct 27, 2020
@ReubenBond ReubenBond added this to the Triage milestone Oct 27, 2020
@ReubenBond
Copy link
Member

Hi @fdbeirao, we will need to come up with a longer-term solution for the eventual demise of BinaryFormatter. At the moment, it is largely used as a fallback serializer, especially for serializing exceptions.

In your case, it appears that you are trying to send a type which is not marked as [Serializable] - is that correct? If so, please add the attribute to all types in your project which you need to transmit between grains. Doing so should instruct Orleans to generate serializers for those types, and BinaryFormatter can be avoided.

@fdbeirao
Copy link
Contributor Author

fdbeirao commented Oct 28, 2020

Hello @ReubenBond . I think you've hit the nail right in the head. The issue is indeed with exceptions. I can see that the payload does make it from graphql (frontend) into the Grain itself, but inside the grain I throw an exception. And that's where all hell breaks loose.

For now, it is okay for me to just add this snipped to both my csproj (frontend and silohost), while I wait for a more long term solution from Orleans itself:

<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <!-- Warning: setting the below switch is *NOT* recommended in web apps -->
    <!-- See: https://aka.ms/binaryformatter -->
    <!-- See: https://github.com/dotnet/orleans/issues/6805 -->
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

Regarding the [Serializable], it was indeed marked. Also, I am starting to use c# 9 records and those also seem to be working fine:

[Serializable]
public record ExecutionParameters
{
    public uint InvoiceMonth { get; init; }
    public uint InvoiceYear { get; init; }
}

Thank you for your quick and helpful answer 🙏🏻

(EDIT by @ReubenBond: I changed the TargetFramework property from netcoreapp5.0 to net5.0)

@ghost ghost locked as resolved and limited conversation to collaborators Sep 25, 2021
@ghost ghost added the stale Issues with no activity for the past 6 months label Dec 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stale Issues with no activity for the past 6 months
Projects
None yet
Development

No branches or pull requests

2 participants