System.Runtime.InteropServices.COMException: "Object Name Not Found"

Started by Helkost, October 13, 2023, 03:16:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Helkost

Hi,
I received this error a few times when coding my C# application. I would like to know more about this error, in general, like how and why it occurs.

From what I gathered it happens when I try to retrieve a stencil shape with the appropriate get method of the propriety "ItemU", when the shape name I provide is incorrect and it doesn't match any corresponding shape inside the stencil.

I ask because this error fires up once in a while, and sometimes I do not understand why it happens, since double checking the string I provide and the shape names inside the stencil, there is indeed a match. Moreover, at times the method starts working again, just by simply rebuilding the solution (or whatever, I'm not sure which action makes it go away, I'm pretty confused right now).

Here is a piece of code that triggers it:


[...]
    Visio.Master masterElement = CurrStencil.Masters.get_ItemU(@"CONNECTOR"); //triggers the COMException.

    Visio.Shape shapeElement = visioPage.Drop(masterElement, 0.0, 0.0);
[...]


Where CurrStencil is a stencil I uploaded in a different part of the code, and it contains a shape called "Connector". Giving the connector a name in all uppercase letters, so that it matches perfectly, doesn't help at all.

I really don't understand why it happens. Any ideas?


Paul Herber

Do you always open the same stencil, not just the same named stencil, but actually the same stencil each time on the same computer on the same path?
You are using 'get_ItemU' which gets the item using its Universal name. Are you aware of Universal and local names?
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Helkost

Hi Paul, thank you for your reply.

I always open the same stencil, it's in a folder "resources" within my project dir. One of my ideas was that sometimes an old stencil version remains in visual studio cache and it keeps using it. I removed the .vs folder but nothing changed.

I do not know the theory behind Universal names and Local names, I'm mostly learning by doing and through Microsoft Learning Center. I inferred the ItemU referred to a "universal" propriety, but I didn't go any further than that because with other shapes in the same stencil it works. That is: using ".get_ItemU(@"HOST") correctly retrieves the master shape with name "Host".

It has to be said that I created all the stencil shapes ex-novo (I mainly needed custom stuff), but the connector is the only one I just copied from other standard stencils. Is this the reason why it could be a case of conflicting Universal names vs Local Names ?

P.S. If you could suggest a good, exhaustive book on visio theory, I would gladly use it to improve my knowledge base. So far I haven't found much that goes beyond the basics, except visguy blog! the blog is a goldmine.

wapperdude

Try "Dynamic Connector" as name.

Also, if you use macro recorder and do drag and drop, the recorder should fetch the name to use.
Visio 2019 Pro