2014-07-13 81 views
1

我试图使用简单的C#控制台应用程序访问Google API服务(在这种情况下为Plus服务)。每次我调用API函数,我遇到一个很奇怪的例外:Google Plus API C# - AccessViolationException

类型的未处理的异常“System.AccessViolationException” 发生在未知模块。

附加信息:试图读取或写入受保护的内存。 这通常表示其他内存已损坏。

这时候,我发现了API端点这样的例子发生了:

Client.People.Get("me").Execute(); 

这儿还有没有人之前有这个问题吗?

编辑:

我已经下载了GPlus样品,并仍然得到同样的问题,但现在里面:

Oauth2Service.TokeninfoRequest request = service.Tokeninfo(); 

我认为这里的常见的情况是有关生成的代码类:

  1. https://code.google.com/p/google-api-dotnet-client/source/browse/20120425-1.1.4497-beta/Generated/Source/Google.Apis.Oauth2.v2.cs?repo=contrib&name=20120503-1.2.4506-beta

  2. https://code.google.com/p/google-api-dotnet-client/source/browse/Current/Generated/Source/Google.Apis.Plus.v1.cs?repo=contrib&r=c757b64c06e143c8b28bda15b4ec7e6a2738d2e5

编辑2:

我附加堆栈跟踪:

在Google.Apis.Plus.v1.PeopleResource.GetRequest.set_UserId(字符串值) 位于c:\ code.google.com \ google-api-dotnet-client \ default_gen \ Tools \ Google.Apis中的Google.Apis.Plus.v1.PeopleResource.GetRequest..ctor(IClientService服务,字符串userId)。 NuGet.Publisher \模板\卜ild \ Google.Apis.Plus.v1.cs:line 2661 at Google.Apis.Plus.v1.PeopleResource.Get(String userId)in c:\ code.google.com \ google-api-dotnet-client \ default_gen \ Tools \ Google.Apis.NuGet.Publisher \ Template \ Build \ Google.Apis.Plus.v1.cs:line 2649 at Core.External.GoogleService.GooglePlusApplicationClient.Test()in e:\ Copy \ Feedly \ Backend \ Core.External.GooglePlus \ GooglePlusApplicationClient.cs:线34 在FeedlyTest.Program.Main(字串[] args)在E:\项目\资讯提供ly \后端\测试\ Program.cs的:线88

编辑3:

当我使用Ctrl + F5组合时,它正在工作。 我读过该组合禁用调试器。首先想到,也许在调试器模式下,系统运行在32位(然后无法访问位于32位边界之外的内存)。 我试图将调试平台更改为64位,但它没有帮助。

+0

您使用的是哪个版本的库?最新版本的核心库为1.8.2,G + API为1.8.1。*。你附加的文件是旧的。 – peleyal

+0

我正在使用NUGET的最新版本(1.8.1),只是附加相关类(这是我通过谷歌搜索得到的)... 也有YouTube API的相同问题 – weizenberg

+0

你在Visual Studio 2012或更高版本? – class

回答

0

在项目属性 - >构建 - >平台目标: 尝试从“任何CPU”更改为“x86”或改为尝试打开“首选32位”。

+0

已经尝试过。不工作... – weizenberg

0

你使用了什么样的样品? Google+ Quickstart sample是最新的。此外,您可能会发现OAuth 2 flows in .NET上的这篇博文很有用。

请注意,Google+示例目前在Xamarin以及Visual Studio中工作,因此您可以尝试使用免费提供的IDE来确定它是否是您的环境。

请确保在使用快速入门时您将要使用http://server:port/signin.ashx - 在某些配置中,网络应用将默认使用其他路由。

你也可以发布更多关于你正在使用的代码的信息吗?例如,下面的代码显示了您的tokeninfo通话更完整上面的例子:

Oauth2Service service = new Oauth2Service(
    new Google.Apis.Services.BaseClientService.Initializer()); 
Oauth2Service.TokeninfoRequest request = service.Tokeninfo(); 
request.AccessToken = token.AccessToken; 

Tokeninfo info = request.Execute(); 

我在GitHub上创建了一个非常简单的Google .NET Client API demo,你可以克隆:

git clone https://github.com/gguuss/google-dotnet-demo 

当您打开项目在Visual Studio中,恢复NuGet包,构建项目,然后输入访问令牌。如果一切正常,演示将显示一些TokenInfo数据。

我添加了另一个显示授权的演示。当我这样做,我与Visual Studio 2013测试,我不得不以下添加为安装后的步...

copy /Y "$(SolutionDir)packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll" "$(TargetDir)Microsoft.Threading.Tasks.Extensions.Desktop.dll" 

... as described in this Stack Overflow question

+0

我使用的样本从这里: https://github.com/googleplus/gplus-quickstart-csharp/ 同样的问题仍然存在,在Youtube API太... 我敢肯定问题来源不在我的代码中,也许在我的环境中。 – weizenberg

+0

添加更多的分辨率选项。 – class

+0

谢谢,但我使用了样本和博客文章中的两个代码。两者都有相同的错误。我正在使用VS2013,我还有什么可以尝试的? – weizenberg