Forum Discussion

mgy333's avatar
mgy333
Contributor
15 years ago
Solved

dotNET.System_Windows_Forms.Clipboard.GetDataObject() in TestComplete 7.51

I use dotNET.System_Windows_Forms.Clipboard.GetDataObject() to check if the clipboard has any data on it.



The code is similar to:



function ClipboardIsAvailable()

{

        var oDataObject = dotNET.System_Windows_Forms.Clipboard.GetDataObject();

        

        return oDataObject.GetDataPresent("string");

}



This worked great while I was using TestComplete 6.52.



However, when I converted the script to TestComplete 7.51, dotNET.System_Windows_Forms.Clipboard.GetDataObject() always returns null.



Is there additional setting I need to do under TestComplete 7.5 that I didn't have to do on 6.52?  Is this a bug?



System.Windows.Forms, version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is listed under CLR bridge of the project.  The application that's being tested is a .NET software, and it's the same software I was testing under TestComplete 6.52.  In fact, I can still run the same script in TestComplete 6.52, and it finds the value.



Thanks.

  • Hi Motoo,





    Let me quote the Clipboard.GetDataObject Method MSDN article:



    The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.




    So, to avoid the problem, you need to set the Preferred apartment model of the calling thread CLR Bridge option to Single-threaded apartment. See the Project Properties - CLR Bridge Options help topic for details.





    I hope this helps.

5 Replies


  • Hi Motoo,





    Let me quote the Clipboard.GetDataObject Method MSDN article:



    The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.




    So, to avoid the problem, you need to set the Preferred apartment model of the calling thread CLR Bridge option to Single-threaded apartment. See the Project Properties - CLR Bridge Options help topic for details.





    I hope this helps.
  • Hi Motoo,




    Thank you for reporting the problem. We have reproduced it, and currently we are investigating it. We will let you know our results as soon as we have some.

  • Hi David,



    Thank you for prompt reply.  I look forward to the resolution of this issue, as this is one of the reason we are having trouble fully migrating to TestComplete 7.5.



    Motoo
  • By the way, can we get some idea of when this bug may be fixed?



    This is one of the biggest reason that we are not fully able to convert to 7.5 from 6.5.  If the fix will not be available soon, we'll have to think of the way around it.



    Thanks,

    Motoo
  • Thanks.  That seemed to have solved the issue.  Now I can see the clipboard data as I did in the previous version of TestComplete.



    Motoo