1
votes

I have a solution named 'MyApplication' with two projects:

ProjectA (namespace MyApplication.ProjectA) {.Net Core 2.1} ProjectB (namespace MyApplication.ProjectB) {.Net Core 2.1 Test Project}

ProjectA contains a resource file named 'Messages.resx'.

I have Messages.resx Add As Link in ProjectB and whenever I am reading value from Messages.resx in ProjectB it is throwing System.Resources.MissingManifestResourceException. I don't want to directly reference ProjectA inside ProjectB. Also adding a third library project with Resource file in it and referring it in both ProjectA and ProjectB is not an option. How can I add resource as Add As Link and consume it?

1

1 Answers

0
votes

For example, I have two mvc projects: WebApplication1 and WebApplication3.

And I have a Resource file(MyData.resx) in WebApplication3:

enter image description here

MyData.resx:

enter image description here

Now, based on your needs, I have MyData.resx Add as link in WebApplication1:

enter image description here

Then, I can get the data from the .rexs file in WebApplication1 controller like below:

 public IActionResult Index()
    {
        var rm = new ResourceManager("WebApplication1.Resources.MyData", Assembly.GetExecutingAssembly());
        string username = rm.GetString("Username");
        return View();
    }

Result:

enter image description here

Note: the baseName in the ResourceManager should be the current project namespace.