[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VFP crashes with C0000005 when inserting olecontrol developed in C#

Posted on 2010-09-02
8
Medium Priority
?
783 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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