3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
940 stars 131 forks source link

create dll based on 3rd dll #93

Closed guzuomuse closed 5 years ago

guzuomuse commented 5 years ago

i have created a dll with 3rd library: Rabbitmq.Client(.dll)

if a function return something without facilities reference to rabbitmq . everything goes well,but when i use some function from rabbitmq.client.dll; the function can't not run as expect; example code:

    [return: MarshalAs(UnmanagedType.LPWStr)]
        [DllExport]
        public static string test_string([MarshalAs(UnmanagedType.LPWStr)]string content)
        {
            //var factory = new ConnectionFactory() { HostName = "localhost", UserName = "test", Password = "test" };  // here is the question, if i comment it , it can return content as expect,but uncomment,the exported dll will crash. 
            return content + "----from-c_sharp-----no--problem!";

        }

anybody can give me some tips ,why this occurs? how to solve this? many thanks!

3F commented 5 years ago

Similar to #84 (continues #83). Try to debug at runtime. Mixed mode for debugger with attaching to process.

https://github.com/3F/DllExport/issues/84#issuecomment-417937869

your problem may be exactly from logic of using your mentioned "the Neural Networks" library: incorrect initialization, invalid data, or even null and the related unhandled exception from managed side, stack corruption, stack overflow, and lot of other bugs.

3F commented 5 years ago

Also note, for stack problems you need to check required calling convention and try to start from basic signature without marshaling. Usually, I recommend only IntPtr because of more control. Well, it's my prefer.

But in general, your ConnectionFactory can do anything like "Neural Networks" library from #84.

Also try to isolate or catch something (about exceptions, start here #85). How about to reproduce an invoking from your trivial unmanaged side? C++ complete example see in related repo.

guzuomuse commented 5 years ago

@3F sorry for late reply.
In my case,after debugging, i found the reason was that i should copy the 3rd dlls to some special place, and the it worked; thanks for this library man!!!