Select to view content in your preferred language

CreateRenderer Failing

239
12
a week ago
MichaelTodd
Occasional Contributor

Under what circumstances would a layer CanCreateRenderer method return true, yet running CreateRenderer with the same renderer caused the following error:

ArcGIS.Desktop.Mapping.MappingException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'

Can't nail down why the error. Everything seems to be set up correctly, using a FeatureLayer, all required elements are set in the classes. To top it off, this code has been working since at least ArcGIS Pro 2.8 and has just recently started to crash Pro. Any ideas?

0 Kudos
12 Replies
UmaHarano
Esri Regular Contributor

Can you please share your code and the type of layer you are rendering?

0 Kudos
MichaelTodd
Occasional Contributor

The layer I am trying to alter is a polyline. I am using a UniqueValueRenderer with one field and five values to differentiate symbology. And, again, this code has worked for about four years now, with no changes to it, so I am unclear why it is failing with that error now. Code is attached.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

Some information from ArcGIS Pro API:

Certain renderers are only appropriate for certain layer types or for layers of a certain geometry type. For example a Dot Density Renderer can only be applied to a polygon layer, a Heat Map Renderer can only be applied to a point layer.

Please give us more information about your layer shape type, renderer type and etc.

 

0 Kudos
MichaelTodd
Occasional Contributor

I'll provide more details, including the code, in the other response in a moment, but my real question, given your statement, is: what utility does the CanCreateRenderer method provide if it returns true, yet the CreateRenderer method fails when using the same ValueRenderer in both cases?  If it had responded with false, I would have looked deeper into the code (which, again, has been working with the same layer for about 4 years now) as the source of the problem. As it stands, I cannot rely on CanCreateRenderer to vet whether or not the renderer I created is valid with the layer in question.

0 Kudos
UmaHarano
Esri Regular Contributor

Hi @MichaelTodd 

The CanCreateRenderer method checks if the renderer being applied to the layer is the appropriate choice -
Certain renderers are only appropriate for certain layer types or for layers of a certain geometry type. For example a Dot Density Renderer can only be applied to a polygon layer, a Heat Map Renderer can only be applied to a point layer.

The method does not check if all the renderer values being applied are correct - such as are the correct fields being used, etc.  


0 Kudos
MichaelTodd
Occasional Contributor

Got it, though given that result I would expect the method to be named "IsValidRendererType", not "CanCreateRenderer". Neither here nor there, of course. 

Have you had an opportunity to examine the code? Is there anything that stands out as being jarringly incorrect? I will say that "status" is a valid field, and the symbologies (to my eye) also appear valid. Just can't narrow down what's causing the failure to create the renderer.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

I have tested your code on ArcGIS Pro 3.5 and can say the same as @UmaHarano . It works as in Uma's screenshot.

What version of ArcGIS Pro do you use?

0 Kudos
MichaelTodd
Occasional Contributor

I am using ArcGIS Pro 3.5.4.57366.

0 Kudos
UmaHarano
Esri Regular Contributor

@MichaelTodd 
I used your code on a mock up data set with "status" fields. It seems to work for me. I can't see anything wrong with the code. We will have to debug with your data to see what is actually happening.

UmaHarano_0-1763751382667.png

 

0 Kudos