0

Spec flow was working fine. I added some more string parameters in one of the Given statement and suddenly I start getting this error

Class Initialization method AutomatedRediTests.RediFeature.FeatureSetup threw exception. BoDi.ObjectContainerException: BoDi.ObjectContainerException: Primitive types or structs cannot be resolved: System.String.


at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath) in W:\SpecFlow\BoDi\BoDi\BoDi.cs:line 772
   at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name) in W:\SpecFlow\BoDi\BoDi\BoDi.cs:line 698
   at BoDi.ObjectContainer.Resolve(Type typeToResolve, String name) in W:\SpecFlow\BoDi\BoDi\BoDi.cs:line 680
   at TechTalk.SpecFlow.Infrastructure.TestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer container) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestObjectResolver.cs:line 11
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ResolveArgument(IObjectContainer container, IBindingParameter parameter) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 285
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.<>c__DisplayClass42_0.<ResolveArguments>b__0(IBindingParameter p) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 273
   at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ResolveArguments(IHookBinding hookBinding, IObjectContainer currentContainer) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 273
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 242
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 234
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnTestRunStart() in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 69
   at TechTalk.SpecFlow.TestRunner.OnTestRunStart() in D:\a\1\s\TechTalk.SpecFlow\TestRunner.cs:line 29
   at TechTalk.SpecFlow.TestRunnerManager.InitializeBindingRegistry(ITestRunner testRunner) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 73
   at TechTalk.SpecFlow.TestRunnerManager.CreateTestRunner(Int32 threadId) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 60
   at TechTalk.SpecFlow.TestRunnerManager.GetTestRunnerWithoutExceptionHandling(Int32 threadId) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 147
   at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(Int32 threadId) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 134
   at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(Assembly testAssembly, Nullable`1 managedThreadId) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:line 224

How do I go about resolving this error? It asks to resolve System.String

EDIT:

looks like in specflow bindings I have a line someMachine abc = SomeControl.BeforeTestRun(); and I needed it to change so it passes a string like someMachine abc = SomeControl.BeforeTestRun("someString"); . When I pass this string , I get this error. No matter if I write the line inside a step definition method or just inside the class.

Is there a way to achieve this?

user1207289
  • 3,060
  • 6
  • 30
  • 66
  • Add new strings one at a time until you find which is causing the issue. – jdweng Jul 18 '19 at 15:47
  • @jdweng And If I find that string , how do I resolve? I think I know which string is that – user1207289 Jul 18 '19 at 15:50
  • I suspect you are trying to convert a structure to a string and there is no method that does the conversion. You would need to create code to convert the structure to a string. Often I use String Join to take an array object and make it a single string. – jdweng Jul 18 '19 at 16:07
  • @jdweng I edited above to provide more information. Is there a way to do what I edited above? – user1207289 Jul 18 '19 at 17:16
  • I usually create a custom class that inherits the standard control. So If you have a button I create a class MyButton : Button and then in the class have a method ToString(). – jdweng Jul 18 '19 at 17:22
  • @jdweng I am not sure if I understand. So , `SomeControl` is a class that inherits another `ControlClass` that was given in a custom framework. `BeforeTestRun` method is annotated `[BeforeTestRun]` in that `ControlClass` . I am not understanding why passing a string invokes the error. Does it have to do something with passing to this `[BeforeTestRun]` annotated method? – user1207289 Jul 18 '19 at 17:39
  • Please post the method implementing the `Given` step. – Greg Burghardt Jul 24 '19 at 14:53

1 Answers1

2

You get this error, if you have a string parameter in the constructor of a class that you get via context injection.

Andreas Willich
  • 5,665
  • 3
  • 15
  • 22
  • how do I go about resolving it? As I described above in edit and comment, I need to pass parameter in `[BeforeTestRun]` annotated method. I am not using context injection here. So you are saying , I will get this error even if I use proper context injection as described [here](https://github.com/techtalk/SpecFlow/wiki/Context-Injection) – user1207289 Jul 19 '19 at 12:39
  • Please add the whole code of the class that makes problems. Without it, I can't say anything concrete. – Andreas Willich Jul 19 '19 at 14:18
  • @ Andreas Willich , I am not able to post the whole code currently but I am able to achieve what I was doing by passing static properties from one class to another and the reading property in `[BeforeTestRun]` instead of having variable as parameter. But for more complex scenarios context injection would be the way to go. Is there a general workaround of the issue that you mentioned ? – user1207289 Jul 22 '19 at 14:38
  • 1
    The workaround is to encapsulate the string in your own type. – Andreas Willich Jul 22 '19 at 15:27