webclient-AccessViolationException [英] webclient - AccessViolationException

查看:72
本文介绍了webclient-AccessViolationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去6个月中,以下使用webclient的代码正常工作.几周前,MS Windows Update开始运行,并在Windows 7 OS上安装了许多更新 .NET Framework的安全更新,用于Office Runtime Redistributable x64的MS VS 2010工具以及其他更新.这些更新(约3打)具有成功的状态.

During the past 6 months the following code using webclient worked. A few weeks ago MS Windows Update kicked in and installed a number of updates to my Windows 7 OS along with security updates for .NET Framework, for MS VS 2010 Tools for Office Runtime Redistributable x64, and others. These updates (around 3 dozen of them) have a status as successful.

WebClient myWebClient = WebClient ();

WebClient myWebClient = new WebClient();

string     uriString   = <我的专有网址"> ;

string    uriString   = "<my proprietary web address>";

myWebClient.Headers.Add(内容类型" "application/x-www-form-urlencoded" );

myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

string postData = " post_cmd = delete_game& game_id =" + game_id.ToString();

string postData   = "post_cmd=delete_game&game_id=" + game_id.ToString();

byte [] postArray   = 编码 .ASCII.GetBytes(postData);

byte[] postArray  = Encoding.ASCII.GetBytes(postData);

         

             

byte [] responseArray = myWebClient.UploadData(uriString,postArray);

string 响应 = 编码 .ASCII.GetString(responseArray);

string response      = Encoding.ASCII.GetString(responseArray);

不幸的是,当我运行任何包含WebClient的代码时,现在会得到一个"; AccessViolationException-尝试读取或写入受保护的内存".请记住,WebClient 通话实际上有效.但是,一旦通话结束,就好像它以某种方式损坏了与之相关的对话框的内部记忆,就像白蚁大军可能会损坏房屋的基础一样,房屋看起来确实 很好,然后突然坍塌成一堆木屑.在您尝试对其进行处理之前,我的对话框看起来还不错,然后它会生成此"AccessViolationException"错误.

Unfortunately when I run any of my code that includes WebClient, I now get an "AccessViolationException - Attempted to read or write protected memory". Keep in mind that the WebClient call actually works. However, once the call completes then it appears that it has somehow damaged the internal memory of the dialog that it is associated with much like an army of termites might damage the foundation of your house - the house looks really nice and then suddenly it collapses into a pile of sawdust. My dialog looks okay until you try to do something with it, and then it generates this "AccessViolationException" error.

为解决此问题,我尝试了以下方法:

1.在另一台计算机上运行我的程序(使用WebClient类),它的工作原理像一个魅力.没问题.因此,似乎有 我的品牌在新计算机上出现问题.

1. Ran my program - that uses the WebClient class - on another computer and it worked like a charm. No problemos. Thus it appears to be that there is something wrong with my brand spanking new computer.

2.在MSDN论坛上查询解决方案,未找到任何解决方案.

3.使用Google查询互联网作为解决方案,但没有找到任何解决方案.

4.重新安装了MS Visual Studio 2010(版本10.0.30319.1 RTMRel).这也包括MS .NET Framework版本4.0.30319 RTMRel.虽然花了几个小时 这样做根本没有帮助.

4. Reinstalled MS Visual Studio 2010 (version 10.0.30319.1 RTMRel). This also includes MS .NET Framework version 4.0.30319 RTMRel. Altho it took hours to do this it didn't help at all.

5.使用系统还原实用程序将我的系统还原到MS Windows升级发生之前的几周.当此回滚没有 帮助我然后撤消它.

5. Used the System Restore utility to restore my system back a few weeks to a point before the MS Windows Upgrade happened. When this rollback did not help I then undid it.

6.确保已安装所有当前MS Windows所需的更新.

7.尝试将WebClient替换为WebRequest,但WebRequest产生了相同的AccessViolation错误.

以下是我的系统信息:

系统类型    基于x64的PC

System Type   x64-based PC

处理器 ;   英特尔®酷睿™i7 CPU       Q 720 @ 1.60GHz,1600 Mhz,4核,8逻辑处理器

Processor     Intel(R) Core(TM) i7 CPU       Q 720  @ 1.60GHz, 1600 Mhz, 4 Core(s), 8 Logical Processor(s)

BIOS版本/日期     Dell Inc. A09,2010年4月26日

BIOS Version/Date    Dell Inc. A09, 4/26/2010

SMBIOS版本       2.6

SMBIOS Version       2.6

Windows目录     C:\ Windows

Windows Directory    C:\Windows

系统目录      C:\ Windows \ system32

System Directory     C:\Windows\system32

启动设备    \ Device \ HarddiskVolume2

Boot Device   \Device\HarddiskVolume2

Locale 美国

Locale United States

硬件抽象层 版本="6.1.7600.16385"

Hardware Abstraction Layer Version = "6.1.7600.16385"

用户名      KirkE-PC \ KirkE

User Name     KirkE-PC\KirkE

时区      中央日光时间

Time Zone     Central Daylight Time

已安装的物理内存(RAM)   6.00 GB

Installed Physical Memory (RAM)   6.00 GB

总物理内存 ;    5.99 GB

Total Physical Memory      5.99 GB

可用的物理内存 ; 3.93 GB

Available Physical Memory  3.93 GB

总虚拟内存 12.0 GB

Total Virtual Memory 12.0 GB

可用的虚拟内存 8.82 GB

Available Virtual Memory   8.82 GB

页面文件空间  ;    5.99 GB

Page File Space      5.99 GB

Page File       C:\ pagefile.sys

Page File     C:\pagefile.sys

  因此,我现在正在寻求您的帮助来解决此问题.希望您会有一些见识,可以帮助我识别然后删除,重新安装或重新配置 冒犯性软件,以便webclient再次表现出来,因为如果不是这种情况,那么我的下一步将是抽掉硬盘驱动器,并与所有其他软件一起重新安装MS Windows 7,这真的很痛苦.我宁愿 有另一个根管帮我M-S-wan kenobe,你是我唯一的希望!

 So, I am now asking for your assistance in solving this problem. Hopefully you will have some insight that will help me identify and then remove, reinstall or reconfigure the offending software so that webclient will behave once more, because if that isn't the case then my next move will be to smoke the hard drive and reinstall MS Windows 7 along with all other software and that will be really painful. I would much rather have another root canal. Help me M-S-wan kenobe, you are my only hope!

谢谢!

柯克

 

  KAE-草原土拨鼠软件有限责任公司

 KAE - Prairie Dog Software, LLC

推荐答案

我想知道是否存在计时问题. .

I wonder if its a timing issue. . .

尝试一下:


public static byte[] DeleteGameById(int id)
{
  WebClient client = new WebClient();
  Uri uri  = new Uri("<my proprietary web address>");
  client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  string postData  = "post_cmd=delete_game&game_id=" + id.ToString();
  byte[] postArray = Encoding.ASCII.GetBytes(postData);
  byte[] result = null;
  AutoResetEvent wait = new AutoResetEvent(false);
  TimeSpan timeout = TimeSpan.FromMinutes(1);
  client.UploadDataCompleted += (UploadDataCompletedEventHandler)
      delegate(object sender, UploadDataCompletedEventArgs e)
      {
        using (var str = new MemoryStream(e.Result))
        {
          using (var rdr = new BinaryReader(str))
          {
            result = rdr.ReadBytes(e.Result.Length);
          }
        }
        wait.Set();
      };
  client.UploadDataAsync(uri, postArray);
  Thread.Sleep(0);
  if(!wait.WaitOne(timeout))
  {
    throw new TimeoutException("Timed out while trying to delete game by Id");
  }
  return result;
}


这篇关于webclient-AccessViolationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆