Some questions about the loading of COM Tlb file - c#

I have a ASP project, which calls a C++ dll file, we called it A temporary. Then A calls a COM dll using C# coding, there is a function to use API "LoadTypeLib" to load the type library of the COM DLL, using relative path, the com dll is in same level directory of A file, but it failed with error code TYPE_E_CANTLOADLIBRARY?

Make sure the COM dll is registered. If it's not the runtime will not be able to find it to make call to loadlibrary

Related

How can I create a COM DLL from a C# Class Library that functions like a VB6 COM DLL?

I have an old VB6 COM DLL and have rewritten the code in a C# Class Library but need to be able to create a DLL to replace the current one. The DLLs created by building the new project cannot be registered through the command prompt. I tried first (as administrator):
regsvr32 Converter.dll
And it failed with:
The module Converter.dll was loaded but the entry-point DllRegisterServer was not found.
Make sure that "Converter.dll" is a valid DLL or OCX file and then try again.
Then I tried this script:
RegAsm.exe -tlb -codebase Converter.dll
And I got back that RegAsm.exe is not recognized as a command.
The current VB6 DLL is called from XML passed through a remote server application.
Since viewing the post sent to me in a comment, I have ran into another problem when building this DLL, and that is I need to reference Adobe Illustrator but the .aip file I need to reference is invalid when the project is et up for COM. I get back
"Please make sure that the file is accessible, and that it is a valid
assembly or COM component".
One more edit: I upgraded Illustrator to the newest version and that issue was corrected. I grabbed the DLL from the /bin/Release directory and tried regsvr32 but once again received:
The module "Converter.dll" was loaded but the entry point DllRegisterServer was not found.
Make sure that "Converter.dll" is a valid DLL or OCX file and then try again.

How I can reference a not strong typed dll on a class library project that is registered for com interop?

I created a test project from .net as a class library, I checked the register for com interop option and it works from visual foxpro.
then I tried to put a reference to a .net dll that I need on this project, it is not strong typed to put it directly on GAC).
I have comvisible class with a method on the test project that calls a method on the .net referenced dll and when I call this method from visualfoxpro I get the error that
"Could not load file or assembly or one of its dependencies ..."
I tested to have the referenced dll on debug folder (that I compile and then test) and from the client app's folder that I'm testing to consume the com dll in foxpro and in none of them the com dll found the referenced dll.
I have another posible folder to put the dll to be found? some code that I need?
When I recompiled the project, it start to work, seems that for some reason the auto publish to COM registry not occurs automatically.
if someone have this problem,
test to use
regasm nameOfLibrary.dll /tlb:nameOfLibrary.tlb /codebase on the .net dll
it loads on the COM registry the dll without put it on the GAC (some warnings about versions, search for that)...
also another option is to make a "registration free activation" that free of the need of registering the COM with regasm to consume the dll later.

Use C++ dll in C#(WPF)

I had one C++ project written in MFC and some of the project are of DLL type. I wanted to use those dll in my C# code(using DllImport).
I tried to add as a reference but could not able to and getting an error. Do i need to copy those dll's in any of particular location? How my code is going to link those dll's?
You can't add a reference to a native DLL. In DllImport you just import the DLL at runtime so be careful with the path to the DLL if it is not in the same directory as your managed application.
A problem with C++-DLLs is, that the function names in that DLLs can be decorated so you have to find out that decorated name before using it.

Managed C dll calling C# dll, FileNotFoundException

I have an application environment that is essentially a plug in where:
host application calls into unmanaged c++ dll which calls into managed C++ dll which calls into C# dll
This is a fairly known way of calling into C# from unamanaged C++ by using a bridge of managed C++. This all works well and good under most circumstances except in a plug in type architecture where my dlls(unmanaged C++, managed C++ and C#) are not in the same directory as the application calling into the dll. When the application calls into the unmanaged C++ all is well and good because the app knows the directory to call into to load up that dll. However, the first time the unmanaged C++ calls into the managed C++ we get a FileNotFoundException. It turns out that it is not finding the C# dll(noting that all three dlls are in the same directory, just not in the app directory). If I drop all of the dlls into the runtime directory of the exe then everything works perfectly and we don't get the FileNotFoundException. But when I deploy I will have no control over the calling application and thus cannot drop my dlls in the runtime directory.
So, the question is how can I in the unmanaged C++ code programmatically set the load directory for the C# dll when managed C++ dll loads up? I have tried SetDllDirectory and setting the path variable on the system to no success for the directory where my dlls reside.
The CLR looks in only two places by default for an assembly: the GAC first, the directory from which the EXE was started second. Getting it to look elsewhere requires extra work. One possibility is off the table, you cannot subscribe an event handler for AppDomain.AssemblyResolve in this scenario. Which leaves an app.exe.config file with the <probing> or <codebase> elements. You must give it the same name as the unmanaged EXE and store it in the same folder as the EXE.
This tends to be unwise if the EXE is not yours and doesn't exactly address the goal of keeping stuff out of the EXE directory. The GAC is the simple workaround.

vb6 COM dll failing to load C# assemblies

I have a asp.net application calling intermediate C# dll which will make a call to a legacy vb6 dll through COM. During the actual call I find an error in my logs from my vb6 dll:
"Could not load file or assembly, 'Generic_C#_DLL.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0c9890f55677d2' or one of its dependencies. The system cannot find the file specified"
Why is my vb6 COM dll trying to load some of my other C# dlls? Is it because the dll that is calling the vb6 COM dll also referencing the 'Generic_C#_DLL.DataAccess'?
I think I am referencing the vb6 dll correctly in the C# dll that is calling COM by having a reference to 'Interops.VB6dll' and I have properly registered the vb6 dll with regasm.exe...So as of now I am kind of clueless to why this is happening, does anyone have any advice?
We're going to need to see code to be able to best help with this. However, note that this also says "or one of its dependencies", which may indicate that there is another load failure preventing this one.
There are a few very useful tools for figuring out DLL loading problems:
Fuslogvw.exe (Assembly Binding Log Viewer)
Dependency Walker 2.2
Process Monitor v3.03

Categories