Error while overriding block via preference in Magento 2

- Magento 2

Magento 2 Development

While overriding block via preference, Magento 2 can show an error when you add a core registry in a construct method.  

'

If the error looks as follows:

you can easily fix the problem.

Probably, Toolbar block has many dependencies, but at the same time you don’t pass them.

Do not use preferences to overwrite classes. It’s better to rely on plugins or layout depends.

Source (Magento Stackexchange Question) (KAndy)

More Magento 2 tips from the Cookbook

'