There is a class library whose class is marked as ComVisible. This class uses Oracle.ManagedDataAccess, which in the form of a dll lies next to the dll of my class library.

When using this code

Assembly asm = Assembly.LoadFile(pathToAssembly); RegistrationServices regAsm = new RegistrationServices(); bool bResult = regAsm.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase); 

Get FileNotFoundException

 {"НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ сборку \"Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342\" Π»ΠΈΠ±ΠΎ ΠΎΠ΄Π½Ρƒ ΠΈΠ· ΠΈΡ… зависимостСй. НС удаСтся Π½Π°ΠΉΡ‚ΠΈ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ».":"Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"} 

Fyughen log shows that the assembly is searched in the directory of the caller. How can I indicate that the assembly should be looked for where they opened the assembly for registration? I understand that dependencies are loaded into the context of the caller, by default.

1 answer 1

You can try to determine the full path to the COM component and load Oracle.ManagedDataAccess by this path:

 string currentAssemblyPath = Assembly.GetExecutingAssembly().Location; string currentAssemblyDir = Path.GetDirectoryName(currentAssemblyPath); string pathToAssembly = Path.Combine(currentAssemblyDir, "Oracle.ManagedDataAccess.dll"); Assembly asm = Assembly.LoadFile(pathToAssembly); // ... 

Subject to new information . You will have to manually manage the resolution of assembly dependencies. This is done through the AppDomain.AssemblyResolve event. The event is triggered if the CLR could not automatically resolve the dependencies.

A small example:

 AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { // Π’ вашСм случаС Π² args.Name Π±ΡƒΠ΄Π΅Ρ‚ Π»Π΅ΠΆΠ°Ρ‚ΡŒ строка // Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342 // Π’Π°ΠΊΠΆΠ΅ сюда Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΊΠ°ΠΊΠΈΠΌ-Ρ‚ΠΎ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³, Π³Π΄Π΅ Π»Π΅ΠΆΠΈΡ‚ COM-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ // ΠΈ зависимая сборка (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΡΡ‡ΠΈΡ‚Π°Ρ‚ΡŒ Ρ‡Π΅Ρ€Π΅Π· рССстр: HKEY_CLASSES_ROOT\CLSID\{guid_вашСго_ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°}\InprocServer32) // ΠŸΡƒΡΡ‚ΡŒ comPath - ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³, Π³Π΄Π΅ Π»Π΅ΠΆΠΈΡ‚ ваша зависимая сборка string depAssemblyFileName = new AssemblyName(args.Name).Name + ".dll"; string depAssemblyPath = Path.Combine(comPath, depAssemblyFileName); return Assembly.Load(depAssemblyPath); }; 

The code must be added before your registration code.

  • Maybe I did not write a little bit. My assembly is loaded normally, but when I try to register, I swear at the dependent assembly that the registrar is looking for in the folder of the calling program, and not where my assembly resides. - Lev Limin
  • Thank you very much. The regasm utility code showed the same method. Your advice approved me in the opinion of the correctness of the path. Thank. - Lev Limin