CustomDotNet.dll Error

I created a custom .net dll to use with CRM 7.1h. This dll uses the accpac com api to create an invoice in AccPacc. This is very intermittent but sometimes it works fine and other times it doesn't. Most of the time when they get this error message they click on the button again and it works fine. Following is the error the customer is getting...

Exception in dotnetdll page : Unable to cast COM object of type 'System.__ComObject' to interface type 'Sage.CRM.Wrapper.ICrmWebObject'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{21E6B752-E2E8-3854-9C28-24D19B418907}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

I've seen several posts about re-registering the sage crm dll's in the gac. I've tried that with no luck. I did write the dll in .net 4.0 which means that I had to change the app pool that runs crm to use .net 4.0. Does CRM support .net 4.0? I tried rebuilding the dll with .net 2.0 but I couldn't get it to work with crm. It kept saying it couldn't find the accpac com api dll?? Anyway this is becoming quite a nuisance for the customer as well as me so any help would be much appreciated. Thanks :-)