LazZiya / XLocalizer

Localizer package for Asp.Net Core web applications, powered by online translation and auto resource creating.
https://docs.ziyad.info
128 stars 14 forks source link

IIS Event Viewer log error: could not find the resource among the resources embedded in the assembly Core 3.1 #8

Closed mohamedryan closed 3 years ago

mohamedryan commented 3 years ago

Hi, first many thanks to you for your efforts.

I have an issue that happens after I publish my project. These errors are shown in the IIS Event Viewer:

Category: XLocalizer.Resx.ResxResourceProvider
EventId: 0
RequestId: 8000004d-0000-e300-b63f-84710c7967bb
RequestPath: /
SpanId: |24337861-4126c121f82e06f5.
TraceId: 24337861-4126c121f82e06f5
ParentId: 
ActionId: 83cffa14-308a-46c3-adf2-312122ec663a
ActionName: /Index

Could not find the resource "EShoping.WebUI.LocalizationResources.ViewLocalizationResource.resources" among the resources "" embedded in the assembly "EShoping.WebUI", nor among the resources in any satellite assemblies for the specified culture. Perhaps the resources were embedded with an incorrect name.

These are my resources:

image

The container class body:

image

I found this exists in the csproj file:

image

The Startup.cs file:

image

I tried to put this line in csproj file, but nothing happened.

<PropertyGroup>
    <EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention
</PropertyGroup>

Could you please check and tell me what should I check and do for this?

Thanks.

LazZiya commented 3 years ago

Hi @mohamedryan

It seems you have something wrong with the resource files properties, can you please right click on the resource file and set its build actions as below:

image

You may check these sample projects with .net 5.0. There is sample project for each resource type (Xml, Db and Resx). And here is a working demo based on Resx project.

The working demo will be available for a limited time only :)

Please let me know if it worked for you.

mohamedryan commented 3 years ago

Hi @LazZiya ,

The file is already made as an embedded resource.

image

I checked the generated DLL file for the resources, and it looks like this:

image

Still cannot find the cause for this.

LazZiya commented 3 years ago

I couldn't reproduce your issue! can you share your repo? also you may try to test with another new project from scratch?

LazZiya commented 3 years ago

Hi @mohamedryan , any updates regarding your problem? Kindly let me know if you still need any help.

mohamedryan commented 3 years ago

@LazZiya I tested a new project, and it works fine and not get any errors, I searched and applied a lot but still gives this error.

LazZiya commented 3 years ago

@mohamedryan , Do you mean that the problem is relevant to the old project only? if so can you share the repo to see it?

mohamedryan commented 3 years ago

@LazZiya Sorry for the late reply, I didn't notice the GitHub notifications.

Yes, the problem applies to the old one only.

For the repo, I made a repo and published my project on it; I invented you to the repo, please accept and see what we can do.

Thanks for your efforts.

LazZiya commented 3 years ago

I'll close this issue since the problem is related to specific configuration in the project and not to XLocalizer, we can continue discussing in the projects repo.

Kind regards, Ziya

LazZiya commented 3 years ago

For the benefit of the community, I'm sharing below the findings of our deep diving in this issue.

Best regards, Ziya


Thank you @mohamedryan for the details,

I believe this is normal behavior, as it is not an actual error, it is just handled to return null in case of the key does not exist, so it will return the value of neutral language or the key itself.

Actually when the key dosen't exists it will return the key itself, but if something went wrong (e.g. if the resource file is missing) so it is an error. But in our case it is more similar to a warning than an error that breaks the app.

And to explain why it looks for neutral resource with no culture; it is the default behaviour of the ResourceManager, first it tries to find the resource in a culture specific file, if not found it will look for the parent culture file, if not found it will look for the neutral file. e.g. lets say that our current culture is ar-AE, the resource manager will look for the text in below files in order:

For localization, ideally it should find the resource in the first culture specific file, because all localized values should be provided in advance. But when the text is not found in one file it will go to the next file, until it looks in the last one which is neutral (culture free) because it is considered as the root parent for that specific file name. Finally, it will throw a System.Resources.MissingManifestResourceException because the neutral resource file dosen't exists.

So XLocalizer will log this as an error, but in production it will not be the case since all keys will be added to the resx file.

I think now we are on a common understanding of the issue.

Notice:

You may use XmlResourceProvider with or without MyMemoryTranslateService to auto add keys and translations during development, and when you are done you can Export XML to RESX and switch to use RESX in production. This way you can make sure all keys are added to the resources.