Click here to Skip to main content
15,845,936 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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

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

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()

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.

C#
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

C#
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);
            }
        }
    }
}
Posted
Updated 28-Oct-14 1:15am
v6
Comments
Mehdi Gholam 28-Oct-14 2:36am    
If you have the source code run your program on that machine and see where your error is.
Hitesh Rohilla 28-Oct-14 2:38am    
No its not development machine its user machine. In some machines its working fine without any problem in others its getting mentioned problem.
Mehdi Gholam 28-Oct-14 2:43am    
Add logging and exception handling to your code and see the stack trace for that machine.
Hitesh Rohilla 28-Oct-14 2:46am    
Its too large source. I have no idea where is the expected error where i should put exception handling. have found online that many people have got similar problem and many suggestions are there to resolve them. none work for me :/
Mehdi Gholam 28-Oct-14 2:51am    
Find the main() and put try...catch in it and save the exception to a file.

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.
C#
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());
        }
    }
}

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.
C#
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);
 
Share this answer
 
v3
Comments
Hitesh Rohilla 28-Oct-14 4:30am    
Thanks George but hint by Mehdi Gholam work fine for me and i already did this now have exceptional message which is telling where the problem exists. the message and what i have tried yet is updated in question. please have a look
George Jonsson 28-Oct-14 4:35am    
Can you update your question with a code segment that generates the error?
Hitesh Rohilla 28-Oct-14 4:51am    
Question updated on demand
George Jonsson 28-Oct-14 5:01am    
See my updated answer.
Hitesh Rohilla 28-Oct-14 5:09am    
I guess this precaution i have already used in createLogFile() function
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:


C#
string logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\gatesv";
if (!Directory.Exists(logFilePath))
{
    Directory.CreateDirectory(logFilePath);
}
 
Share this answer
 
Comments
Hitesh Rohilla 28-Oct-14 5:14am    
I tried to create directory and file manually even then application responds with similar exception error log
Pikoh 28-Oct-14 5:19am    
Well, i'll try what i've told you. If it doesn't work, the only thing i can think of is a permissions issue. Try to change path to "C:\" and see if it works there.
Pikoh 28-Oct-14 5:21am    
And anyway, you should add this code to ensure that the path is created before creating the log file. If you run your code in any system for the first time, it's not going to work unless you manually create that directory.
Hitesh Rohilla 28-Oct-14 5:29am    
the requirement of application do not permitting me to use system root (i.e. "C:\") as path. I have changed the permissions of required directories / child directories and required file[s] and provided full access to current user account as well as everyone. UAC is also disabled. I also want to point out that i have asked user to re-install windows. he has done this two times even then its happening on same system.
Pikoh 28-Oct-14 5:35am    
Did you tried adding the code George Jonsson and i suggested? If not, I really can't help you,sorry.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900