Strong name for unsafe C++ assembly (dll) to be calles by C# application

Posted on 2009-04-18
Last Modified: 2012-05-06
Hello, I am trying to import (Dll import) into a C# application, a C++ dll, wrapping a third party USB driver API. Everything runs smoothly but sometimes the application consumes even up to 99% of cpu. By running process check up, I have discovered that from time to time (at moments of high cpu load) an invisible exception occurs, at the dll level related to the StrongNameErrorInfo. Next to that exceptions related to unregisterassembly and other similar issues.
Well started searching for Strong, Weak name signing assembly and found nothins related to this situation.
Does anyone have a solution?

Question by:ivanadu
    LVL 39

    Expert Comment

    might it be that the "next to that exceptions..." are a result of the earlier exceptions? I.e., that the unwinding in the dll does not go smoothly and hence the unregisterassembly etc do not work as smoothly either?

    it seems likely that the error either occurs in your wrapper, or in the third party usb driver. Maybe you can add structured exc. handling in your wrapper (if not already there) to at least log any exceptions that occur from the driver?

    Author Comment

    I'll give it a try. I am back within an hour :)

    Author Comment


    ptr is a reference to a function from the c# application passed at init time.
    Most of the times this works, and when the communication load is high it fails.

    typedef void (__stdcall *pTempMessageHandler)(unsigned long);
    	unsigned long bytes2Read;
    	unsigned long bytes2Send;
    	unsigned long eventStatus;
    	pTempMessageHandler ptr = (pTempMessageHandler)pContext;
    	while (applicationRun == true)
    		unsigned int uiTemp = WaitForSingleObject(hEvent,INFINITE);
    		if (applicationRun == true)
    		{	//(handle, *dword, *dword,	*dword);
    			FT_STATUS ft_status = FT_GetStatus(ftHandle,&bytes2Read,&bytes2Send,&eventStatus); 
    		catch (char * str)
    			//cout << "Exception raised: " << str << '\n';

    Open in new window


    Accepted Solution

    Solved, thread not in dll but in c#, manualreset instead of autoresetevent in c++ dll, no loops in dll, c# thread calls blocking receive function from dll. upon receiving manually reset event in c++. none of the events are exchanges between c# and c++ dll. ...

    thanks anyway
    LVL 39

    Expert Comment

    glad you found it. I was just thinking of a way to help you further, but it isn't easy with this type of errors if you're not behind the machine (physically or remotely).

    Author Comment

    i know, once you search for such an error, you wonder if that is the right path. simplifying was the only option and minimizing interaction between c# and c++...
    still not sure about this manually reset event, but once in correct position before reading how many bytes are in the queue i do not expect problems  

    thanks again

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now