Skip to content

Localization not working after changing rootnamespace #2645

Closed

Description

@aspnet-hello

From @mattiaz9 on Tuesday, March 14, 2017 6:34:33 AM

If you specify a default namespace different from the assembly name the localization doesn't work anymore.

Copied from original issue: aspnet/Localization#340

Activity

  1. added this to the 2.1.0-preview2 milestone on Jan 2, 2018
  2. added
    enhancement
    Needs: Design
    on Jan 2, 2018
  3. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @hishamco on Tuesday, March 14, 2017 6:51:02 AM

    @mattiaz9 is it the same of issue #296? if not please clarify your scenario, because localization relay on assembly name, specially ResourceStringLocalizer

  4. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @mattiaz9 on Tuesday, March 14, 2017 7:16:33 AM

    I'm not sure. It worked before updating the project format to the new one in VS 2017.
    The same problem occurs with the sample project in this repository. If I change the default namespace with VS 2017 the localization doesn't work.
    I can't verify with the old VS though.

  5. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @hishamco on Tuesday, March 14, 2017 8:08:46 AM

    I'm still surprising why you changed the default namespace for sample repo?

  6. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @mattiaz9 on Tuesday, March 14, 2017 8:36:30 AM

    Just to test if I could replicate the problem

  7. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @hishamco on Tuesday, March 14, 2017 8:40:35 AM

    IMHO changing this absolutely will affect the generated resource files, so that's why you should care about the namespaces. I saw many issues in the past raised by namespace conflict, so that's why I mentioned the issue #296 in my first comment

  8. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @ryanbrandenburg on Tuesday, March 14, 2017 11:16:26 AM

    When having trouble with resource discovery make sure you've read the localization docs, especially https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization#resource-file-naming.

    To sum up, there are two things you must know before naming a resource, first is the name of the assembly for your project. This is decided by a lot of different factors (name of .csproj file, name of containing folder, properties within the .csproj file etc), which are different between project.json and MSBuild, so the most correct way to find it is to look at the result of typeof(Startup).GetTypeInfo().Assembly.FullName at runtime.
    The second thing to know is the full name of the class the resource is for. If you're looking up a resource for the class Startup in the namespace Localization.Project then it's Localization.Project.Startup.

    Once you know both of these things you can create your resource. You must name your resource the full name of the class, but trim the assembly name from the front if it's there. So in the project Localization.Project a class with full name Localization.Project.Startup would have the resource file Startup.resx, but a class with full name ExternalNamespace.Startup would have a resource file ExternalNamespace.Startup.resx

    If you're still having trouble after double checking these things please upload a sample which reproduces your problem to GitHub for us to review and debug against.

  9. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @hishamco on Tuesday, March 14, 2017 11:18:54 AM

    I'm able to reproduce the issue after modifying the default namespace

    This will let all the resource files to use the newly RootNamespace in the LocalizationSample.csproj.FileListAbsolute.txt, so if I change the default namespace to MyLocalizationSample the French resource for instance will be MyLocalizationSample.My.Resources.Startup.fr-FR.resources instead of LocalizationSample.My.Resources.Startup.fr-FR.resources

  10. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @mattiaz9 on Wednesday, March 15, 2017 4:42:02 AM

    Maybe I'm doing something wrong..
    I made this repo https://github.com/mattiaz9/LocalizationSample
    I used two different naming convention to test it out, but none of them works with a custom default namespace.
    I hope it can help

  11. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @hishamco on Wednesday, March 15, 2017 9:24:59 AM

    Changing the RootNamspace absolutely will cause the bug, but still wondering we need change it?!!
    Anyhow I will look to your sample

    @Eilon can we consider this as bug?

  12. aspnet-hello commented on Jan 2, 2018

    @aspnet-hello
    Author

    From @tmm360 on Wednesday, March 15, 2017 9:31:21 AM

    We need to change it for example when a company has a structured enterprise path on namespace, for example Contoso.MyService.Solution.InternalPath.
    In this example Contoso.MyService.Solution will be the root namespace, but it will not also the assembly's name, that could be "ServiceSolution", for example.

    An other example is when you have a complex solution with modules, where you want to put modules on other sub namespaces of the original project.

  13. 15 remaining items

  14. tmm360 commented on May 28, 2018

    @tmm360

    So how can I use the RootNamespaceAttribute now? Why I can't simply use <RootNamespace>My.Custom.Namespace</RootNamespace> into the project's file? This sound me like a workaround.

    Actually if I set it in project's file I receive this exception: System.Resources.MissingManifestResourceException: 'No manifests exist for the current culture.'

  15. TsengSR commented on May 28, 2018

    @TsengSR

    @tmm360 : See here

    Add

    [assembly: RootNamespace("Alternate.Namespace")]
    

    to your AssemblyInfo.cs (or any other *.cs file).

  16. tmm360 commented on May 28, 2018

    @tmm360

    Thank you! I've solved

  17. joemey commented on Jul 3, 2018

    @joemey

    @ryanbrandenburg
    It would be awesome if this could be added to the current localization docs
    (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization#resource-file-naming.)

    Took me some hours to track this down

  18. hishamco commented on Jul 3, 2018

    @hishamco
    Member
  19. ryanbrandenburg commented on Jul 3, 2018

    @ryanbrandenburg
    Contributor

    I created dotnet/AspNetCore.Docs#7434 to track this work.

  20. added
    Done
    and removed on Aug 8, 2018
  21. added
    area-mvc
    and removed
    area-mvc
    on Nov 7, 2018
  22. chrsas commented on May 24, 2019

    @chrsas
  23. ghost locked as resolved and limited conversation to collaborators on Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

DoneNeeds: Designarea-mvcenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions