Hi There: I have 2 projects in a solution. Project A and Project B. B has a reference to A. Thus A uses B's class and functions. B does not have any resource files as it contains all business functions only. A contains all the resource files. I need to use a resource file from An into B. I CAN NOT refer to A in B. I deploy my main project and it has referred to B. But how can I refer to a resource file(of A project) into B project without referencing the A library in B. Thanks in advance
-
The assembly from A will be loaded in the same process as B. As part of the API A exposes pass an `Assembly` reference and A can use that reference when loading resources. – Richard Jul 12 '16 at 15:04
-
could you write a little bit more in code? I have a resource file in A that I want to use in B. But I will not add reference to A. – Abu Alam Jul 12 '16 at 19:16
-
`var resStrm = otherAsm.GetManifestResourceStream(name)` is all you need to load a resource (or other methods on `Assembly`), so all assembly A needs is a reference to the assembly containing the resource. – Richard Jul 13 '16 at 06:06
-
I don't want to ref to the assembly containing the resource. Thx – Abu Alam Jul 14 '16 at 14:48
4 Answers
Wow, I finally found it from searching online.
I Linked the resource file in Project A to Project B.
Right Click Project B and "Add-Existing Item" then Browse the resource file in Project A
(
myresrc-en.resx
and mymyresrc-fr.resx
)
Add a Link for both. Now in Project B
ResourceManager rmg=new ResourceManager("B.myresrc", Assembly.GetExecutingAssembly());
string str1 = rmg.GetString("resxTxt"); // resxTxt is any string in your resx file.
It worked perfectly. Keep original resources in Project A unchanged. These were already Embedded Resource.
Enjoy!

- 58
- 7

- 121
- 1
- 5
You could add a reference to the project that contains the resource file. However, to use the resource file which is generated as an internal class by default (inaccessible in your project if it's under a different namespace), you need to change the access modifier to public. See https://stackoverflow.com/a/4274341/3666333

- 589
- 6
- 15
You could create a separate project C containing the resources that both A and B can use.

- 101
- 1
- 7
-
Hi Mark: B needs just few strings from that resource file in A. Is there any other way but not creating another class C? Is there anything known as calling a resource file by Ref.? – Abu Alam Jul 12 '16 at 15:03
All you need to do is just change this from Internal to public in resource file, and voila, you can access the resources directly in other projects.
no nonsense additional steps.

- 773
- 1
- 10
- 18