应用程序停止工作获取CLR20r3和System.IO.DirectoryNotFound错误 [英] Application stop working Getting CLR20r3 and System.IO.DirectoryNotFound error

查看:365
本文介绍了应用程序停止工作获取CLR20r3和System.IO.DirectoryNotFound错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试在某些系统中遇到问题其他工作正常

while testing getting problem in some system others working fine

Problem signature:
  Problem Event Name:	CLR20r3
  Problem Signature 01:	xyz.exe
  Problem Signature 02:	1.0.0.0
  Problem Signature 03:	54433673
  Problem Signature 04:	mscorlib
  Problem Signature 05:	4.0.30319.17929
  Problem Signature 06:	4ffa561c
  Problem Signature 07:	43c4
  Problem Signature 08:	105
  Problem Signature 09:	System.IO.DirectoryNotFound
  OS Version:	6.1.7600.2.0.0.256.1
  Locale ID:	1033
  Additional Information 1:	0a9e
  Additional Information 2:	0a9e372d3b4ad19135b953a78882e789
  Additional Information 3:	0a9e
  Additional Information 4:	0a9e372d3b4ad19135b953a78882e789



我尝试Google 问题事件名称:CLR20r3 并找到以下命令,我已在命令提示符中成功执行了admin优先级


I tries to Google Problem Event Name: CLR20r3 and found following commands which i have executed successfully in command prompt with admin priority

regsvr32 atl.dll
cd C:\WINDOWS\eHome
ehSched /unregServer
ehSched /service
ehRecvr /unregServer
ehRecvr /service
ehRec.exe /unregServer
ehRec.exe /regserver
ehmsas.exe /unregServer
ehmsas.exe /regserver



但它没有帮助。然后我尝试搜索 System.IO.DirectoryNotFound Exception 原因,但在我的代码中发现没有任何可疑的目录。



什么可以是这个问题的可能补救措施?我的环境规范是.NET 4.5



- 更新的部分 -



感谢Mehdi Gholam通过将try catch放在main()上来获取跟踪错误的源代码这就是我得到的。


but it didn't help. Then i tried to search System.IO.DirectoryNotFound Exception causes but have found nothing suspicious in my code that have missing directory.

What could be the possible remedy of this problem? my environment specification is .NET 4.5

--Updated part--

Thanks to Mehdi Gholam who become source to trace error by putting Try catch over main() this is what i got.

System.IO.DirectoryNotFoundException: Could not find a part of the path
'C:\Users\hctnba\AppData\Local\abcde\pan.log'.
  at System.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,
Int32 right, Boolean useRight, FileShare share, Int32 bufferSize, FileOptions
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFormProxy,
Boolean useLongPath, Boolean checkHost)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize)
  at System.IO.File.Create(String path)
  at UserSide.App_Code.LogFile.createLogFile()
  at UserSide.App_Code.LogFile.writeLogFile(String lofFileOutput, String status)
  at UserSide.formSplashScreen.ctor()
  at UserSide.Program.Main()



获得此功能后,我尝试手动创建 C:\ Users \hctnba \ AppData \ Local \ abcde \ pan.log 文件,但无效。然后我将文件/文件夹可访问性认证(读/写/执行)全部(读/写/执行)发送到 hctnba (即当前用户)以及每个人 [但是UAC已在系统上禁用]即使这样它也会出现同样的错误为什么只有在这个系统中它不能正常工作,但对其他人来说工作得很好。



系统配置(硬件/软件/操作系统)对每个人都是一样的。



- 代码更新 -



以下是我用来编写日志文件的代码。在上面提到的代码中,我已经通过一些随机名称更改了日志文件的名称,但实际上它是在%LocalAppData%/ getest / 文件夹中创建的,其名称为当前系统日期。




After getting this i tried to create C:\Users\hctnba\AppData\Local\abcde\pan.log file manually it didn't work. then i make file/folder accessibility authentication all(read/write/execute) to hctnba (i.e. current user) and also to everyone [However UAC is already disabled on system] even then it gives same error. why only in this system its not working fine but for others its working nicely.

System configuration (Hardware/Software/OS) are same for everyone.

-- Code Updation --

Following is the code which i am using to write log files. In above mentioned code i have changed the name of log file by some random name but in actual its created in %LocalAppData%/getest/ folder with name of current system date.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace UserSide.App_Code
{
    class LogFile
    {
        public static void writeLog(string logFileOutput, string status)
        {
            createLogFile();
            DateTime currentDateTime = DateTime.Now;
            string logTime = Convert.ToString(currentDateTime);

            using (StreamWriter sw = File.AppendText(@getLogFilePath()))
            {
                sw.WriteLine(logTime + " | " + status + " | " + logFileOutput);
            }
        }

        public static void createLogFile()
        {
            if (!File.Exists(getLogFilePath()))
            {
                File.Create(getLogFilePath()).Dispose();
            }
        }

        public static string getLogFilePath(){

            string logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\gatesv";

                DateTime today = DateTime.Today; // As DateTime
                string logFileName = today.ToString("MM-dd-yyyy"); // As String
                logFileName = logFileName + ".log";

                logFilePath = logFilePath + "\\" + logFileName;

                return logFilePath;
        }
    }
}





----更新的代码工作正常--- -



感谢大家指引正确的方向。这是一个小问题,最后我怀疑的部分是我应该首先检查的实际区域。现在代码正在运行。再次感谢





---- updated code that work fine -----

Thanks everyone to direct in correct direction. this was a minor problem by at the end the very suspected part was actual area that i should check very first. now code is working. Thanks once again

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace UserSide.App_Code
{
    class LogFile
    {
        public static string logDirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\gatesv";
        public static string logFileName = DateTime.Today.ToString("MM-dd-yyyy") + ".log";
        public static string logFilePath = logDirPath + "\\" + logFileName;

        public static void writeLog(string logFileOutput, string status)
        {
            if (!Directory.Exists(logDirPath))
            {
                Directory.CreateDirectory(logDirPath);
            }

            if (!File.Exists(logFilePath))
            {
                File.Create(logFilePath).Dispose();
            }

            string logTime = Convert.ToString(DateTime.Now);

            using (StreamWriter sw = File.AppendText(@logFilePath))
            {
                sw.WriteLine(logTime + " | " + status + " | " + logFileOutput);
            }
        }
    }
}

推荐答案

查看我的答案问题: C#app已安装但未运行 [ ^ ]



在您的情况下,如果您的代码非常大,请按照Mehdi Gholam的建议进行尝试main方法,通常位于Program.cs文件中。



以下示例适用于Windows窗体应用程序。

See my answer for a similar problem: C# app Installed but does not run[^]

In your case, if your code is very large follow the advice from Mehdi Gholam and put a try-catch in the main method, usually located in the file Program.cs.

The example below applies to a Windows Form application.
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        try
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());
        }
        catch (Exception ex)
        {
            // Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
            // returns a folder that is usually allowed to write files to
            string filePath = System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                 "MyApplication_CrashInfo.txt");
            System.IO.File.WriteAllText(filePath, ex.ToString());
        }
    }
}



将MyApplication更改为您的应用程序名称。

使用 Exception.ToString() [ ^ ]你得到的完整的堆栈跟踪,它应该指出代码抛出异常的行。



有关Environment.SpecialFolder枚举 [ ^ ]



当您收到错误消息时,您可以希望缩小到代码失败的位置并解决问题。



[已更新]

确保d你希望在exists中创建文件的irectory,你可以尝试这段代码。


Change MyApplication to your application name.
By using Exception.ToString()[^] you get the full stack trace and it should point out the line where the code throws the exception.

See this link for more info about Environment.SpecialFolder Enumeration[^]

When you get the error message you can then hopefully narrow down to where your code fails and fix the problem.

[Updated]
To make sure the directory you want to create the file in exists, you can try this code.

string dummyPath = @"C:\Temp\Tes\Test\Test.txt";
string dir = System.IO.Path.GetDirectoryName(dummyPath);
if (!System.IO.Directory.Exists(dir))
    System.IO.Directory.CreateDirectory(dir);

System.IO.File.Create(dummyPath);


嗯..我真的认为问题是你所在的目录试图写不存在。尝试在你的getLogFilePath方法中添加它:





Well..i really think the problem is the directory where you are trying to write doesn't exists. Try adding this in your getLogFilePath method:


string logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\gatesv";
if (!Directory.Exists(logFilePath))
{
    Directory.CreateDirectory(logFilePath);
}


这篇关于应用程序停止工作获取CLR20r3和System.IO.DirectoryNotFound错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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