You have a constructor that takes an IDbTransaction and a Action<UnitofWork> and starts by calling the constructor which takes an IDbTransaction and a Action<UnitofWork>, which is to say itself.
That would then immediately call itself, then immediately call itself, then immediately call itself…
If it was allowed, then one of two things would happen:
-
It would keep doing these calls to itself until there was a
StackOverflowExceptionthat crashed the application. -
The use of the stack was optimised away, so it just called itself forever in an infinite loop.
Either way, it would be pointless, so it’s obviously wrong, so it’s good for the compiler to not allow you to do so.
Instead a constructor must either:
- Use
thisto call a different constructor on the same type. - Use
baseto call a constructor on the base type. - Use neither (which is the same as using
base()to call a parameterless constructor on the base type.
2
solved C# Constructor cannot call itself