AccessViolationException goes away when native code debugging is enabled

不羁的心 提交于 2019-12-12 12:09:44

问题


I get an AccessViolationException when I run the Google Drive API sample in Visual Studio 2012 on Windows 7 x64. My project is targeting .Net 4.5. I get the exception on line 185:

await service.Files.Delete(file.Id).ExecuteAsync();
  • It happens in both Debug and Release modes, and in all platforms (x86, x64, AnyCPU).
  • It does NOT happen when I run without the debugger attached ("Start without Debugging").
  • It does NOT happen when I enable the "Enable native code debugging" in the Project properties.

Any ideas why enabling native code debugging might prevent the exception?

Note: running the sample requires the NuGet package (prerelease): Google.Apis.Drive.v2


EDIT: I wish Google people would chime in and tell if they've seen this as well because the sample instructions say:

  • Open the GoogleApisSamples.sln with Visual Studio
  • Click on Build > Rebuild Solution
  • Execute the .exe in Drive.Sample\bin\Debug

which is weird since they go out of their way to execute the exe directly from the debug folder instead of just saying "Run the sample".


回答1:


It is just a shot in the dark, but I had a similar issue which turned out to be caused by the visual studio hosting process.
you can disable it and see if anything has changed.

You can do it from Project properties > Debug > uncheck the Enable the visual studio hosting service




回答2:


I also had this problem although with a completely different project. for me the initial problem was that the wrapper library was a .net 2 assembly and my application was a .net 4 app. When i changed the wrapper to .net 4 i started getting stackunbalancedExceptions instead.

This turned out to because the callingconvention (and perhaps the charset) property for the DllImports was not set correctly. Once i fixed this i no longer get any exceptions in .net 4, however i still get them when compiling the wrapper library as .net 2.

There might be a compat settings that can make it work with mixed 2/4 framework, but since i was able to recompile i haven't really checked.



来源:https://stackoverflow.com/questions/20019808/accessviolationexception-goes-away-when-native-code-debugging-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!