Bug in Clipboard.SetContent

2

I'm building a UWP targeting:

Min version: 14393 Target Version: 18362

My Windows version is: 10.0.19041 Build 19041

I have the following codebehind:

using Windows.ApplicationModel.DataTransfer;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace LinkTest
{
    public sealed partial class MainPage : Page
    {
        public MainPage() => this.InitializeComponent();

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dataPackage = new DataPackage();
            dataPackage.SetApplicationLink(new System.Uri("http://www.google.es"));
            Clipboard.SetContent(dataPackage);
        }
    }
}

And the following simple UI:

<Page
    x:Class="LinkTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Button Content="Button" Margin="129,125,0,0" VerticalAlignment="Top" Click="Button_Click"/>
    </Grid>
</Page>

When running this code I receive the following error in Debug or Release:

System.Exception: 'Not enough memory resources are available to process this command. (Exception from HRESULT: 0x80070008)'

in the line: Clipboard.SetContent(dataPackage);

I remember this same code used to work in previous versions of Windows so I think it might be potentially a bug on Windows.

Has anyone come up with the same problem? Thanks!

c#
windows
uwp
asked on Stack Overflow Sep 30, 2020 by Fritjof Berggren • edited Sep 30, 2020 by Fritjof Berggren

1 Answer

3

well one thing that you are missing is setting operation type i.e. dataPackage.RequestedOperation = DataPackageOperation.Copy;

and for copying a string, I used this and it worked fine in copying

private void CopyLink()
{
    DataPackage dataPackage = new DataPackage();
    dataPackage.RequestedOperation = DataPackageOperation.Copy;
    dataPackage.SetText("www.google.com");
    Clipboard.SetContent(dataPackage);
}

you can try operation type Link to set a link I am not sure of it I haven't used it before

answered on Stack Overflow Oct 1, 2020 by Abhishek Sharma • edited Oct 1, 2020 by Abhishek Sharma

User contributions licensed under CC BY-SA 3.0