Gary
Gary

Reputation: 29

Why does C# change the way a VB.Net DLL works?

 Dim A As String = Chr(128)
  1. Put this line in a VB.Net DLL
  2. Call it from a VB program -->> it works fine.
  3. Call it from a C# program -->> "No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method." err.Number 13

Vb accepts 0 to 255 as acceptable values for Chr() but C# breaks the code with a fatal error if the value is above 127.

Why? Why does C# break the code inside the VB.Net DLL?

What other VB functions are affected by C#?

========== Thanks to Charlyface for asking me to add the full exception message. I had been looking at the error the DLL was raising in C# but not the one in VB. The error has given me an idea for the solution...

Upvotes: 0

Views: 135

Answers (1)

Gary
Gary

Reputation: 29

Solution to problem.

Upgrade project to .NET 6 (https://dotnet.microsoft.com/en-us/platform/upgrade-assistant/tutorial/install-upgrade-assistant)

Add System.Text.Encoding.CodePages NuGet package to solution

Register encoding in startup.

Create a global variable (Encod in the sample) and assign to encoding in startup

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
Encod = Encoding.GetEncoding(1252)

Upvotes: 1

Related Questions