Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,i am new to this technology please help me.in my mvc project,i am developing a web API projects when i run the program i am getting this error
C#
An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code

Additional information: The device is not ready.



here error comes

C#
public SafeDirectoryCatalog(string directory)
      {
          var files = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);//ERROR HERE

          this.catalog = new AggregateCatalog();

          foreach (var file in files)
          {
              try
              {
                  var asmCat = new AssemblyCatalog(file);

                  ////Force MEF to load the plugin and figure out if there are any exports
                  // good assemblies will not throw the RTLE exception and can be added to the catalog
                  if (asmCat.Parts.ToList().Count > 0)
                  {
                      this.catalog.Catalogs.Add(asmCat);
                  }
              }







C#
Source Error: 


Line 32:         public SafeDirectoryCatalog(string directory)
Line 33:         {
Line 34:             var files = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);
Line 35: 
Line 36:             this.catalog = new AggregateCatalog();

Source File: C:\ProjectVI\Code\BA\ProjectVI.Api\Install\SafeDirectoryCatalog.cs    Line: 34 

Stack Trace: 


[IOException: The device is not ready.
]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +11185413
   System.IO.FileSystemEnumerableIterator`1.CommonInit() +241
   System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost) +445
   System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption) +96
   ProjectVI.Api.Install.SafeDirectoryCatalog..ctor(String directory) in C:\ProjectVI\Code\BA\ProjectVI.Api\Install\SafeDirectoryCatalog.cs:34
   ProjectVI.Api.Install.MefConfig.Register() in C:\ProjectVI\Code\BA\ProjectVI.Api\Install\MefConfig.cs:28
   ProjectVI.Api.WebApiApplication.Application_Start() in C:\ProjectVI\Code\BA\ProjectVI.Api\Global.asax.cs:30

[HttpException (0x80004005): The device is not ready.
]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9916673
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): The device is not ready.
]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Posted
Updated 18-Sep-19 22:30pm
v2
Comments
phil.o 17-Dec-15 4:04am    
What is the value of the directory parameter when exception is thrown?
[no name] 17-Dec-15 4:07am    
D:\NGN\MVC\Dev Code\libs\api-getting this text
phil.o 17-Dec-15 4:11am    
And where does this value come from? Is this path a valid one on the machine this code is executing?
[no name] 17-Dec-15 4:14am    
i didnt get u.pls chek my updated question..how can i find the value of the directory parameter when exception is thrown
phil.o 17-Dec-15 4:59am    
"The device is not ready" means the path in the directory variable is not reachable on the machine the code is executing on.
In clear text, the "D:\NGN\MVC\Dev Code\libs\api" path is not a valid path on the server on which the assembly is run. It may be a valid path on your local/development machine, but it's not a valid path on the server.

1 solution

Here exceptions occur when,

* The specified path/searchoption is not a valid one.

* You are trying to access an unmapped network location.

* You do not have the persmission.

I have taken a sample from the microsoft website. Just insert the following code into your function.


C#
string sourceDirectory = @"C:\current"; // Replace this path with your local folder path.
            
string archiveDirectory = @"C:\archive"; // Replace this path with your local folder path.

           
            try
            {
                var txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt", SearchOption.AllDirectories);

                foreach (string currentFile in txtFiles)
                {
                    string fileName = currentFile.Substring(sourceDirectory.Length + 1);
                    Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


Now debug your application and see what happens. If it runs correctly, then just re-check your old argument directory and give a valid path; then you are good to go.

In case if you catch an error in these blocks, have a debug point inside the catch block and see what type of exception is thrown.
<br />
Path Invalid -> ArgumentException / ArgumentNullException /                                 DirectoryNotFoundException / IOException /  PathTooLongException


Access Denied -> SecurityException / UnauthorizedAccessException

SearchOption Invalid -> ArgumentOutOfRangeException


Please check and correct your inputs based on the types exception thrown. I hope you can modify your code based on these information and make it work seamlessly.
Please get back if you need any more help with the issue.
 
Share this answer
 
v4
Comments
[no name] 17-Dec-15 6:57am    
its cleared but now i am getting An exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in ProjectVI.Api.dll but was not handled in user code

Additional information: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.


how can i fix this?

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