Error when using ServerStyleGalleryClass ?

455
2
Jump to solution
08-22-2013 02:13 AM
TaiBui
by
Occasional Contributor II
Hi,

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
0 Kudos
1 Solution

Accepted Solutions
TaiBui
by
Occasional Contributor II
I know that this is stating the obvious but perhaps the server style file which was generated does not contain the thing that you are asking for. 

The help reads:

"The style items from the specified style file, in the specified class and category. The style set and category may be blank to return all items"

Modify your code to get everything thing and see if that works.  If it does then print out what you get.


Thank you. I discovered that, we need to release COM object, and I added below codes

if (styleItems != null)                 System.Runtime.InteropServices.Marshal.ReleaseComObject(styleItems);  
   

before the line

styleItems = styleGallery.get_Items("Line Symbols", strFilePath,"");


, then successfull:


Kind regards,

View solution in original post

0 Kudos
2 Replies
RichardWatson
Frequent Contributor
I know that this is stating the obvious but perhaps the server style file which was generated does not contain the thing that you are asking for. 

The help reads:

"The style items from the specified style file, in the specified class and category. The style set and category may be blank to return all items"

Modify your code to get everything thing and see if that works.  If it does then print out what you get.
0 Kudos
TaiBui
by
Occasional Contributor II
I know that this is stating the obvious but perhaps the server style file which was generated does not contain the thing that you are asking for. 

The help reads:

"The style items from the specified style file, in the specified class and category. The style set and category may be blank to return all items"

Modify your code to get everything thing and see if that works.  If it does then print out what you get.


Thank you. I discovered that, we need to release COM object, and I added below codes

if (styleItems != null)                 System.Runtime.InteropServices.Marshal.ReleaseComObject(styleItems);  
   

before the line

styleItems = styleGallery.get_Items("Line Symbols", strFilePath,"");


, then successfull:


Kind regards,
0 Kudos