User code referenced as DLL does not show up in recording action

Ask general questions here.
mrt
Posts: 259
Joined: Mon Mar 16, 2020 11:31 am

User code referenced as DLL does not show up in recording action

Post by mrt » Tue May 17, 2022 3:21 pm

Dear all,

I added a separate project to my solution, and compiled it as DLL.

Then I referenced this DLL in the original project, but the User Code methods just do not show up in the recording action "Select from Library".

When I reference the project directly (not the DLL), all User Code methods show up fine.

Can anyone tell me what could be the issue here?

thank you!
br mrt

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: User code referenced as DLL does not show up in recording action

Post by odklizec » Wed May 18, 2022 7:22 am

Hi,

I'm afraid, it's impossible to tell what's wrong, without seeing the method and whole class file.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mrt
Posts: 259
Joined: Mon Mar 16, 2020 11:31 am

Re: User code referenced as DLL does not show up in recording action

Post by mrt » Wed May 18, 2022 8:20 am

Hi, it is a very basic project, folder structure looks like this:
2022-05-18 09_16_32-Window.png

and in UserCodeCollection.cs:

Code: Select all

/*
 * Created by Ranorex
 * 
 * To change this template use Tools > Options > Coding > Edit standard headers.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Microsoft.Win32;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Data;
using Ranorex.Core.Repository;
using Ranorex.Core.Testing;

using OpenQA.Selenium;
// for correct value conversions
using System.Globalization;
// for making life easier
using System.Linq;
// for converting object properties to string array
using System.Reflection;
// for creating temp directory
using System.IO;

// for parsing XMLs
using System.Xml;
using System.Xml.Linq;

namespace Public.UserCode
{
    /// <summary>
    /// Creates a Ranorex user code collection. A collection is used to publish user code methods to the user code library.
    /// </summary>
    [UserCodeCollection]
    public class UserCodeCollection
    {
        // You can use the "Insert New User Code Method" functionality from the context menu,
        // to add a new method with the attribute [UserCodeMethod].
        
        /// <summary>
	/// This method logs the message AND the content of a variable separated by whitespace
	/// </summary>		
	/// <param name="message">The text to display</param>
	/// <param name="variable">The variable to display the content of</param>
	[UserCodeMethod]
	public static void LogVariableAndMessage(string message, string variable)
	{
		Report.Log(ReportLevel.Info, "Data", message + " " + variable);
	}
    }
}
As mentioned, when referenced directly I can select the method from Add action -> User Code -> Select from library.
When referenced as DLL, it does not show up there.

I tried adding a Class library project and a Ranorex module library project, both behave the same.

thanks!
You do not have the required permissions to view the files attached to this post.

mrt
Posts: 259
Joined: Mon Mar 16, 2020 11:31 am

Re: User code referenced as DLL does not show up in recording action

Post by mrt » Wed May 18, 2022 9:00 am

Here is a example solution:
TestSolution.zip

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: User code referenced as DLL does not show up in recording action

Post by odklizec » Wed May 18, 2022 10:24 am

Hi,

There appears to be two problems.

At first, add 'Static' to MyMethod declaration.

At next, it seems that the source MyProvider project must not be in the same test suite? Once removed, it works as expected, both in Recording module or Recording User Code.
MyTest1.zip
BTW, have you tried to compile the original sample test suite? Because it throws an error too (in referenced project).
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration