Custom language switcher block, returning urls problem
I finally found what the problem was.
This code "$type = $this-&gt;getDerivativeId();" was null, and, as a result, this code "$links = $this-&gt;languageManager-&gt;getLanguageSwitchLinks($type, Url::fromRoute($route_name));" could not build the following part of the $links array:

"[language] =&gt; Drupal\language\Entity\ConfigurableLanguage Object
                    (
                        [id:protected] =&gt; en
                        [label:protected] =&gt; English
                        [direction:protected] =&gt; ltr
                        [weight:protected] =&gt; -10
                        [locked:protected] =&gt; 
                        [preSaveMultilingual:protected] =&gt; 
                        [originalId:protected] =&gt; en
                        [status:protected] =&gt; 1
                        [uuid:protected] =&gt; 6c14f789-dcf3-4149-883f-63c29df3e544
                        [isSyncing:Drupal\Core\Config\Entity\ConfigEntityBase:private] =&gt; 
                        [isUninstalling:Drupal\Core\Config\Entity\ConfigEntityBase:private] =&gt; 
                        [langcode:protected] =&gt; en
                        [third_party_settings:protected] =&gt; Array
                            (
                            )

                        [_core:protected] =&gt; Array
                            (
                                [default_config_hash] =&gt; HolYKYAaiuzaHd7bV6FOM0HVbmmEMd3Zq4JAcgW55_4
                            )

                        [trustedData:protected] =&gt; 
                        [entityTypeId:protected] =&gt; configurable_language
                        [enforceIsNew:protected] =&gt; 
                        [typedData:protected] =&gt; 
                        [cacheContexts:protected] =&gt; Array
                            (
                                [0] =&gt; languages:language_interface
                                [1] =&gt; url.site
                            )

                        [cacheTags:protected] =&gt; Array
                            (
                            )

                        [cacheMaxAge:protected] =&gt; -1
                        [_serviceIds:protected] =&gt; Array
                            (
                            )

                        [dependencies:protected] =&gt; Array
                            (
                            )

                    )"


All the above was missing, so the url could not be properly build.
The solution was to add "Derivative" php file for my class, just like the core language module includes both the "core/modules/language/src/Plugin/Block/LanguageBlock.php" and the "core/modules/language/src/Plugin/Derivative/LanguageBlock.php".
Of course, you have to fix the machine names and namespaces if you do something similar.