-
Notifications
You must be signed in to change notification settings - Fork 235
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
FileSessionHandler exception: BinaryFormatter serialization and deserialization are disabled #544
Open
8 of 24 tasks
Comments
As a workaround, a custom ISessionHandler can be implemented using BinaryReader/BinaryWriter: public class CustomFileSessionHandler : ISessionHandler
{
public IInstaApi InstaApi { get; set; }
public string FilePath { get; set; }
private Encoding _encoding = Encoding.UTF8;
public void Load()
{
if (System.IO.File.Exists(FilePath))
{
using (var stream = File.Open(FilePath, FileMode.Open))
{
using (var reader = new BinaryReader(stream, Encoding.UTF8, false))
{
var stateAsBase64String = reader.ReadString();
var stateAsString = _encoding.GetString(Convert.FromBase64String(stateAsBase64String));
InstaApi.LoadStateDataFromString(stateAsString);
}
}
}
}
public void Save()
{
using (var stream = File.Open(FilePath, FileMode.Create))
{
var stateAsString = InstaApi.GetStateDataAsString();
var stateAsBase64String = Convert.ToBase64String(_encoding.GetBytes(stateAsString));
using (var writer = new BinaryWriter(stream, Encoding.UTF8, false))
{
writer.Write(stateAsBase64String);
}
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've:
Issue category
Language
Usage
Operating System
Debug logs
throws following exception
Describe your issue
FileSessionHandler uses BinaryFormatter to laod and save session. As stated in https://aka.ms/binaryformatter
The text was updated successfully, but these errors were encountered: