cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in code stage - unable set binary type in Collection

NaveenRPA
Level 4

Hi,

i am trying to add binary type column in collection but i am getting below error.

Internal : Could not execute code stage: Conversion from type 'Byte()' to type 'String' is not valid.

Below is sample code 

var dt = new DataTable();
dt.Columns.Add("Column1",typeof(Byte[]));
dt.Rows.Add(File.ReadAllBytes(@"C:\Windows\Web\Wallpaper\Windows\img0.jpg"));
outParam=dt;
Screenshot 2024-04-03 160313.pngScreenshot 2024-04-03 160810.png

Screenshot 2024-04-03 160438.png

9 REPLIES 9

NaveenRPA
Level 4

i am using Blueprism trail version 7.2.1.7446 (x64) and .net version is 4.8.9181.0

NaveenRPA
Level 4

when i try to store in Binary data item instead of in Collection it is working fine.

Below are sample screenshots.

Screenshot 2024-04-03 161810.pngScreenshot 2024-04-03 161932.png

faheemsd
MVP

Hi Naveen,

Could you please try this code 

// Create a new DataTable
var dt = new DataTable();

// Add a column to the DataTable
dt.Columns.Add("Column1", typeof(Byte[]));

// Read the bytes from the image file and add them to the DataTable
byte[] imageBytes = File.ReadAllBytes(@"C:\Windows\Web\Wallpaper\Windows\img0.jpg");
dt.Rows.Add(imageBytes);

// Assign the DataTable to the output parameter
outParam = dt;

NaveenRPA
Level 4

@faheemsd - Thanks for reply.

I tried your code but no luck same error only i am getting.

faheemsd
MVP

Hi Naveen,

Could you please try this?


byte[] imageBytes = File.ReadAllBytes(@"C:\Windows\Web\Wallpaper\Windows\img0.jpg");

BinaryDataItem binaryDataItem = new BinaryDataItem(imageBytes);

outParam = binaryDataItem;

NaveenRPA
Level 4

Page: Initialise
Stage: Code2
Type: Error
Action: Validate
Description: Compiler error at line 4: The type or namespace name 'BinaryDataItem' could not be found (are you missing a using directive or an assembly reference?)
Repairable: No

 

ewilson
Staff
Staff

@NaveenRPA 

dt.Rows.Add() is used to add a new DataRow object instance to the dt (DataTable) rows collection. You need to create a DataRow instance first, populate it with your binary data, and then add that instance to the DataTable Rows collection.

Here's one way to do it:

var dt = new DataTable();
dt.Columns.Add("Column1",typeof(Byte[]));
DataRow dr = dt.NewRow();
dr["Column1"] = File.ReadAllBytes(@"C:\Windows\Web\Wallpaper\Windows\img0.jpg");
dt.Rows.Add(dr);
outParam=dt;

Cheers,

Eric

@ewilson - I tried your code but i am getting same error only. same code working in BP version 6.10.5 or lower version. the problem is only with BP version 7.2.1

ewilson
Staff
Staff

@NaveenRPA 

I just tested it in BP v7.3 and it works exactly as shown, assuming your VBO is configured for C# and not VB.NET. Have you recently restarted your BP instance and machine? If not, you might try that.

Cheers,

Eric