为何C#调用VB.Net DLL时会导致Chr()函数运行异常?
问题背景与复现
- 在VB.Net DLL中写入以下代码:
Dim A As String = Chr(128) - 用VB程序调用该DLL——运行正常
- 用C#程序调用该DLL——抛出错误:
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中Chr()函数接受0到255的参数值,但C#调用时参数值超过127就会触发致命错误。
疑问
- 为何C#会导致VB.Net DLL内的代码运行异常?
- 还有哪些VB函数会受C#调用的影响?
感谢Charlyface提醒补充完整异常信息。此前我只关注了C#中DLL抛出的错误,未留意VB中的情况,该错误为我提供了解决思路...
内容的提问来源于stack exchange,提问作者Gary
相关产品推荐
相关产品推荐

