RegistrationServices.RegisterAssembly error - help!

I have an assembly in a shared folder (only a UNC path, no mapped drive). When I try to register it programmatically through RegistrationServices , I get a strange error.

Here is the code:

 using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; namespace BLRegisterAssembly { public static class BlRegisterAssembly { public static void Register() { var asm = Assembly.LoadFile(@"\\myUNCPath\myAssembly.dll"); var rs = new RegistrationServices(); rs.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase); // I've also tried AssemblyRegistrationFlags.None : same error. } } } 

This is the error I get:

“Failed to load file or assembly” [XXXXXXXXXXXXXX], Version = 1.0.0.0, Culture = Neutral, PublicKeyToken = [xxxxxxxxxxxxxx] 'or one of its dependencies. The system cannot find the specified file. "

(This file is the assembly referenced by the main assembly).

A few more points:
- The referenced assembly is in the same folder as the main assembly that I am trying to register.
- The folder cannot be displayed as a logical drive. Due to access to network folders, users in different groups have different drive mappings with the same network folders, and they cannot be changed in accordance with IT policy ...

Can someone point me in the right direction to solve the problem?

ANSWERED
Since I used Assembly.LoadFile , dependent assemblies must be manually resolved through AssemblyResolve . The following code update fixed my problems:

 public void Register() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); var asm = Assembly.LoadFile(Path.Combine(m_path, assemblyName)); var rs = new RegistrationServices(); rs.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase); } static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { //... code to resolve the path and load the dependent assembly... } 
+4
source share
1 answer

You should not use LoadFile (), use LoadFrom () so that the CLR has a chance to find any dependent assemblies. If you still have problems, use Fuslogvw.exe to get a trace of the attempt to resolve the assembly. The backup plan is designed to implement AppDomain.AssemblyResolve.

+4
source

All Articles