question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler warning and runtime exception on UWP Release

See original GitHub issue

The library works fine on Debug UWP builds but gives the compiler warnings for each of the unsupported windows p/invoke calls when built in Release. For example:

MCG : warning MCG0007: Unresolved P/Invoke method 'user32.dll!CloseClipboard' for method 'System.Boolean WindowsClipboard.CloseClipboard()'.
 Calling this method would throw exception at runtime.
 Please make sure the P/Invoke either points to a Windows API allowed in UWP applications, or a native DLL that is part of the package. 
If for some reason your P/Invoke does not satisfy those requirements, please use [DllImport(ExactSpelling=true) to indicate that you understand the implications of using non-UWP APIs		

At runtime the promised exception is thrown when trying to cut, copy or paste.

This is using a UWP with a minimum target version of 10.0.16299. I don’t see the clipboard windows calls listed in the available APIs: https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-and-com-for-uwp-apps

I will attempt a fix for my own app that uses the UWP Clipboard https://docs.microsoft.com/en-us/windows/uwp/app-to-app/copy-and-paste

If that works I’ll make a PR for this library.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SimonCroppcommented, Dec 9, 2019

can u submit a failing PR with that code?

0reactions
HaikuJockcommented, Nov 30, 2019

I think there’s definitely something weird with my setup which I’m going to look into further.

I tried copying your test code by getting and setting on a thread and it worked fine.

I then tried repeatedly firing the get and set on new threads:

        public MainPage()
        {
            InitializeComponent();
            var thread1 = new Thread(TestClipboard);
            thread1.Start();
        }

        void TestClipboard()
        {
            var random = new Random();
            while (true)
            {
                var thread = new Thread(OutputClipboardText);
                thread.Start();
                Thread.Sleep(random.Next(1, 100) * 10);
            }
        }

        async void OutputClipboardText()
        {
            await TextCopy.Clipboard.SetText("AAA");
            var text = await TextCopy.Clipboard.GetText();
            Debug.WriteLine("Clipboard");
            if (text == null)
            {
                Debug.WriteLine("NULL");
            }
            else
            {
                Debug.WriteLine(text);
            }
        }

I found two things from this:

  1. Sometimes the result of GetText was null
  2. An unhandled exception was occasionally thrown with error code CLIPBRD_E_CANT_OPEN. I vaguely seeing code where you handled this for the .NET framework version. https://stackoverflow.com/questions/68666/clipbrd-e-cant-open-error-when-setting-the-clipboard-from-net
Read more comments on GitHub >

github_iconTop Results From Across the Web

UWP-APP Application Error on Release Build
I figured out, how to perform a Build with the Compile with .NET Native tool chain option enabled. However, I receive only the...
Read more >
Compiling UWP C# app in Release mode fails due to ...
I have a solution that has a Windows Runtime Component (C++/WinRT) and a C# app that consumes that component.
Read more >
Trying out v5. UWP App does not build in Release mode. ...
Describe the bug I was able to get my app updated to v5 and works in Debug mode, but now that I'm trying...
Read more >
[UWP] Bug report: .Net Native compiler crashing
I am unable to compile UWP application in Release configuration when the following two lines added to the project: public struct TestStruct ...
Read more >
Runtime error in release mode while preparing build for ...
as per the MD guidlines I enabled the "Compile with .net native tool chain" option but I am getting error1. Error 1:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found