Skip to content
Menu

Articles

Create Custom Actions in Power Automate Desktop - Advanced Tutorial

Here’s how to create Custom C# actions in Power Automate Desktop.

Anders Jensen Automation & AI Instructor

C# Code to Check if a Date is a Bank Holiday

Copy the code to Visual Studio.

namespace Modules.DanishBankHolidays
{
    [Action(Id = "IsBankHoliday")]  // All classes representing actions must have an Action attribute specified above
    public class IsDanishBankHoliday : ActionBase // Likewise, all classes representing actions must be public and inherit from the ActionBase class
    {
        // Input and output parameters for our action are specified as classic C# properties. However, they must have an attribute above that indicates whether they are input or output parameters
        [InputArgument]
        public DateTime DateToCheck { get; set; }

        [OutputArgument]
        public bool IsBankHoliday { get; set; }

        public override void Execute(ActionContext context) // In this method, we will write the actual code we want to execute. It should be defined this way
        {

            // I've cheated a bit from home and have made the code to calculate Easter Sunday in advance - and yes, you're right. I asked ChatGPT to write the code for me.
            int a = DateToCheck.Year % 19;
            int b = DateToCheck.Year / 100;
            int c = DateToCheck.Year % 100;
            int d = (int)(b / 4);
            int e = b % 4;
            int f = (int)((b + 8) / 25);
            int g = (int)((b - f + 1) / 3);
            int h = (19 * a + b - d - g + 15) % 30;
            int i = (int)(c / 4);
            int k = c % 4;
            int l = (32 + 2 * e + 2 * i - h - k) % 7;
            int m = (int)((a + 11 * h + 22 * l) / 451);
            int month = (int)((h + l - 7 * m + 114) / 31);
            int day = ((h + l - 7 * m + 114) % 31 + 1);
            DateTime easter = new DateTime(DateToCheck.Year, month, day);

            // Now we can check if the given day is a public holiday. I've cheated a bit again and defined the list of holidays from home
            if (DateToCheck.Day == 01 && DateToCheck.Month == 01   // New Year's Day
                || DateToCheck.Day == 24 && DateToCheck.Month == 12   // Christmas Eve
                || DateToCheck.Day == 25 && DateToCheck.Month == 12   // Christmas Day
                || DateToCheck.Day == 26 && DateToCheck.Month == 12   // Boxing Day
                || DateToCheck.Day == 31 && DateToCheck.Month == 12   // New Year's Eve
                || DateToCheck == easter                       // Easter Sunday
                || DateToCheck == easter.AddDays(-3)           // Maundy Thursday
                || DateToCheck == easter.AddDays(-2)           // Good Friday
                || DateToCheck == easter.AddDays(+1)           // Easter Monday
                || DateToCheck == easter.AddDays(+39)          // Ascension Day
                || DateToCheck == easter.AddDays(+40)          // Bank holiday after Ascension Day
                || DateToCheck == easter.AddDays(+49)          // Pentecost
                || DateToCheck == easter.AddDays(+50)          // Whit Monday
                || DateToCheck.Day == 05 && DateToCheck.Month == 06 // Constitution Day
                )
            {
                IsBankHoliday = true;
            } else
            {
                IsBankHoliday = false;
            }
        }
    }
}

Resources Needed

Download the resources needed to create a certificate and compress the DLL-files: Download

Comments (8)

  1. Mikkel Pedersen

    Thank you!

    1. Anders Jensen Author

      🙌

  2. Rabie BOULAL

    Hello Andres, I'm encountering an issue when adding the action in PAD. Despite following the instructions to the letter, I'm facing this problem that's stopping me from proceeding. Do you have any idea what might be the solution? No custom actions group was found. Please check the naming and development conventions are followed correctly and try again.

    1. Anders Jensen Author

      Hey Rabbie, thanks for the the feedback 🙂 Did you sign the DLLs, cab compress the release, and sign the cap compress? Are you in the same environment as you published to? Kind regards, Anders

  3. Arun

    Hi Anders, this was so helpful building my first custom action, however, though I followed the same exact steps, I have been consistently getting the error - "failed to initialize module loader" while I try to add the custom action in the Power Automate Desktop project flow. Any thoughts or suggestions to help fix this error will be greatly helpful. Thanks in advance.

    1. Anders Jensen Author

      Thanks for writing 😊 I'm getting more than 50 messages daily. While I read all of them, I can’t reply to everyone 😔 But I’ve created an RPA/Automation community where we’re 14,000+ RPA Developers helping each other with solutions and our careers. It’s free, and you can find it here: https://discord.gg/iloveautomation Kind regards, Anders

  4. Grizz

    Hi Anders, If I update my custom action code after publishing the CAB file. Do I need to re-sign all of the DLL files again before publishing the new CAB file?

    1. Anders Jensen Author

      Yes 😊🙌 Kind regards, Anders

Write a comment

Your name and comment are shown publicly once approved. Your email is not shown. Read more in the privacy policy. Once approved, the comment may be machine-translated for the other language version. The original is always available.

More articles

  • Build Your First Agent in the New Copilot Studio

    Step by step: Build an HR agent in the new Copilot Studio with instructions, knowledge and a skill, test it in Preview, and publish it to Teams. With video.

    Read more →
  • Copilot Studio Pricing 2026: Credits Explained + Calculator

    See what your Copilot Studio agents cost per month. Free credit calculator (estimator) with correct license math, capacity packs, and the new GitHub Copilot harness.

    Read more →
  • The New Copilot Studio Explained (GitHub Copilot Harness)

    Copilot Studio has a new default experience on the GitHub Copilot harness. See what changed, what a harness is, and the three things to know before you build.

    Read more →