.NET COM DLL throwing exception when used in Delphi - c#

I have a COM DLL produced in C# using VS2010, using it from VS2910, it works fine, but when I try to use the DLL from Delphi 7, having imported the .tlb file, some of the functions work fine, but one seems to generate the following error.
Could not load file or assembly 'InnovateCV, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c06107b7da48b1da' or one of its dependencies. The system cannot find the file specified. unfortunatly it have no idea what is failing to load, the InnovateCV is my DLL, and is loaded, getting more information from the exception the Data value is 'System.Collections.ListDictionaryInternal'. Unfortunally my COM DLL is calling a third party .NET DLL, which is where the exception is being thrown. Is there any way to find what it is failing to load.
I've tried using Depends.exe, and there are no DLL's mising that it can see.
Any help would be appreciated.

Solved the problem, it was a clash of DLL names, between the Delphi App, and the .NET App, so the Delphi App, was failing to find the required function in the DLL, I also had to put all the DLL's in the same directory as the Delphi App. And its now working. Thanks for the Help.

Related

BadImageFormatException Could not load file or assembly ... An attempt was made to load a program with an incorrect format

I have .NET 5 project which includes C++/CLI DLL, which includes C++ DLL, which includes opencascade DLLs. All these projects are built for the x64 platform. I've published this solution to my local folder and then set up IIS server everything works fine. But when I've tried to upload my project to two different hostings (https://www.smarterasp.net/ and azure) I've got this error. Project crashes when it starts use C++/CLI dll(using namespace C++/CLI). I've also set up x64 platform in azure portal.
I would appreciate any help.
Thank you Joe. Posting your suggestion as an answer to help other community members.
Project crashes because of missing DLL. Run the app and get the error.
Go to the Windows Event Viewer (Start Menu and type "Event"). In the EventViewer, under Windows Logs >> Application, you might see an error message regarding the failure. If the error is a missing DLL, it will typically tell you the name of the DLL as well.
You can refer to Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException), Troubleshooting BadImageFormatException and System.BadImageFormatException An attempt was made to load a program with an incorrect format

.Net DLL reference error (after strong name sign)

Here is my scenario.
I have Few applications using ABCD.dll (written in C# .net), this old DLL was NOT strong name signed.
I modified this dll basically kept the same name ABCD.dll and signed it with the key. Please note there is no code change
I thought I should be able to just place this newly updated DLL into different applications folders and it should work. Am I wrong?
I am getting following error
BadImageFormatException: Could not load file or assembly 'ABCD, Version=7.2.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
How do I use this new dll without compiling all the old applications?
Am I wrong?
Yes, basically. Changing the signature on a DLL, including from "not having one" to "having one" is a breaking change - it changes the identity of the DLL as far as the CLR is concerned.
How do I use this new dll without compiling all the old applications?
You don't, as far as I'm aware. I don't know of any way of getting that to work. I suggest you take the hit and rebuild everything.
You can, if you're lucky 'just' change the reference to the new .DLL. There are tools for this.
You can try this one: https://marketplace.visualstudio.com/items?itemName=markkemper1.ReferenceSwitcher

dll File not accessible

I know this question has been asked before but all the steps advised doesn't seem to work for me.
I am trying to use WebCamLib.dll to my project but it keeps giving me this error:
please make sure the file is accessible and that is a valid assembly
or com component
I tried to register the dll to SYSTEM32 and I get this error
The module C:\WebCamLib.dll" was loaded but the entry-point
DllRegisterServer was not found.
Make sure that "C:\WebCamLib.dll" is a valid DLL or OCX file and then
try again.
Please suggest a way. Thank you in advance.
The library you are trying to use is a managed library, you don't need to register it or use dllimport. Just add a reference from inside your project to the dll.
First option is DLL file may be corrupt. Make sure it is working with other applications.
My second opinion is you are trying to use this DLL as COM object which is not.

C# COM-Interop dll for C++ COM dll doesn't work between 2 solutions

I am trying to reuse an interop DLL that compiled in one project on another, and it doesn't work.
I'll elaborate:
I compile the C++ COM DLL native_com_object.dll
In the same solution I have a C# project called LocalComClient.dll that generates Interop.native_com_objectLib.dll to use the C++ native_com_object.dll.
Last, I have another solution with a C# project (being compiled on another computer) called RemoteComClient.dll that references to native_com_object.dll (registered in that computer). This generates another Interop.native_com_objectLib.dll.
The problem is RemoteComClient.dll tries to load native_com_object.dll it MUST use its own Interop. If I try to use the LocalComClient.dll Interop .Net fails to load the assembly.
Edit: The exact exception message I am getting is:
Could not load file or assembly 'Interop.native_com_objectLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Of course the problem also occurs vice-versa (LocalComClient cannot use RemoteComClient's Interop).
My first question is - why?? As far as I understand it should generate the same interop (which obviously I am wrong).
My second question is, is it possible to make one interop for all the .Net clients of the DLL?
I'll point out I am using VS2013 (both machines), the C# objects are AnyCPU, and the C++ is x64.
Important EDIT: I cannot embed interop types because the C# projects are .Net 3.5 (not 4).
The located assembly's manifest definition does not match the assembly reference.
Very common exception message, the DLL it finds at runtime isn't the same as the reference assembly your program was compiled with. A very basic DLL Hell problem, not otherwise specific to COM interop.
You diagnose these kind of failures with Fuslogvw.exe, its trace for the failed assembly bind shows you what it looked for and what it found. The usual mismatch is the version number, you compiled your program with the 1.0.0.0 version of the interop assembly. That version is generated from the type library version number of the COM server. You were using version 1.0, kaboom if the COM server changed and you use its newer interop assembly.
And the PublicKeyToken can easily be a mismatch, you expect the interop DLL not to have one. Kaboom if the one you load at runtime does have one. Not terribly uncommon in COM interop, you tend to favor them getting stored in the GAC and that requires a strong name. Something you usually do later, forgetting to rebuild the app is an easy mistake.
The solution is to rebuild the client app with the correct interop assembly.

Interop.MSXML2 throwing exceptions because its not registered BUT IT WONT REGISTER!

Ok, this line of code:
XMLHTTP40 http = new XMLHTTP40();
Throws a System.Runtime.InteropServices.COMException and complains that:
Retrieving the COM class factory for component with CLSID {88D969C5-F192-11D4-A65F-0040963251E5} failed due to the following error: 80040154.
I have googled that and I guess the DLL needs to be registered because its a COM DLL. That's fine, but when I try to register it I get this error:
C:\some\directory\path\etc\Interop.MSXML2.dll was loaded, but the DllRegisterServer entry point was not found.This file can not be registered.
Apparently this is working on another guys box (he wrote the code, so yeah.. :P). This COM object does not show up in my list of available COM references so I just reference the DLL which is sitting in the bin\Debug directory of the project. When I add the reference to this DLL to my project, I get access to all of the symbols in VisualStudio. I'm wondering, is there something that I can install that would register the DLL and have it show up in my list of COM objects that I can reference? I installed what I thought was the MSXML 4.0 library but when I looked in the directory there wasn't anything in there.
Any ideas?
You need to actually have MSXML4 installed on your box for it to work. THe interop dll doesn't contain any runtime code it only helps .NET talk to MSXML4.
However why would you not use the System.Xml namespace instead of using a COM component?
You need to register (regsvr32) msxml4.dll, not the interop assembly. msxml4.dll is the COM server.

Categories

Resources