Solved

VFP crashes with C0000005 when inserting olecontrol developed in C#

Posted on 2010-09-02
8
734 Views
Last Modified: 2012-05-10
Hello,

We are the editor of a programme developed in Visual FoxPro 9.0 sp2. It runs on thousands of computers. But for a a few of them, it crashes with a C0000005 error.

The line of the error contains : thisForm.AddObject('boutons_cancelok','olecontrol','MyDotNet.FactoryUi')

For test purposes, i've made a version 'MyDotNet.FactoryUi' with minimum source code :

using System;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Win32;
using System.Globalization;


namespace MyDotNet
{

    [Guid("49931b23-c598-4bd6-b97e-761f933f6cff")]
    [ProgId("MyDotNet.FactoryUi")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public partial class FactoryUi : UserControl
    {
       
        public FactoryUi()
        {
           
        }
       
       

        #region COM Registration
       [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            // Open the CLSID\{guid} key for write access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            // And create the 'Control' key - this allows it to show up in
            // the ActiveX control container
            RegistryKey ctrl = k.CreateSubKey("Control");
            ctrl.Close();

            // Next create the CodeBase entry - needed if not string named and GACced.
            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            // Finally close the main key
            k.Close();
        }

        [ComUnregisterFunction()]
        public static void UnregisterClass ( string key )
        {
          StringBuilder sb = new StringBuilder ( key ) ;
          sb.Replace(@"HKEY_CLASSES_ROOT\","") ;

          // Open HKCR\CLSID\{guid} for write access
          RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(),true);

          // Delete the 'Control' key, but don't throw an exception if it does not exist
          k.DeleteSubKey ( "Control" , false ) ;

          // Next open up InprocServer32
          RegistryKey inprocServer32 = k.OpenSubKey ( "InprocServer32" , true ) ;

          // And delete the CodeBase key, again not throwing if missing
          k.DeleteSubKey ( "CodeBase" , false ) ;

          // Finally close the main key
          k.Close ( ) ;
        }
        #endregion
  }
}

If I put a MessageBox.Show() in the constructor, this dialogbox is correctly shown and the C0000005 error occurs just after.

On a minor number of computers suffering from this problem, it has been resolved with an update of the video driver (ATI). But for the rest, we do not see any solution.

Thanks in advance for helping,

Best regards,

Guy
0
Comment
Question by:guyvaio
  • 4
  • 4
8 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33591402
Perhaps have a read on the whole subject of COM objects created in .NET and consumed elsewhere (not limited to foxpro) here: http://www.west-wind.com/presentations/VfpDotNetInterop/DotNetFromVFP.asp Rick Strahl adresses some problems you can have due to memory usage, garbage collection and more. Read for yourself.

Bye, Olaf.
0
 

Author Comment

by:guyvaio
ID: 33594306
Olaf,
Thank you very much for your help.
I knew this famous paper of Rick Strahl. It inspired me largely for the development of our .net connector 2 years ago. I read it again carefully but i do not find any information that could give me a way for a solution.
Best regards,
Guy
0
 

Accepted Solution

by:
guyvaio earned 0 total points
ID: 33618434
Here is the solution : copy the .net DLL from system32 to another directory on c: Run Regasm with this new path. And the problem is solved.
Best regards,
Guy
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33621527
OK, I could have told you that putting a DLL into system32 is not sufficient. Like any OCX this needs to be registered, in case of .NET dll via regasm. Glad you found the solution.

Bye, Olaf.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:guyvaio
ID: 33624449
Olaf,
The OCX that was in system32 was already passed via regasm.
As explained in my 1st topic, this solution works on thousands of computer.
Guy
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33656120
Then why would you need another regasm on a different location, or would regasm be sufficient even when you stayed with system32?

That something runs on thousands of computers but not on one is often the case isn't it? Something went wrong on that machine, eg a user without admin rights installed, something else failed during the original regasm run, something is different on that machine, eg some group policy, anything out of the scope of what you or the users know.

If a COM class doesn't work, reinstalling, reregistering it is a thing you can try, isn't it?
Anyway, glad you found the solution.

Bye, Olaf.
0
 

Author Comment

by:guyvaio
ID: 33656473
Olaf, I know this situation is unbelievable.

If i put the DLL in system32 and regasm it, it doesn't works.
If i put it in another directory and regasm it, it works
If i put back the DLL in system32 and regasm it, it doesn't works.

It has been noticed up to now on 5 different machines. I've seen that with my own eyes.

I think it is a bug in the .net framework, because 2 of our dealers solved this problem by uninstalling and then reinstalling the framework.

Regards,

Guy
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33656592
I would not put DLLs into system32 in the first place, this is for the system, OS in my opinion, everything else belongs into an applications folder or perhaps the global assembly cache.

Bye, Olaf.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

18 Experts available now in Live!

Get 1:1 Help Now