0
 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...

4

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.