Solved

VFP crashes with C0000005 when inserting olecontrol developed in C#

Posted on 2010-09-02
8
761 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 

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

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

697 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