While the answer by @tibaverus is the ‘nicest’ way, your approaches should also work with the exception of missing parentheses in the second example:
((SomeClass)inst).Test();
In fact, GetNode<T> does nothing else than (T)GetNode(...).
So your problem is probably somewhere else. Are you sure that your inst is not null? You getting a NullReferenceException in the second example suggests otherwise.
Do you get a ‘Node not found’ error?
I didn’t get errors like “Node not found” and I tried
inst = GetNode<Sprite2D>("NodeName");
GD.Print(inst.Position);
GD.Print(inst as SomeClass);
The position of inst was printed. I think it proves that the node is not null.
However, in the second line I got a null, indicating that it’s an invalid cast.
does throw an InvalidCastException. I got a mistake again, sorry.
Now I have found out the real reason behind the exceptions.
In ParentClass, I wrote a constructor with some parametres, which makes the editor unable to instantiate the any script extends from ParentClass and throw an MissingMemberException (I thought it was some kind of error that wasn’t related to my situation so I ignored it).
The reason why I suceeded last week when attaching ParentClass directly to the node is unclear, maybe I got things right accidentally. But now I have deleted the constructor in the ParentClass and everything works well including attaching SomeClass to the node.
Thank you for your replies!