Hi everyone This C# code how write in vb.net?


Welcome to our UiPath community.

Replace Square brackets with round brackets.

Replacing the square brackets is too vague, and still won’t generate valid VB.NET code.

You should not do this in an Invoke Code activity as it is not neccessary, use a normal assign that looks something like this (aircode so untested).

AttachmentData = DirectCast(dtRow("Data"), Byte())

DirectCast is one of the ways you can cast to a specific data type in VB.Net.

There are C# to VB.NET code converter you can use, e.g. https://converter.telerik.com

Otherwise, if you are using Invoke Code, you can just use the C# code directly. Invoke Code has an option where you can select the language:


HI @Mehmet_Basci,

When creating a new process you can choose between VB.NET and C#. That way all Not directly an answer to your question, but for your information :slight_smile:


So this is some potentially misleading advice. CType is VB.net is not the same as casting in C# and the differences in behaviour can cause issues.
For example in C# you cannot do (Int)"1" as thats a conversion from a string to an integer, CType in VB.net can do that however.
DirectCast is stricter (and actually stricter than casting in C#) and only allows a cast if the object is already of that type or inherits that type.
That can be an extremely important difference and a big reason to not just blindly use a converter to convert C# code.

Furthermore, I’d like to re-iterate. Invoke code is totally not needed here. It seems like a C# developer, who didn’t want to spend 2 minutes googling how to cast in VB.net brute forced an Invoke Code solution.

This is a really simple assign activity. Invoke code should be avoided.