Basic custom app has for Class does not exist error

Hello,

Im building a internal custom app and using the password_policy app as an example of how to code it. Im only need a Event Listener and got $context->registerEventListener(BeforeUserLoggedInEvent::class, BeforeUserLoggedInEventListener::class); in the lib/AppInfo/Applicaton.php like the policy app has and have the file lib/Listener/BeforeUserLoggedInEventListener.php like the policy app as well with correct namespaces and what not, yet on user login I get the following error:

{“reqId”:“XXXXXXXXXXXXX”,“level”:3,“time”:“2021-01-22T18:32:18+00:00”,“remoteAddr”:“X.X.X.X,“user”:”–",“app”:“no app in context”,“method”:“POST”,“url”:"/index.php/login",“message”:{“Exception”:“OCP\AppFramework\QueryException”,“Message”:“Could not resolve OCA\MyCustomInternalApp\Listener\BeforeUserLoggedInEventListener! Class OCA\MyCustomInternalApp\Listener\BeforeUserLoggedInEventListener does not exist”,“Code”:0,“Trace”:[{“file”:"/var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",“l
…
on”:“handleRequest”,“class”:“OC”,“type”:"::"}],“File”:"/var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",“Line”:115,“CustomMessage”:“Could not load event listener service OCA\MyCustomInternalApp\Listener\BeforeUserLoggedInEventListener”},“userAgent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36”,“version”:“20.0.5.2”}

Enabling the app without issue, no other errors and permissions are set correctly, I spent a day and a half trying to figure this out before coming on here. Not sure why its not seeing the file and using it. Can anyone help?

That class or one of its dependencies can’t be loaded by the DI container.

Thanks, but how do I get it to load the class if I have the use to it already

In my Application.php I have:

namespace OCA\aisonetauthapi\AppInfo;

use OCA\aisonetauthapi\Listener\BeforeUserLoggedInEventListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\User\Events\BeforeUserLoggedInEvent;

Can you share a link to the code?

Ya, I can, you can download it here:

https://www.solarsendit.net/dlYwJKLjt3N1kpu9SseDCO

not found. is the code anywhere on github where I can just browse the files?

Yes, here you go sorry about that:

The code looks fine. I don’t see why the class couldn’t be resolved.

I assume you previously redacted the actual class name?!

Would could play a role is the automagic PSR-4 autoloading: Classloader — Nextcloud latest Developer Manual latest documentation. You use your lowercase app id as namespace. I’m not sure if that is right. Try changing all occurences to something like Sisonetauthapi or set the namespace to aisonetauthapi in info.xml as shown in the docs.

1 Like

Yes in here I redacted it.

And you are great thanks! Adding namespace parameter with the value of aisonetauthapi to the info.xml file fixed the issue!

1 Like

Awesome :slight_smile:

FWIW I’m planning to improve the container error messages because they are not very helpful at the moment