简体   繁体   中英

Could not load file or assembly 'XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies

I have been trying to debug this Error:

System.IO.FileNotFoundException: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

I see a lot of solutions out there and try them all.

I am looking at Fusion Viewer and I am getting the following message:

LOG: This bind starts in default load context. LOG: Using application configuration file: I:\\Projects\\ACE Explorer\\AceV_1Explorer\\AceExplorer\\AceExplorer\\bin\\Debug\\AceExplorer.exe.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\config\\machine.config. LOG: Post-policy reference: ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///I:/Projects/ACE Explorer/AceV_1Explorer/AceExplorer/AceExplorer/bin/Debug/ClassLibrary1.DLL. LOG: Attempting download of new URL file:///I:/Projects/ACE Explorer/AceV_1Explorer/AceExplorer/AceExplorer/bin/Debug/ClassLibrary1/ClassLibrary1.DLL. LOG: Attempting download of new URL file:///I:/Projects/ACE Explorer/AceV_1Explorer/AceExplorer/AceExplorer/bin/Debug/ClassLibrary1.EXE. LOG: Attempting download of new URL file:///I:/Projects/ACE Explorer/AceV_1Explorer/AceExplorer/AceExplorer/bin/Debug/ClassLibrary1/ClassLibrary1.EXE. LOG: All probing URLs attempted and failed.

I see the file in the directory and the Target framework is 4.0 for all using x86

Any ideas of finding out what is broken

Updated Sorry for the confusion. In the log it was PublicKeyToken=null. I was trying everything.

UPDATE I added some code in the main program that will resolve assemblies using the ResolveEventHandler. It didn't work at first. But when I had the program load those external assemblies (LoadReferences()) in the start of the program it do work. Weird since the path was exactly the same when I load them in the beginning LoadReferences() and then when the method enters a reference to a custom assemble which triggers the CurrentDomain_AssemblyResolve. The blank path resolves to the assemblypath. As you can see, in the LoadReferences(), I am adding EntityFramework which will cause the same issue, even though I am using Nuget.

In Main() I added:

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
LoadReferences();



private static void LoadReferences()
        {
            Assembly  objExecutingAssemblies;
            objExecutingAssemblies = Assembly.GetExecutingAssembly();
            AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
            Assembly asm;
            foreach (AssemblyName strAssmbName in arrReferencedAssmbNames)
            {
                if (strAssmbName.FullName.ToLower().Contains("[company].") || strAssmbName.FullName.ToLower().Contains("entityframework"))
                    asm = Assembly.LoadFrom(Path.Combine("", strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(","))+ ".dll"));


            }
            // these were also posing an issue
            asm = Assembly.LoadFrom(Path.Combine("", "EntityFramework.dll"));
            asm = Assembly.LoadFrom(Path.Combine("", "EntityFramework.SqlServer.dll"));


        }
        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            string assembliesDir = "";
            try
            {
                string dll = (args.Name.IndexOf(",") < 0 ? args.Name + ".dll" : args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll");
                Assembly asm = Assembly.LoadFrom(Path.Combine(assembliesDir, dll));
                return asm;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return null;
        }

Also. Not sure if this makes a difference but it is a clickonce with full trust.

Also our desktops are pretty locked down.

Also platform is set to x86 for all projects.

file:///I:/Projects/ACE Explorer/.../bin/Debug/ClassLibrary1.DLL.

This question requires psychic debugging. Fusion is asked to resolve a path on the I: drive. That is often a mapped drive letter to a share on a file server. And often troublesome like this. Given the excessive focus on security, ACE is liable to be the acronym for Access Control Entry . Which makes it likely that the program uses impersonation to "explore" access rights. Which makes it likely that Fusion can't figure out what the I: drive might refer to, drive mappings are a per-user setting.

Works okay early in the program because it still runs with the default user token. And works okay once the program is deployed since it now has a stable location that doesn't depend on a drive letter mapping.

Not sure what to recommend, I am a charter member of the Geneva Convention on Programmer's Rights. Which demands that programmers can create and test programs on their local drive and install the kind of debugging tools they need to find out why their program doesn't work. This is a problem that your IT staff needs to solve. If that gives you control over your dev machine back then you're ahead. A likely outcome given the kind of hits that Google returns for a ".net debug project on mapped drive" query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XX' or one of its dependencies C#: Could not load file or assembly 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' or one of its dependencies Could not load file or assembly 'BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies Could not load file or assembly 'Dapper, Version=1.8.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies Could not load type 'AgencySystem' from assembly 'EPaymentInvoicing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' Could not load file or assembly 'Microsoft.SqlServer.Types, Version=12.0.0.0, Culture=neutral, PublicKeyToken=myKey' or one of its dependencies. Could not load file or assembly 'itextsharp, Version=5.5.0.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=561934e089' or one of its dependencies Could not load file or assembly 'Tools, Version=4.5.0.0, Culture=neutral, PublicKeyToken=f7660c0f5438cda5' or one of its dependencies Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM