Page 1 of 1

Using Visual Studio to create scripts

Posted: Tue Aug 07, 2018 4:46 pm
by Aracknid
Years ago when I started with Ranorex and Visual Studio, I was advised to create my scripts in VS a certain way. There was information on how to do this on your web site. While reading another thread (viewtopic.php?f=13&t=12425&p=49796#p49796) I noticed they referenced this link (https://www.ranorex.com/help/latest/int ... tegration/) and so I decided to re-visit this topic and was surprised to see how different it is to create a script in Visual Studio. So I'd like to ask some questions with respect to this.

Even though I'm using Ranorex 8.2 (and having issues like mentioned in the first link above), my scripts still look much like the old way you provided as reference. I'm also coding in VB, in case this matters.

1) Does my Main function no longer require the "[STAThread"] at the front, and does leaving it there cause issues?

2) I have not added the references to all the items you mentioned, specifically ALL the plugins (I only added the ones I used) nor the Ranorex.Bootstrapper, Ranorex.Common, and Ranorex.Core.Resolver. I have had issues, which I'll look to fix using the solutions mentioned in the first link, but I was working around it by just copying all the Ranorex Bin folder to script EXE folder.

3) Every time I install a new version of Ranorex, the default folder is a folder with the version number in the path name. This seems to cause issues with references. Do you recommend we remove the version number every time to avoid issues?

Thanks,

Aracknid

Re: Using Visual Studio to create scripts

Posted: Fri Aug 10, 2018 4:56 am
by N612
I followed the user guide to use Ranorex in my VS project. Although the user guide does not say to add the [STAThread] attribute, Ranorex does throw a warning when running your test about it missing. Not having the [STAThread] seemed to never cause any issues for me, but I added it to my Main() method to get rid of the warning and to avoid possible issues down the road.
[2018/08/09 23:47:46.140][Warn ][Automation]: The apartment state of the current thread is not set to STA. Please make sure that all threads accessing Ranorex methods have their apartment state set to STA.

Code: Select all

[STAThread]
static void Main(string[] args)
{
    InitResolver();
    RanorexInit();
    run();
}
Also, I did add all of the mentioned libraries to avoid any issues down the road. I know many have dependencies on each other and I want to avoid any possible issues related to this by just simply adding everything recommended.

Re: Using Visual Studio to create scripts

Posted: Tue Aug 14, 2018 9:15 pm
by Support Team
Hi Aracknid,
  1. The [STAThread] is required and should not be removed from your main method. The user guide does not include it because this is just a snippet, however, I have requested it be added as this can be confusing.
  2. It is a best practice for simplicity and ease to include every plugin, however, if you know what you are doing, you can get away with referencing only what you need.
  3. You can rename the folder, but you will still need to update the libraries since the version number is also referenced in the DLL itself.
    1.png
I hope this helps!

Cheers,
Ned

Re: Using Visual Studio to create scripts

Posted: Wed Sep 12, 2018 7:25 pm
by mpbard
I'm evaluating and am trying to follow the instructions in the link mentioned above, (https://www.ranorex.com/help/latest/int ... tegration/) but nowhere on the machine is the Ranorex.Common dll that is suppoed to be included in step 4. Any idea where to find this?

Re: Using Visual Studio to create scripts

Posted: Fri Sep 14, 2018 6:01 pm
by Support Team
Hi mpbard,

Upon researching your question, I have discovered Ranorex.Common is no longer needed as a reference (as it does not exist anymore). I will inform the documentation team to update this user guide page. I apologize for the confusion this may have caused and thank you for pointing this out!

Cheers,
Ned

Re: Using Visual Studio to create scripts

Posted: Fri Sep 14, 2018 6:04 pm
by mpbard
Yeah, it turns out that Ranorex.Dex.Common is required instead.

Unfortunately the example posted in the original link simply does not work or even compile. Since I don't have the time to diagnose bad documentation I may need to find another solution for my needs. :(