We have some legacy code in a .NET 4.8.1 Library (assumed migrated from VB.6 written decades ago) that is used by our main Application running on 4.8.1 We plan to move this library to .Net Standard 2.0 in order to migrate at some point the whole application to .NET 7/8. When moving parts of the code to .NET Standard we have issues with VisualBasic-specific functions that cause errors like Len, Mid, Val, and Asc although we reference Microsoft.Visual.Basic nuget package (10.3.0)
The same code works when adding it to.NET 7 but this is not an option since it will be shared by both 4.8.1 and 7 apps as we walk parallel in migration
Are we missing something? We don't want to rewrite the existing code since we have enough and not time. Maybe at some point, we will
a small Sample Code
Public Shared Function HexEncode(Text As String) As String
Try
Dim iCount As Double, sTemp As String = "", GData As String = ""
For iCount = 1 To Text.Length
sTemp = Hex$(Asc(Mid$(Text, iCount, 1)))
If Len(sTemp) < 2 Then sTemp = "0" & sTemp
GData &= sTemp
Next
HexEncode = GData
Catch ex As Exception
Return ""
End Try
End Function
any workaround to make it happen in the least amount of time will be excellent !
For starters, don't format it like it's still in VB6. It's been 20 years. :-)
Secondly, the easiest "cross compatible" type I know of is
BitConverter
. I can't confirm with execution that it works in Core 2.0 (earliest I can check easily is 3.1), but the docs say it's there, and it's definitely in Framework 4.8.1So this function will work in both frameworks as written. You'll have to confirm things like the encoding and if the endian-ness of the
Hex$
matchesBitConverter.ToString
, but that's all string manipulation at that point.