(AppDomain)domain).GetAssemblies() will throw exception "file not found"
-
Wednesday, June 29, 2011 7:40 AMJust as the codes below showed. The only thing I can tell it throw the exception on the appdomain which loads an assembly dynamically. can it be the root cause?I found in the GetAssemblies(), it tries to reload the assembly. I don't know why it has to reload. OK. maybe it is across app domain. so it has to create a new one. but it creates the new one only by assembly name, while this assembly is not registered in gac or other folder, then it fails. so tricky....
IntPtr enumHandle = IntPtr.Zero;CorRuntimeHost host = new CorRuntimeHost();try{host.EnumDomains(out enumHandle);object domain = null;while (true){host.NextDomain(enumHandle, out domain);if (domain == null)break;//this line will cause the exceptionAssembly[] assemblies = ((AppDomain)domain).GetAssemblies();}}catch (Exception ex){Console.WriteLine(ex.ToString());}finally{host.CloseEnum(enumHandle);int rel = Marshal.ReleaseComObject(host);}
Reed- Changed Type CaddreModerator Saturday, July 02, 2011 9:42 PM Low level issue
All Replies
-
Friday, July 01, 2011 4:25 AM
I run the code without any exceptions.
Are you sure the exception is thrown by the code line?
Hard hard work, Day day up! -
Tuesday, February 21, 2012 8:13 PMEver get this figured out? I'm running into the same same odd FileLoadException exception right now, only I'm not switching domains, I'm just calling AppDomain.CurrentDomain.GetAssemblies() and it's throwing FileLoadException in certain circumstances that I haven't quite nailed down yet.
-
Thursday, February 23, 2012 11:10 AM
Which assembly it is not able find? Change your catch block as below to know the missing file,
catch (FileNotFoundException ex) { Console.WriteLine(ex.FileName); Console.WriteLine(ex.ToString()); }After that you can check whether the file is present at the probing location or not.
Please mark this post as answer if it solved your problem. Happy Programming!
- Edited by AdaveshMVP Thursday, February 23, 2012 11:11 AM
-
Thursday, February 23, 2012 9:30 PMIn my case it was a 3rd party assembly that is referenced in one of the many assemblies in the project. The file is there and access is allowed, but this one time it failed with a FileLoadException stating that access was denied. The several times it was used before that worked just fine, and another load of our app less than 30 seconds later worked as well, without any changes in between. Was never able to repro, so for now we're just writing it off as some fluke timing issue between attempting to load an assembly indirectly when the OS had it locked somehow (due to search index or virus scan). Definitely be continuing to watch for it but I doubt it will happen again.

