Unable to compile C# code: No Compiled Code to Run

I am trying to use an Invoke Code task to execute C# code but I’m having an issue as I get an error stating that there is no compiled code to run. Any ideas on how I can get this code to compile in UiPath Studio? I’m not sure what is missing/incorrect.

Below is the code, the goal of which is to split a large file into smaller file by row count. All of the arguments needed are correctly passed to it via the Argument panel.

String inputfile = inputFileName;
String outpath = outputPath;
int linesPerFile = numberOfLinesPerFile;

Try
{

Using (StreamReader sr = New StreamReader(inputfile))
{
    int fileNumber = 0;

    While (!sr.EndOfStream)
    {
        int count = 0;

        Using (StreamWriter sw = New StreamWriter(outpath + "_" + ++fileNumber + ".txt"))
        {
            sw.AutoFlush = True;

            While (!sr.EndOfStream && ++count < linesPerFile)
            {
                sw.WriteLine(sr.ReadLine());
            }
        }
    }
}

}
Catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}

Hi @jennifer.cannon

Try this C# Code:

string inputfile = inputFileName;
string outpath = outputPath;
int linesPerFile = numberOfLinesPerFile;

try
{
    using (StreamReader sr = new StreamReader(inputfile))
    {
        int fileNumber = 0;

        while (!sr.EndOfStream)
        {
            int count = 0;

            using (StreamWriter sw = new StreamWriter(outpath + "_" + ++fileNumber + ".txt"))
            {
                sw.AutoFlush = true;

                while (!sr.EndOfStream && ++count <= linesPerFile)
                {
                    sw.WriteLine(sr.ReadLine());
                }
            }
        }
    }
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}

Invoke Code Arguments:

Variables:

Note: Make sure to keep Language as C#

Regards

That worked! Thanks!!

1 Like

Perfect, so the topic can be closed @jennifer.cannon

Please mark my post as solution to close the loop.

Regards

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