Clipboard does copy/paste objects when complied with .Net8
Steps to Reproduce
Create a new Avalonia project.
Set the targets to: net7.0
Create a model that includes the [Serializable] attribute. For example:
[Serializable]
public class MyTestModel
{
public int Id { get; set; }
public string? Name { get; set; }
public MyTestModel()
{
}
}
Update the MainView to create the model and copy then paste the model to and from the clipboard like so:
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
Loaded += MainView_Loaded;
}
private void MainView_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
TestAsync().GetAwaiter().GetResult();
}
private async Task TestAsync()
{
var m = new MyTestModel()
{
Id = 1,
Name = "Test",
};
var dataObject = new DataObject();
dataObject.Set("my-app-person", m);
var clipboard = TopLevel.GetTopLevel(this)!.Clipboard!;
await clipboard.SetDataObjectAsync(dataObject);
var r = await clipboard.GetDataAsync("my-app-person");
Debug.WriteLine(r);
}
}
Run the program. Notice the variable "r" is returned as expected.
Modify both Avalonia projects to target to net8.0
Run the program. Notice the variable "r" is null.
Describe the bug
Clipboard does copy/paste objects when complied with .Net8
Steps to Reproduce
Create a new Avalonia project. Set the targets to:net7.0
Create a model that includes the [Serializable] attribute. For example:
Update the MainView to create the model and copy then paste the model to and from the clipboard like so:
Run the program. Notice the variable "r" is returned as expected. Modify both Avalonia projects to target tonet8.0
Run the program. Notice the variable "r" is null.