Results 1 to 5 of 5

Thread: Cannot find file, even though I already found it.

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Cannot find file, even though I already found it.

    I am getting an error stating the program cannot find the file, even though the file was found using a loop to grab all files in the directory.

    Code:
    vb.net Code:
    1. For Each file In IO.Directory.GetFiles(Application.StartupPath & "\Editors")
    2.  
    3.             pbar.Value += 1
    4.             pbar.Text = "Checking: " & New IO.FileInfo(file).Name
    5.  
    6.             ' Only search files that end in .dll
    7.             If file.EndsWith(".dll") Then
    8.  
    9.                 Try
    10.                     ' Load the assembly.
    11.                     asm = Reflection.Assembly.Load(IO.Path.GetFileNameWithoutExtension(file))
    12.                 Catch ex As Exception
    13.                     Continue For
    14.                 End Try
    15.  
    16. ...

    Exception:
    vb.net Code:
    1. -       ex  {"Could not load file or assembly 'testModule' or one of its dependencies. The system cannot find the file specified.":"testModule"}    System.Exception
    2. -       System.IO.FileNotFoundException {"Could not load file or assembly 'testModule' or one of its dependencies. The system cannot find the file specified.":"testModule"}    System.IO.FileNotFoundException
    3.         _className  "System.IO.FileNotFoundException"   String
    4.         _COMPlusExceptionCode   -532462766  Integer
    5.         _data   Nothing System.Collections.IDictionary
    6.         _dynamicMethods Nothing Object
    7.         _exceptionMethod    Nothing System.Reflection.MethodBase
    8.         _exceptionMethodString  Nothing String
    9.         _fileName   "testModule"    String
    10.         _fusionLog  "=== Pre-bind state information ===  LOG: DisplayName = testModule  (Partial)  WRN: Partial binding information was supplied for an assembly:  WRN: Assembly Name: testModule | Domain ID: 1  WRN: A partial bind occurs when only part of the assembly display name is provided.  WRN: This might result in the binder loading an incorrect assembly.  WRN: It is recommended to provide a fully specified textual identity for the assembly,  WRN: that consists of the simple name, version, culture, and public key token.  WRN: See whitepaper [url]http://go.microsoft.com/fwlink/?LinkId=109270[/url] for more information and common solutions to this issue.  LOG: Appbase = file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/  LOG: Initial PrivatePath = NULL  Calling assembly : NDSMain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.  ===  LOG: This bind starts in default load context.  LOG: Using application configuration file: C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\NDS\__Output\NDSMain.vshost.exe.Config  LOG: Using host configuration file:   LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.  LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule.DLL.  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule/testModule.DLL.  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule.EXE.  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule/testModule.EXE.  "  String
    11.         _helpURL    Nothing String
    12.         _HResult    -2147024894 Integer
    13.         _innerException Nothing System.Exception
    14.         _ipForWatsonBuckets 1820636370  System.UIntPtr
    15.         _maybeFullPath  Nothing String
    16.         _message    "Could not load file or assembly 'testModule' or one of its dependencies. The system cannot find the file specified."   String
    17.         _remoteStackIndex   0   Integer
    18.         _remoteStackTraceString Nothing String
    19. +       _safeSerializationManager   {System.Runtime.Serialization.SafeSerializationManager} System.Runtime.Serialization.SafeSerializationManager
    20.         _source Nothing String
    21. +       _stackTrace {SByte()}   Object
    22.         _stackTraceString   Nothing String
    23.         _watsonBuckets  Nothing Object
    24.         _xcode  -532462766  Integer
    25.         _xptrs  0   System.IntPtr
    26. +       Data    {System.Collections.ListDictionaryInternal} System.Collections.IDictionary
    27.         FileName    "testModule"    String
    28.         FusionLog   "=== Pre-bind state information ===  LOG: DisplayName = testModule  (Partial)  WRN: Partial binding information was supplied for an assembly:  WRN: Assembly Name: testModule | Domain ID: 1  WRN: A partial bind occurs when only part of the assembly display name is provided.  WRN: This might result in the binder loading an incorrect assembly.  WRN: It is recommended to provide a fully specified textual identity for the assembly,  WRN: that consists of the simple name, version, culture, and public key token.  WRN: See whitepaper [url]http://go.microsoft.com/fwlink/?LinkId=109270[/url] for more information and common solutions to this issue.  LOG: Appbase = file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/  LOG: Initial PrivatePath = NULL  Calling assembly : NDSMain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.  ===  LOG: This bind starts in default load context.  LOG: Using application configuration file: C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\NDS\__Output\NDSMain.vshost.exe.Config  LOG: Using host configuration file:   LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.  LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule.DLL.  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule/testModule.DLL.  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule.EXE.  LOG: Attempting download of new URL file:///C:/Users/Troy Lundin/Documents/Visual Studio 2012/Projects/_Emulation/NDS/__Output/testModule/testModule.EXE.  "  String
    29.         HelpLink    Nothing String
    30.         HResult -2147024894 Integer
    31.         InnerException  Nothing System.Exception
    32.         IPForWatsonBuckets  1820636370  System.UIntPtr
    33.         IsTransient False   Boolean
    34.         Message "Could not load file or assembly 'testModule' or one of its dependencies. The system cannot find the file specified."   String
    35.         RemoteStackTrace    Nothing String
    36.         s_EDILock   {Object}    Object
    37.         Source  "mscorlib"  String
    38.         StackTrace  "   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)     at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)     at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)     at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)     at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)     at System.Reflection.Assembly.Load(String assemblyString)     at NDS.Main.LoadModule() in C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\NDS\_NDS\Main.vb:line 182" String
    39. +       TargetSite  {System.Reflection.RuntimeAssembly _nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)} System.Reflection.MethodBase
    40.         WatsonBuckets   Nothing Object

    The exception informs me it cannot load the assembly 'testModule' because it cannot find the file ":"testModule".

    What's with the three quotes and the colon? Why would I get this error even though the assembly was grabbed in the loop?
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Cannot find file, even though I already found it.

    did you write all that?
    My Github - 1d3nt

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Cannot find file, even though I already found it.

    I suggest that you read the documentation for that Assembly.Load method that you're calling. The String you pass should contain the long-form assembly name, NOT a file path.

    http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Cannot find file, even though I already found it.

    John did not mention

    If file.EndsWith(".dll") Then
    My Github - 1d3nt

  5. #5

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: Cannot find file, even though I already found it.

    I understand what you are saying. I am just a bit confused. I have used the same code for over two years now and haven't once gotten an error. In fact, I am able to load two assemblies from the same directory (Editors) prior to the assembly that causes the exception.

    After some fiddling, I was able to load it using the same process, Reflection.Assembly.Load(IO.Path.GetFileNameWithoutExtension(file)), but I changed the directory from 'Application.StartupPath & "\Editors"' to just 'Application.StartupPath'. This made it work, but I am still wondering why it would load two other assemblies from the 'Editors' directory, but not 'testModule'.
    Prefix has no suffix, but suffix has a prefix.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width