Coded workflows - namespace created within same library - unable to publish

Hi!

I’m trying to create a library to deserialize a JSON into an object I’ve created a class for.

using System.Collections.Generic;
using UiPath.CodedWorkflows;
using Newtonsoft.Json;

namespace API_Library.RegisterCenter.CodedWorkflows.Vehicles
{

    public class DeserializeResponse : CodedWorkflow
    {
        [Workflow]
        public List<VehicleInfo> Execute(string JSONInput)
        {
     
            return JsonConvert.DeserializeObject<VehicleData>(JSONInput).VehicleInfos;
            
        }
    }
    
    public class VehicleData
    {
        public List<VehicleInfo> VehicleInfos { get; set; }
    }
    public class VehicleInfo
    {
        public string LicenseNumber { get; set; }
        public string Brand { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string UnregisteredDate { get; set; }
    }
}

Everything works fine when debugging, here’s my workflow (I want to use my object later on)

But I’m unable to publish and the workflow analyzer is complaining:

Error Could not load file C:.…\API_Library_RegisterCenter\Vehicles\POST Vehicles.xaml. Reason: Cannot create unknown type ‘{http://schemas.microsoft.com/netfx/2009/xaml/activities}Variable({clr-namespace:System.Collections.Generic;assembly=System.Private.CoreLib}List({clr-namespace:API_Library.RegisterCenter.CodedWorkflows.Vehicles;assembly=API_Library.RegisterCenter.Core}VehicleInfo))’.

Do I need to have my classes in a “namespace” library and import it into this library to make it work, or am I doing something wrong?

1 Like

I believe if you want to add a custom type to your UiPath low-code files you cannot simply create a cs file with the class in the project. You are going to need to make a class library in Visual Studio and install it as a Nuget package.

If you only use the custom class in your coded workflow, I do not believe this is required.

Thanks for replying!

Through some trial and error I managed to get to work by generating a new library with just the two classes as separate Code Source Files ( I could probaly put the actual deserializer there too)

And then importing that Library into my first library


I can now publish it and use it in processes:

The question is if that’s a good way to do it or not.
I’m not sure what UiPath has in mind in terms of best practice around this.
Especially using custom classes.

1 Like

can you check coded workflows vs. coded source files?

and use it within a POCO style for the Un/Marshalling of the JSON. It should work within the same project

Good follow-up. Regarding best practice, I think even the UiPath developers are figuring out what those should be in coded workflows haha.


This is how I do most of my stuff. No need to fiddle around with UiPath libraries or Custom Activities. The code is in a coded source file. Method DoStuff is static so no need to create an instance. But DoMoreStuff is not static so instead I create an instance called UtilsInstance to be able to use DoMoreStuff.

I’m not sure if I follow you.

I’ve rewritten the classes into each of their own Coded Source File:

using System.Collections.Generic;

namespace API_Library.RegisterCenter.CodedWorkflows.DeserializeVehicles
{
    public class VehicleData
    {
        public List<VehicleInfo> VehicleInfos { get; set; }
    }
}
namespace API_Library.RegisterCenter.CodedWorkflows.DeserializeVehicles
{
    public class VehicleInfo
    {
        public string LicenseNumber { get; set; }
        public string Brand { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string UnregisteredDate { get; set; }
    }
}

This is in a coded workflow

using System.Collections.Generic;
using UiPath.CodedWorkflows;
using Newtonsoft.Json;

namespace API_Library.RegisterCenter.CodedWorkflows.DeserializeVehicles
{

    public class DeserializeResponse : CodedWorkflow
    {
        [Workflow]
        public List<VehicleInfo> Execute(string JSONInput)
        {
     
            return JsonConvert.DeserializeObject<VehicleData>(JSONInput).VehicleInfos;
            
        }
    }
    
}

This still yields

Error Could not load file C:.…\API_Library_RegisterCenter\Vehicles\POST Vehicles.xaml. Reason: Cannot create unknown type ‘{http://schemas.microsoft.com/netfx/2009/xaml/activities}Variable({clr-namespace:System.Collections.Generic;assembly=System.Private.CoreLib}List({clr-namespace:API_Library.RegisterCenter.CodedWorkflows.DeserializeVehicles;assembly=API_Library.RegisterCenter.Core}VehicleInfo))’.

But if I create the Coded Source File in a separate library and then import that library it works.

I do not believe this is correct. You dont need a separate library

1 Like

I think the other guy is pointing out you dont need a coded workflow and I agree. Just do that deserialize line in an assign. Making an entire workflow to run one line of code doesnt make sense in my opinion.

@sven.wullum1
just let us know the used Studio Version. Thanks

Of course, I should have posted that right away:

2023.10.6

Thanks!

I think I get it now.
And to get access to the classes they can’t be inside a Coded Source File :slight_smile:

I’ll update tomorrow.

This version is still buggy with coded source files. I’d wager your error was the workflow analyzer throwing false positives and if you built via command line, which can skip the analyzer, it would work. I used to need to do this reguarly.

The classes can be anywhere, as long as the class is ‘public’ you can use it anywhere in your project as long as you have the relevant imported namespaces.

Thanks @ppr and @Jon_Smith

It sure helps looking at a problem with fresh eyes… :slight_smile:

This wording made me believe the Code Source Files could only be “used” within Coded workflows, and not in “regular” workflows.

I’ve put my classes into Code Source Files now, imported the namespace into my “regular” workflow and deserialized directly in an assign.

It works as it should now.

Another error I got while trying to publish threw me off.
I already had a sequence named Vehicles elsewhere in my project, at the root folder

Deleting or renaming the sequence removed the error.

Sometimes its worth dumping out the coded workflow files generated in the .local folder in your project. Sometimes things go wrong there and you get ‘conflicts’.

In my experience this is mostly just the workflow analyzer being wrong as its a super annoying tool that frequently gives false positives, sometimes re-opening studio fixes it, sometimes I’ve had to publish via command line to skip it, and sometimes it gets confused by changes if the .locals isnt cleared out.

I’ve asked many times to UiPath for them to let me totally disable to analyzer, but sadly its still there.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.