I came across kinda similar issue when working with Reqnroll (formerly known as Specflow) ScenarioContext
object:
System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.Func`1[System.String]'.
at Reqnroll.ReqnrollContext.TryGetValue[TValue](String key, TValue& value)
at Helpers.Extensions.ScenarioContextExtensions.GetTextValueOrKey[T](ScenarioContext scenarioContext, String key)
It does give you relevant information as well. During closer inspection I have realized that I am trying to do something that is already done out of the box:
https://github.com/reqnroll/Reqnroll/blob/main/Reqnroll/ReqnrollContext.cs#L33 https://github.com/reqnroll/Reqnroll/blob/main/Reqnroll/ReqnrollContext.cs#L76
I hope it might help somebody in the future :)