S
S
Sergey Karbivnichy2019-02-12 12:02:35
.NET
Sergey Karbivnichy, 2019-02-12 12:02:35

How to access resources from a dll class library in C#?

Hello! I haven't been able to figure it out since last night. Created a WinFroms application, then added an empty resource file to the project. I added a picture to the resource file and I get the picture while the application is running like this:
pictureBox1.Image = Resource1.TestImage;
But if you create a class library, then ide does not see the Resource1.resx file. Tried like this:
global::library
but the ide shows that the project only has the "MyClass" class.
Why do I need it? I am writing a plugin-enabled program. From the plugin (dll), in addition to methods, images are also exported (to add buttons to the toolbar in the main program). I used to do this (in a plugin):

public Image SetToolBarIcon()
    {
      return Image.FromFile("image.jpg");
    }

But the problem is that the images must be in the same folder as the plugin, which is not convenient.
I read that there is a ResourceManager, but I'm not sure yet that this is what I need.
Still, the question is why it is impossible to access resources from the library with such a simple method?
5c628b84d24a4559004173.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shai_hulud, 2019-02-12
@hottabxp

or add the attribute InternalsVisibleToAttribute to the Library for the assembly .
or make the Resource1 resource class public, to do this, change the Custom Tool from ResXFileCodeGenerator to PublicResXFileCodeGenerator in the file properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question