none
DllImport with .Net Core RRS feed

  • Question

  • Dear I am developing a small laboratory in .net core .21 to consume a .DLL that is elaborated in c ++ with System.Runtime.InteropServices, in the following way

    [DllImport ("prueba.dll", CallingConvention = CallingConvention.Cdecl)]
    
    private static extern bool helloExternal (String [] text)
    But when executing it, it shows me the following error:



    An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

    I have reviewed several recommendations, changing from x86 to x64 in the .net core project. I have also compiled the c ++ .dll in 32 and 64 bit. I have also made several combinations to execute but until now I still show the same error message.

    reference link


    https://github.com/dotnet/cli/issues/7532

    https://xaviergeerinck.com/binding-cpp-with-dotnet-core

    https://github.com/dotnet/corefx/issues/24444

    Thank you for your cooperation.

    PS: I have the 64bit dotnet installed from what I can understand.

    Alex_87

    Wednesday, November 28, 2018 2:53 PM

All replies

  • Hi 13Javier,

    Thank you for posting here.

    For your question, what is the prueba.dll? Do you define the dll by yourself? If yes, could you provide the method which you want to invoke in C# for us to test?

    Here is the link which descript the definition in C++ dll and how to invoke in C#.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbafec35-0759-4dde-9048-d1c0c80a2ffb/use-managed-c-class-library-with-c?forum=netfxbcl#2ad16543-0272-4e30-b0b4-617207408921

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 29, 2018 8:31 AM
    Moderator
  • Hi 13Javier,

    Thank you for posting here.

    For your question, what is the prueba.dll? Do you define the dll by yourself? If yes, could you provide the method which you want to invoke in C# for us to test?

    Here is the link which descript the definition in C++ dll and how to invoke in C#.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbafec35-0759-4dde-9048-d1c0c80a2ffb/use-managed-c-class-library-with-c?forum=netfxbcl#2ad16543-0272-4e30-b0b4-617207408921

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thanks for your contribution. I commented to you I managed to execute the .DLL c ++, with the console .net core. The solution that I have been able to give so far is to generate the c ++ DLL in x64 and also the .net core console. Additional activate the following option that is highlighted in the attached image.

    But this is working only on my development team, as I test on a client workstation that has Windows64 x64. It shows me the following message

    Unable to load DLL "..." The specified module could not be found.

    Investigating tells me that there may be dependencies of the c ++ DLL that the client's machine does not have installed. How can I know which dependencies are I using the Dependency Walker program?

    Alex_87

    Friday, November 30, 2018 3:26 PM
  • Hi 13Javier,

    This is English forum. It would be better to show the screenshot with English.

    What is the different between development team and client workstation? If the code works well in development team, there is nothing wrong for the code. I think the environment in client workstation cause the error.

    Do you have Visual Studio in your client workstation? Have you try to install the C++ part?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, December 5, 2018 7:55 AM
    Moderator