args.Name For some reason it contains = "Project_file_backup.resources, Version = 1.0.0.0, Culture = ru-RU, PublicKeyToken = null"

And always: return null:

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { if (args.Name.StartsWith("7z")) { return Assembly.Load(Project1.Properties.Resources._7z); } else return null; } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; var a = Assembly.Load(Project1.Properties.Resources._7z); SevenZipCompressor.SetLibraryPath(Path.Combine("", a.FullName)); 

{"Could not load file or assembly \" 1073664 bytes loaded from Project_file_backup, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null \ "or one of their dependencies. An attempt was made to load a program that has the wrong format."}

System.BadImageFormatException is not processed. FileName = 1073664 bytes loaded from Project_file_backup, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null FusionLog = "" = 1.0.0.0, Culture = neutral, PublicKeyToken = null "or one of their dependencies. An attempt was made to download a program that has the wrong format.
Source = mscorlib StackTrace: in System.Reflection.RuntimeAssembly.nLoadImage (Byte [] rawAssembly, Byte [] rawSymbolStore, Evidence evidence, StackCrawlMark & ​​stackMark, Boolean fIntrospection, SecurityContextSource securityContextSource, in the system, in the same file, and in the same file, in the same way, in the same way, in the same way, the system will be used by the system, Boolean fIntrospection, SecurityContextSource securityContextSource, in the SystemCleanfile, SecurityContextSource, SecurityContextSource) in MyProcess.FileBackup.AddToArchive2 (String [] fileNames, String archiveName) ... in System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.Threading.ExtECTEnthereEnactEnthereEnline_EnthereEnline_EnthereEnline_EnthereEnlineEnthereEnthereEbjectEntritEntrToArchive2 , ContextCallback callback, Object state) in System.Threading.ThreadHelper.ThreadStart () InnerException: HResult = -2147024885 Message = Incorrect IL format. InnerException:

enter image description here

enter image description here

Option2

 public static void Load(string name) { String resourceName = "app1." + new AssemblyName(name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); Assembly.Load(assemblyData); } } 

...

  Load(@"Resources\7z.dll"); //var currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //SevenZipCompressor.SetLibraryPath(Path.Combine(currentDir, @"Resources\7z.dll")); SevenZipCompressor.SetLibraryPath(Path.Combine(currentDir, ???Что здесь писать?)); //???Что здесь писать 

I look like they do here:

http://www.sql.ru/forum/868852/kak-sdelat-takoy-appdomain-currentdomain-assemblyresolve

https://blogs.msdn.microsoft.com/microsoft_press/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition/#comments

http://www.cyberforum.ru/attachments/433016d1410669282

  • Well, that is, you can, if you load it through some Assembly.Load(byte[]) , but it is quite difficult. And why do you need it, if not a secret? - VladD
  • so that libraries do not install into the system. When using the adjacent lying Resources \ 7z.dll for some launches through another exe or shortcut or from another user, it does not find Resources \ 7z. 2) Use one file more convenient. - codename0082016
  • one
    And why in Resources, and not directly in the same directory? - VladD
  • one
    It is normal that in the code 7z , and not 7z. ? - int3
  • one
    The problem is most likely not in embedding, but in specifying the path of SevenZipCompressor.SetLibraryPath ... I remember your previous question - there was no time to look. With this biblical did not work - without this method can not do? - Ev_Hyper

0