Solved

VFP crashes with C0000005 when inserting olecontrol developed in C#

Posted on 2010-09-02
8
723 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:guyvaio
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

6 Experts available now in Live!

Get 1:1 Help Now