Tag: ioexception

如何像HttpWebRequest一样用TcpClient做HTTPS?

我有一个基于TcpClient的通信系统,除了它对特定IP做HTTPS之外,它工作得很好。 然后它开始失败。 通过使用浏览器或HttpWebRequest,我可以毫无问题地为该IP做HTTPS。 我已经创建了一个测试程序来将我的问题缩小到基本的本质,如果你需要,你可以在这里查看它: TestViaTcp 该测试程序完全适用于基本HTTP到同一IP,它总是产生对请求的成功响应。 我把它放在一个循环中,用按键触发它,它将一整天继续成功。 一旦我切换HTTPS,我就会得到一个反复出现的模式。 它会工作,然后就不会,成功之后是失败,然后整天来回成功。 我一直遇到的特殊失败是这样的: {“Authentication failed because the remote party has closed the transport stream.”} [System.IO.IOException]: {“Authentication failed because the remote party has closed the transport stream.”} Data: {System.Collections.ListDictionaryInternal} HelpLink: null InnerException: null Message: “Authentication failed because the remote party has closed the transport stream.” Source: “System” TargetSite: {Void […]

c#exception进程无法访问该文件

我得到一个例外:进程无法访问该文件。 这是代码: if (!Monitor.TryEnter(lockObject)) return; try { watcher.EnableRaisingEvents = false; try { XmlDocument xdoc = new XmlDocument(); xdoc.Load(FileName); xdoc = null; } catch (XmlException xe) { using (StreamWriter w = File.AppendText(FileName)) { Console.WriteLine(xe); w.WriteLine(“”); w.WriteLine(“”); } } System.Threading.Thread.Sleep(2000); XPathDocument myXPathDoc = new XPathDocument(new StreamReader(FileName, System.Text.Encoding.GetEncoding(“windows-1256”))); XslCompiledTransform myXslTrans = new XslCompiledTransform(); myXslTrans.Load(“D:/GS/xsl/test.xsl”); XmlTextWriter myWriter = new […]

如何识别是否打开文件夹?

在我的应用程序中,我正在尝试重命名该文件夹,但如果在Windows资源管理器中打开该文件夹,则会收到IOException 。 如何识别是否在C#中的Windows资源管理器中打开文件夹?

System.IO.IOException:另一个进程使用的文件

我一直在研究这段似乎微不足道的小代码,但我仍然无法确定问题出在哪里。 我的function很简单。 打开文件,复制其内容,替换内部的字符串并将其复制回原始文件(然后在文本文件中进行简单的搜索和替换)。 我真的不知道怎么做,因为我在原始文件中添加了行,所以我只创建了一个文件副本,(file.temp)副本也备份(file.temp)然后删除原始文件(文件)并将file.temp复制到文件。 我在删除文件时遇到exception。 以下是示例代码: private static bool modifyFile(FileInfo file, string extractedMethod, string modifiedMethod) { Boolean result = false; FileStream fs = new FileStream(file.FullName + “.tmp”, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); StreamReader streamreader = file.OpenText(); String originalPath = file.FullName; string input = streamreader.ReadToEnd(); Console.WriteLine(“input : {0}”, input); String tempString = input.Replace(extractedMethod, modifiedMethod); […]

当文件被锁定时,模拟等待文件。在C#中打开

基本上,我和这张海报有同样的问题,但是在C#中: 等待文件可以用Win32读取 更多信息:我们的代码在我们的一个项目中调用File.Open ,当文件已被另一个进程( EDIT:或线程)打开时偶尔会死掉: FileStream stream = File.Open(m_fileName, m_mode, m_access); /* do stream-type-stuff */ stream.Close(); File.Open将抛出一个IOException (当前正在某处悄悄吞下),其HResult属性为0x80070020 ( ERROR_SHARING_VIOLATION )。 我想做的是: FileStream stream = null; while (stream == null) { try { stream = File.Open(m_fileName, m_mode, m_access, FileShare.Read); } catch (IOException e) { const int ERROR_SHARING_VIOLATION = int(0x80070020); if (e.HResult != ERROR_SHARING_VIOLATION) throw; else […]

C#进程无法访问文件”’,因为它正由另一个进程使用

代码片段只是将字符串写入名为“all_results.txt”的文本文件中。 我在File.WriteAllText中实现了错误。 在网上搜索解决方案之后,我尝试使用FileStream和StreamWriter作为替代品。 问题仍然存在。 它给了我: IOException未处理:进程无法访问文件’C:\ Users \ MadDebater \ Desktop \ ConsoleTest1 \ ConsoleTest \ bin \ Debug \ all_results.txt’,因为它正由另一个进程使用。 奇怪的是,错误是随意发生的。 它可能是在第3次循环或第45次循环之前遇到错误。 我提供了该类的完整代码,以防问题比看上去更深。 我确定它与我的病毒扫描程序或其他任何东西无关。 try { using (FileStream stream = new FileStream(@”all_results.txt”, FileMode.Create)) // Exception here { using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine(result); writer.Dispose(); writer.Close(); } stream.Dispose(); stream.Close(); } } catch (IOException […]

使用serialport.open()时IOexception错误

最终更新这是我们固件的全部时间。 在某种程度上令人尴尬,但我很高兴我们可以继续前进,我可以把学习Java关闭一天。 我的答案如下。 更新所以我或多或少地放弃了这一点。 我认为这是一个归结为API的错误,但我没有时间,资源和技能组合来深入了解它。 我认为存在一些Windows只是中指的硬件。 我已经下载了Eclipse,切换到Java并将尝试查看是否有效。 如果没有,你会看到我回到这里。 但是,我绝对喜欢解决这个问题,所以如果有人有时间或倾向深入研究这个问题,我很乐意看到你提出的问题。 显然我会不时回来看看。 请确保你在评论中’@’我,所以我会收到通知。 原始邮政 我知道还有其他一些人在处理这个问题,但我希望有人可以帮助我。 我正在尝试连接到COM端口,但是当我尝试使用serialport.Open()命令时,我收到了IOexception: System.IO.IOException: The parameter is incorrect. at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str) at System.IO.Ports.InternalResources.WinIOError() at System.IO.Ports.SerialStream.InitializeDCB(Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Boolean discardNull) at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean […]

等待文件被进程释放

如何等待文件自由,以便ss.Save()可以用新的覆盖它。 如果我一起运行两次(ish)我得到一个generic GDI+错误。 /// /// Grabs a screen shot of the App and saves it to the C drive in jpg /// private static String GetDesktopImage(DevExpress.XtraEditors.XtraForm whichForm) { Rectangle bounds = whichForm.Bounds; // This solves my problem but creates a clutter issue //var timeStamp = DateTime.Now.ToString(“ddd-MMM-dd-yyyy-hh-mm-ss”); //var fileName = “C:\\HelpMe” + timeStamp + “.jpg”; var […]