Yse, there is a RhinoCommon for .NET (C# & VB.NET), and yes, you can write a plugin which you install directly into Rhino (this is ho0w many commands are actually added to Rhino, “natively” so to speak).
There are examples of how you write a plugin (= a command plugin) for Rhino, using VS, on these pages (common API page):
With the way of working described below, it is possible to separate declaration and implementation of C# commands. The implementation assembly is read from byte stream, and can be reloaded when the command executes. That way it can always be rebuilt while Rhino is running, and the latest version is loaded as the command executes. We use this approach, and it saves a ton of time because you don’t have to restart Rhino each time the implementation of a command changes. We also use it for Grasshopper assemblies.
I am new user to Rhino.I want to connect to running instance of Rhino and I want to get current file name using c#.I have tried Marshal.GetActiveObject.Its throwing error.Any documents or code would be helpful.
If you are happy to make your own plugin for this you could try to host https://github.com/aelij/RoslynPad in a Rhino plugin. (I am working on something similar but with F#.)