Error after magento upgrade

I have solved this problem by just simply doing this steps. follow steps :

  1. Delete the "di" folder located in var directory (for 2.0 and 2.1)
  2. Run this command and go to your project root folder command:

    cd /yourmagentoroot/
    

    If your Magento mode is developer then you don't need to run below commands just remove var/generation directory(2.0 & 2.1) or generated folder(2.2 onwards)

  3. Then run this command

    php bin/magento setup:di:compile
    
  4. Then run this command (required in production mode only)

    php bin/magento setup:static-content:deploy
    
  5. Finally, give file/directory permissions.(If needed)


Giving full control (read/write/execute) to var and pub directory solved this issue for me.

sudo chmod -R 777 var pub

Or, you may also try running the command using sudo.

sudo php bin/magento setup:upgrade

Also, try clearing cache.

sudo rm -rf var/cache/* var/generation/*

Setup ownership again

CentOS: chown -R :apache .
Ubuntu: chown -R :www-data .

Refer this Link