Symfony InvalidArgumentException when running app/

2019-08-09 05:22发布

问题:

I have been developing a website using Symfony. Everything was good until earlier today I was adding some Fixtures using the DoctrineFixturesBundle and ran the "app/console" command. I received the following error:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
 Symfony\\Bundle\\AsseticBundle\\EventListener\\RequestListener
 is not a valid class name for the "assetic.request_listener" service.

I tried undoing the changes I made to the fixtures to find my mistake and it didn't change. In my infinite wisdom, I decided to try updating my vendors by running "composer update" and it didn't work.

Also, when I run my site in a browser, I get the same error.

I don't know what's going on. Someone please help, any help appreciated.

回答1:

For those who stop by :)

In most cases problem is with class name which has leading \ in front of class name. More info more info



回答2:

Just wanted to let you all know how I fixed it. It's not the most elegant solution but it worked. I downloaded a new company of Symfony, copied over all my bundles, my whole config directory,my composer.json, and my AppKernel.php. It got rid of all my errors, even some cache issues I was getting.



回答3:

For the record, this error is always related to one thing and that's the name of the class is wrong. Either you are specifying the path the class incorrectly, or you spelled the name wrong.

For instance, I got stumped on this one because I accidentally add .php to the class name.



回答4:

Reformat on .xml files gave me same issue. Exactly, reformat the files in a directory instead of a single file, working with PhpStorm.

@abarisone: Problem was in a services.xml file. PhpStorm "reformat" transform (example):

    <parameter key="xxx">Petrus\xx\xx\XHRCoreExceptionListener</parameter>

to:

    <parameter key="xxx">
        Petrus\xx\xx\XHRCoreExceptionListener
    </parameter>

Was hard to find and easy to correct, manually with help of "Local history" Phpstorm's feature.