1

First, I used:

IStyleGallery styleGallery = new StyleGalleryClass();

I can run my program without error (on my computer). But this require using ESRI.ArcGIS.Framework (need install Arcgis Desktop). And, I can't use for my client computers. So, I used ServerStyleGalleryClass, and I used "MakeServerStyleSet" utility to convert my style file into server style.

Then, I used below codes, but I got the error "Error HRESUT _EFAIL has been returned from a call to a COM component" (because after getting Items, styleItems is NULL)

        IStyleGallery styleGallery = new ServerStyleGalleryClass();

        IStyleGalleryStorage styleStor = (IStyleGalleryStorage)styleGallery;            
        string startupPath = Environment.CurrentDirectory;


        string strFilePath = startupPath + "\\Data\\Styles\\SoDo.ServerStyle";
        styleStor.AddFile(strFilePath);

        IEnumStyleGalleryItem styleItems;            

        styleItems = styleGallery.get_Items("Line Symbols", strFilePath, "Default");  // Return NULL value
        styleItems.Reset();
        IStyleGalleryItem styleGalleryItem = styleItems.Next();

Are there anyone know what's wrong ?

Thanks and regards,

Tai

2

The Style Gallery is a singleton object. It shouldn't be instantiated with the "new" keyword. Instead use the Activator class like this:

Type t = Type.GetTypeFromProgID("esriFramework.StyleGallery");
System.Object obj = Activator.CreateInstance(t);
IStyleGallery sg = obj as IStyleGallery;

Use the following reference for further info: Interacting with singleton objects

  • +1 Need to use esriDisplay.ServerStyleGallery as progID if you don't have desktop installed. – Kirk Kuykendall Aug 27 '13 at 21:38
  • Thank all of you. I resolved this problem. Please see the link: forums.arcgis.com/threads/… – taibc Aug 28 '13 at 2:45
  • Yep, that's why you use the Activator class to properly handle these COM objects. You might have solved your current issue by releasing the object explicitly, but without instantiating the singleton objects in the recommended way other COM errors may arise. – Rich Wawrzonek Aug 28 '13 at 16:43
  • @RichWawrzonek: Dear Rich Wawrzonek. I got the error again with IStyleGalleryStorage. Please see my code: IStyleGalleryStorage styleStor = (IStyleGalleryStorage)styleGallery; styleStor.AddFile(strFilePath); // Throw exception in the "add file" statement – taibc Sep 9 '13 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.