# Graphviz source reference with c#

**URL:** <https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288>\
**Category:** Help\
**Created:** [June 21, 2024, 7:10am UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288 "2024-06-21T07:10:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wbarisch](https://avatars.discourse-cdn.com/v4/letter/w/7cd45c/32.png) [@wbarisch](https://forum.graphviz.org/u/wbarisch)\
**Post date:** [June 21, 2024, 7:10am UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/1 "2024-06-21T07:10:12Z")

</div>

Hello everyone!

I’m developing a graphViewer app in C#(VS). My code creates a Dot file and passes the parameters of dot process with `ProcessStartInfo` in order to get the text output of the dot graph from graphviz(-Tplain). Which I then use to get the coordinates of the nodes and edges.  
Is there a way to directly call the dot.c source code to do this?(maybe referencing) That is, without having to use the dot.exe from graphviz.

I tried looking for some graphviz c# libraries that offer this functionality, but it is either not offered, or the lib project has been abandoned for years. But I could also have misjudged the usability of some of them.

This is my first using forums by the way.  
Thanks for your help!

Wesley

---

<div class="post-metadata">

**Author:** ![mark](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/mark/32/84_2.png) [@mark](https://forum.graphviz.org/u/mark)\
**Post date:** [June 21, 2024, 7:52am UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/2 "2024-06-21T07:52:43Z")

</div>

I don’t think we have official C# graphviz bindings. But maybe the community has made some.

You might have an easier time parsing -Tjson output rather than plain?

I would probably encourage making a process call rather than library. Then you can put a timeout on it, and when it takes too long, cancel it. And when it hits bugs it won’t take down your app.

---

<div class="post-metadata">

**Author:** ![smattr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/smattr/32/85_2.png) [@smattr](https://forum.graphviz.org/u/smattr)\
**Post date:** [June 21, 2024, 7:58am UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/3 "2024-06-21T07:58:48Z")

</div>

In theory there are C# bindings in the Graphviz tree (`--enable-sharp=yes` to `./configure`). But I doubt any of the downstream packaging ecosystems enable this. In particular, I know the main vector for shipping Graphviz on Windows ([Chocolatey](https://community.chocolatey.org/packages/Graphviz)) does not, because it is using the CMake build system which does not support the C# bindings. We’re working on plugging this gap ([cmake parity (#2530) · Issues · graphviz / graphviz · GitLab](https://gitlab.com/graphviz/graphviz/-/issues/2530)).

---

<div class="post-metadata">

**Author:** ![wbarisch](https://avatars.discourse-cdn.com/v4/letter/w/7cd45c/32.png) [@wbarisch](https://forum.graphviz.org/u/wbarisch)\
**Post date:** [June 21, 2024, 7:59am UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/4 "2024-06-21T07:59:31Z")

</div>

I haven’t tried parsing with -Tjson, this could in fact make it faster and easier. I will try it, thank you for the tip.  
It does make sense to have the process call, and that is the way I’m currently using it.  
But, if I one day deploy the app, every user would need to already have graphviz installed, right?  
I was trying to maybe avoid this, and have every needed resource be already inside the deployed application.

---

<div class="post-metadata">

**Author:** ![mark](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/mark/32/84_2.png) [@mark](https://forum.graphviz.org/u/mark)\
**Post date:** [June 21, 2024, 11:17pm UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/5 "2024-06-21T23:17:42Z")

</div>

You could bundle graphviz with your app. Just make sure you include a copy of our license to comply with it.

---

<div class="post-metadata">

**Author:** ![PolarGoose](https://avatars.discourse-cdn.com/v4/letter/p/4491bb/32.png) [@PolarGoose](https://forum.graphviz.org/u/PolarGoose)\
**Post date:** [October 17, 2024, 8:10pm UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/6 "2024-10-17T20:10:03Z")

</div>

You can look at how I did it at [PolarGoose/GraphvizWpf](https://github.com/PolarGoose/GraphvizWpf):

- Add a prebuild event in your csproj that downloads Graphviz binaries and unpacks them into your build folder: [Test.csproj](https://github.com/PolarGoose/GraphvizWpf/blob/main/src/Test/Test.csproj#L36)
- Use Graphviz DLLs directly to generate the needed output: [NativeMethods.cs](https://github.com/PolarGoose/GraphvizWpf/blob/main/src/GraphvizWpf/Renderer/Interop/NativeMethods.cs) and [DotGraphDescriptionProcessor.cs](https://github.com/PolarGoose/GraphvizWpf/blob/main/src/GraphvizWpf/Renderer/DotGraphDescriptionProcessor.cs)
- You can use [JSON](https://graphviz.org/docs/outputs/json/) output format, it is easier to parse.

---

<div class="post-metadata">

**Author:** ![PolarGoose](https://avatars.discourse-cdn.com/v4/letter/p/4491bb/32.png) [@PolarGoose](https://forum.graphviz.org/u/PolarGoose)\
**Post date:** [January 1, 2025, 7:56am UTC](https://forum.graphviz.org/t/graphviz-source-reference-with-c/2288/7 "2025-01-01T07:56:22Z")

</div>

Just in case anyone encounters a similar problem:  
I have created a [PolarGoose/GraphvizProxy](https://github.com/PolarGoose/GraphvizProxy) that allows usage of GraphViz from C# and getting graph information like node positions, e.t.c.
