“Google.Apis.Json.NewtonsoftJsonSerializer”的类型初始值设置程序抛出异常 [英] The type initializer for 'Google.Apis.Json.NewtonsoftJsonSerializer' threw an exception
本文介绍了“Google.Apis.Json.NewtonsoftJsonSerializer”的类型初始值设置程序抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Oauth访问Google Analytics(分析)数据2.当我尝试执行以下代码时,会出现此错误:
I am accessing google analytics data using Oauth 2. When I try to execute the following code, this error occurs:
初始化
'Google.Apis.Json.NewtonsoftJsonSerializer'
抛出异常。
The type initializer for
'Google.Apis.Json.NewtonsoftJsonSerializer'
threw an exception.
这里是我的代码:
string clientid = "my client id";
string clientsecret = "my client secret";
var client = new WebServerClient(GoogleAuthenticationServer.Description, clientid, clientsecret);
var auth = new OAuth2Authenticator<WebServerClient>(client, Authenticate);
var asv = new Google.Apis.Analytics.v3.AnalyticsService(new BaseClientService.Initializer()
{
Authenticator = auth,
});
var request = asv.Data.Ga.Get("ga:" + "my ProfileID", "2012-01-01", "2012-02-20", "ga:visits");
var report = request.Fetch();
private IAuthorizationState Authenticate(WebServerClient client)
{
IAuthorizationState state = new AuthorizationState(new string[] {}) { RefreshToken = "my refresh token" };
client.RefreshToken(state);
return state;
}
推荐答案
使用Newtonsoft.Json
是旧版本。然后我导入了新版本的 Newtonsoft.Json
(Version = 4.0.2.0)
。现在它的工作...........
The namespace which i was importing using Newtonsoft.Json
was the older version. Then i imported the new version of Newtonsoft.Json
(Version=4.0.2.0)
. Now its working ...........
这篇关于“Google.Apis.Json.NewtonsoftJsonSerializer”的类型初始值设置程序抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文