Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding.GetEncoding("GBK") 在 .net core中报错 #14

Open
pePZqFHzJVofRgEDrn5L opened this issue May 7, 2019 · 3 comments
Open

Encoding.GetEncoding("GBK") 在 .net core中报错 #14

pePZqFHzJVofRgEDrn5L opened this issue May 7, 2019 · 3 comments

Comments

@pePZqFHzJVofRgEDrn5L
Copy link

netstandard2.0版本的sdk中有 Encoding.GetEncoding("GBK")的代码,但.net core项目使用的时候会报错。是否考虑引入System.Text.Encoding.CodePages?

@ForkBug
Copy link

ForkBug commented May 16, 2019

同样的问题,百度的文档示例在netcore上跑不通

Unhandled Exception: System.ArgumentException: 'GBK' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name
at System.Text.EncodingTable.internalGetCodePageFromName(String name)
at System.Text.EncodingTable.GetCodePageFromName(String name)
at Baidu.Aip.Nlp.Nlp.DefaultRequest(String uri)

@pePZqFHzJVofRgEDrn5L
Copy link
Author

恩,虽然在调用sdk的项目中Encoding.RegisterProvider一下也能解决,但是感觉不太友好。

@hoilung
Copy link

hoilung commented Jul 13, 2020

同样的问题,百度的文档示例在netcore上跑不通

Unhandled Exception: System.ArgumentException: 'GBK' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name
at System.Text.EncodingTable.internalGetCodePageFromName(String name)
at System.Text.EncodingTable.GetCodePageFromName(String name)
at Baidu.Aip.Nlp.Nlp.DefaultRequest(String uri)

今天用dotnet core 也发现这个问题了.core里面没有gbk编码,需要单独引用,可以参考下面

1,nuget 安装 System.Text.Encoding.CodePages
2,程序入口main里面注册下
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
3,gbk编码
var text="百度是一家高科技公司";
var input = System.Text.Encoding.GetEncoding("gb2312").GetString(System.Text.Encoding.UTF8.GetBytes(text)); ;
var client = new Baidu.Aip.Nlp.Nlp(API_KEY, SECRET_KEY);
client.SentimentClassify(input)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants