?
Solved

VFP crashes with C0000005 when inserting olecontrol developed in C#

Posted on 2010-09-02
8
Medium Priority
?
787 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 30

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

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
 

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 30

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 30

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 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