Select to view content in your preferred language

Memory could not be read closing the application

1048
5
03-20-2012 07:53 AM
SergioMunoz
Emerging Contributor
Hello everyone,

I updated my ArcGIS version from 9.3 to 10.0, and now I have always an error when application is closing:

The instruction at "0x7c90100b" referenced memory at "0x294e0a24". The memory could not be "read". Click on OK to terminate the program.

I have read that I can solve this error with the following code:

      
 protected override void Dispose(bool disposing) 
        {
            try
            {
                IStyleGallery styleGallery = new StyleGalleryClass() as IStyleGallery;
                IntPtr pointer = Marshal.GetComInterfaceForObject(styleGallery, typeof(IStyleGallery));
                Common.GIS.GISUtil.releaseCOMObjects(styleGallery);
                //Close the ARCGIS map license
                ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception e)
            {
                Common.Utilities.LogFile.appendLine_error(e);
            }
            finally
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
        }


This Dispose method is the main form's method. However, I am having the following exception on the first line (creating the StyleGalleryClass):

System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {AC0E9827-91CB-11D1-8813-080009EC732A} failed due to the following error: 80040154

So I can not solve the problem, and I don't have any idea of how to avoid the memory error.

Does anyone have any idea? Thank you very much in advance.
0 Kudos
5 Replies
RichWawrzonek
Frequent Contributor
You didn't explain enough about your application to help you with the original error. However, the error you are seeing in your work around is likely due to the way you instantiate the IStyleGallery. It is a singleton object and needs to be created like this:
Type t = Type.GetTypeFromProgID("esriFramework.StyleGallery");
System.Object obj = Activator.CreateInstance(t);
IStyleGallery sg = obj as IStyleGallery;


http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000043p000000
0 Kudos
SergioMunoz
Emerging Contributor
Thank you for your answer,

I cannot give you more information because I don't have it. Everything was working fine until I updated ArcGIS from 9.3 to 10.0, and now when the application is closed that error appears. However, that error only appears when I execute the application without debugging. If I debug the application, instead of that error the application hangs on, i.e., everything is closed and finished but the application is still running (I suppose that one of the libraries has an active thread or something).

I have used this code to know if an unhandled exception is thrown, but everything is fine:

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionCaptured);


Besides, if I use your code to get the StyleGallery, the t object is null:

Type t = Type.GetTypeFromProgID("esriFramework.StyleGallery");


So I am at the same point 😞
0 Kudos
SergioMunoz
Emerging Contributor
Ok, I have located exactly where the error is, and it's on the following code:

    IMoleSymbol moleSymbol = new MoleMarkerSymbolClass();
    moleSymbol.SymbolID = APP6IDSymbol;
    moleSymbol.Style = moleSymbologyStyleEnum.moleSSAPP6A;
    
    IMoleSymbolImportExport pExport = (IMoleSymbolImportExport)moleSymbol;
    int handle = pExport.ToBitmapHandle(null, 70, 70);


The last line is the one that is blocking the application and launching the error when it is closed. If I comment it, the application finishes correctly, but it worked on 9.3 version, so I don't know why in 10.0 is crashing...
0 Kudos
MarkMindlin
Frequent Contributor
We have the same problem. See the post named "Exception after stand alone application was closed".

We guess that may be problem in "new" (10) License objects or ... (?).
0 Kudos
RichWawrzonek
Frequent Contributor
I cannot give you more information because I don't have it.

You have the source code if you are debugging it so there is a lot you should know about the application. The original post did not let anyone know that this is a standalone application.



Besides, if I use your code to get the StyleGallery, the t object is null:

This is not my code, it is a direct example from Esri from the link I provided, and t is not an object it is a type.


I don't have the Military Analyst extension so I cannot help with the code you posted but I'm sure it would help other users if you show the part where pExport is instantiated. I deduced that it is probably a IMoleSymbolImportExport object but you are not making it easy for people to help you.
0 Kudos