The type 'CodeActivity' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Activities'

im trying to make a simple acivity for UiPath in c# , i had used the System.Activties versoin 4.0.0.0

and inside the nuget pakage explorer i had created net461 and net6.0-windows7.0 folders respectedly also in the depenecy section i had added the target framework as the same as the folder names

i dont know why but when im using the activity in windows compatblity (net.6.0 +) project settings in UiPath im getting this error

Unexpected error has occurred during the library compilation process:
The assembly compilation returned the following errors:
 * (1,7939): error CS0012: The type 'CodeActivity' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
 * (1,7939): error CS0117: 'ConcatString' does not contain a definition for 'DisplayName'
 * (1,7954): error CS0012: The type 'InArgument<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
 * (1,8181): error CS0012: The type 'OutArgument<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
 * (1,8435): error CS0012: The type 'InArgument<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
 * (1,7840): error CS0012: The type 'CodeActivity' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

I dont know what is happening i also had a System.Activties version 6.0.0.0 it works all fine in both windows and windows legacy projects (.net6.0+ and v4.6.1+)

this is the code for the activity

using System.Activities;
using System.ComponentModel;

namespace String_Concatination
{

    public class ConcatString : CodeActivity
    {
        [RequiredArgument]
        [Category("Input")]
        [DisplayName("First String")]
        [Description("Enter First String")]
        public InArgument<string> FirstString { get; set; }

        [RequiredArgument]
        [Category("Input")]
        [DisplayName("Second String")]
        [Description("Enter Second String")]
        public InArgument<string> SecondString { get; set; }

        [Category("Output")]
        [DisplayName("Result")]
        public OutArgument<string> OutputString { get; set; }
        protected override void Execute(CodeActivityContext context)
        {
            var firstString = FirstString.Get(context);
            var secondString = SecondString.Get(context);

            var outString = firstString + secondString;

            OutputString.Set(context,outString);
        }
    }
}

and here is the code of the metadata reference in the NuGet package explorer

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>ConcatString.Activities</id>
    <version>1.0.5</version>
    <title>ConcatString.Activities</title>
    <authors>Sagar Raval</authors>
    <owners>Feat Systems</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>This Activity Helps to Concatinate Two String</description>
    <dependencies>
      <group targetFramework=".NETFramework4.6.1" />
      <group targetFramework="net6.0-windows7.0" />
    </dependencies>
  </metadata>
</package>

im doing a simple string concatenation so i didnt have any dependencies or package , thats the reason in the metadata code you are not able to see any dependencies in there respected target frameworks

Hello @indiedev91

  1. Update your custom activity’s target framework to “.NET Framework 4.6.1” or “.NET Framework 4.8.”
  2. Update the System.Activities reference in your custom activity project to version 6.0.0.0.
  3. Ensure your NuGet package dependencies include both “.NETFramework4.6.1” and “net6.0-windows7.0.”

Thanks & Cheers!!!