Custom app suddenly stopped working "QueryException: Could not resolve service! Class service does not exist"

Hi!

Somewhere between Christmas and last week my custom wishlist app stopped working (most likely it’s connected to the upgrade to 21, something with PHP 8???).

I use docker with nextcloud:21.0.1

The logs show the following error:

{
"reqId": "Mc7f7VbTsyg6lvKvCNmV",
"level": 3,
"time": "2021-04-20T18:38:57+00:00",
"remoteAddr": "172.27.0.1",
"user": "julian",
"app": "index",
"method": "GET",
"url": "/apps/wishlist/wishes",
"message": {
	"Exception": "OCP\\AppFramework\\QueryException",
	"Message": "Could not resolve service! Class service does not exist",
	"Code": 0,
	"Trace": [
		{
			"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
			"line": 126,
			"function": "resolve",
			"class": "OC\\AppFramework\\Utility\\SimpleContainer",
			"type": "->",
			"args": [
				"service"
			]
		},
		{
			"file": "/var/www/html/lib/private/ServerContainer.php",
			"line": 162,
			"function": "query",
			"class": "OC\\AppFramework\\Utility\\SimpleContainer",
			"type": "->",
			"args": [
				"service",
				true
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
			"line": 434,
			"function": "query",
			"class": "OC\\ServerContainer",
			"type": "->",
			"args": [
				"service",
				true
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
			"line": 96,
			"function": "query",
			"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
			"type": "->",
			"args": [
				"service"
			]
		},
		{
			"function": "OC\\AppFramework\\Utility\\{closure}",
			"class": "OC\\AppFramework\\Utility\\SimpleContainer",
			"type": "->",
			"args": [
				"*** sensitive parameters replaced ***"
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
			"line": 101,
			"function": "array_map",
			"args": [
				{
					"__class__": "Closure"
				},
				[
					{
						"name": "AppName",
						"__class__": "ReflectionParameter"
					},
					{
						"name": "request",
						"__class__": "ReflectionParameter"
					},
					"*** sensitive parameter replaced ***",
					{
						"name": "userManager",
						"__class__": "ReflectionParameter"
					},
					{
						"name": "UserId",
						"__class__": "ReflectionParameter"
					}
				]
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
			"line": 109,
			"function": "buildClass",
			"class": "OC\\AppFramework\\Utility\\SimpleContainer",
			"type": "->",
			"args": [
				{
					"name": "OCA\\Wishlist\\Controller\\WishController",
					"__class__": "ReflectionClass"
				}
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
			"line": 126,
			"function": "resolve",
			"class": "OC\\AppFramework\\Utility\\SimpleContainer",
			"type": "->",
			"args": [
				"OCA\\Wishlist\\Controller\\WishController"
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
			"line": 459,
			"function": "query",
			"class": "OC\\AppFramework\\Utility\\SimpleContainer",
			"type": "->",
			"args": [
				"OCA\\Wishlist\\Controller\\WishController"
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
			"line": 431,
			"function": "queryNoFallback",
			"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
			"type": "->",
			"args": [
				"OCA\\Wishlist\\Controller\\WishController"
			]
		},
		{
			"file": "/var/www/html/lib/private/AppFramework/App.php",
			"line": 144,
			"function": "query",
			"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
			"type": "->",
			"args": [
				"OCA\\Wishlist\\Controller\\WishController"
			]
		},
		{
			"file": "/var/www/html/lib/private/Route/Router.php",
			"line": 302,
			"function": "main",
			"class": "OC\\AppFramework\\App",
			"type": "::",
			"args": [
				"OCA\\Wishlist\\Controller\\WishController",
				"index",
				{
					"__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
				},
				{
					"_route": "wishlist.wish.index"
				}
			]
		},
		{
			"file": "/var/www/html/lib/base.php",
			"line": 993,
			"function": "match",
			"class": "OC\\Route\\Router",
			"type": "->",
			"args": [
				"/apps/wishlist/wishes"
			]
		},
		{
			"file": "/var/www/html/index.php",
			"line": 37,
			"function": "handleRequest",
			"class": "OC",
			"type": "::",
			"args": []
		}
	],
	"File": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
	"Line": 115,
	"CustomMessage": "--"
},
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36",
"version": "21.0.0.18"

}

The import block in the controller class:

namespace OCA\Wishlist\Controller;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\AppFramework\Controller;
use OCA\Wishlist\Service\WishService; 
use OCP\AppFramework\Http\DataResponse;
use OCA\Wishlist\Db\Wish;

class WishController extends Controller {

/** @var WishService */
private $service;


/** @var IUserManager */
private $userManager;

/** @var string */
private $userId;

use Errors;

public function __construct(string $AppName, IRequest $request, WishService $service, IUserManager $userManager, $UserId){
     parent::__construct($AppName, $request);
     $this->service = $service;
     $this->userId = $UserId;
     $this->userManager = $userManager;
 }

The WishService class:

<?php
namespace OCA\Wishlist\Service;

use Exception;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;

use OCA\Wishlist\Db\Wish;
use OCA\Wishlist\Db\WishMapper;
use OCA\Wishlist\Service\NotAllowedException;


class WishService {

I compared the code with other projects (like Deck) and can’t find any differences. Can anyone tell me why this breaks without any prior changes to the code? My PHP is very rusty these days…

Thanks in advance!

The problem is constructing WishServer, it fails because the problem is construction WishMapper:

Fix the database interface to the correct casing \OCP\IDBConnection and it will work again

1 Like