C # resx file not working after namespace change

I am working on an existing windows form application. I just need to make a few changes, during these changes I came across a scenario where I also need to rename an existing namespace. Now, renaming this namespace, my project is not running. Although it compiles fine, it breaks into the next line of code

ImageList il = new ImageList(); ImageList = il; il.Images.Add((Image)new Bitmap(GetType(), "Images.ImageFileName.png"));//when this line is executed a dialog box appears and says that "there is no source code available for current location" 

Now that I am new to the .net world, I study this problem and believe that it arises due to changes in namspace. I am also trying to rename the namespace in Resource.Designer.cs but this also did not solve my problem.

+6
source share
5 answers

Thanks to everyone.

I find a solution on my own. The purpose of posting the solution here is that there might be someone else from it. Infact is kind of negligence on my part, because I forgot to change the value of the "Default NameSpace" property, this property contains the old namespace, so my alwasy resource file points to the old namespace

+4
source

try to get rid of this second line, ImageList = il; . what it does is replace the class with an instance of the class. not good.

+3
source

Right-click on Resources.resx , select Properties , find the Custom Tool Namespace , set the required namespace.

Also, why don't you reference your resources in a typed way, like Resources.ResrouceName .

Here is a quick guide to setting resources, so you donโ€™t need to give up and think about namespaces: http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx

+2
source

This specific overload of the bitmap constructor combines the namespace of this type with the name of the resource string and looks for a match in the assembly manifest. So in this case it will be the namespace of your class + ".Images.ImageFileName.png" . I guess this does not exist. Change the Resource.resx namespace by right-clicking on it and selecting properties, rebuild and see if it works now.

0
source

I also ran into this problem. I had to rename the namespace of my application. After that, the designer ignored all the resources, although they appeared after creating the solution and launching the application.

I found that although I renamed the namespace, it was not replaced in Application Properties in the "Default Namespace" text box. I changed the old namespace that was still appearing there with the new namespace, and after that it worked correctly.

0
source

Source: https://habr.com/ru/post/888504/


All Articles