You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 21:05:22