Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# resx file not working after changing namespace

I am working on an existing windows form application. I only need to make few modification, during those changes i came across a scenario where i need to rename an existing namespace aswell. Now after renaming that namespace my project is not running. Although it compiles fine but breaks at the following 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 since i am new to .net world so i study this problem and figure that it arises due to change in namspace. I also trying renaming the namespace in the Resources.Designer.cs but it also didn't solve my problem

like image 967
Jame Avatar asked May 19 '11 06:05

Jame


3 Answers

Thanks All.

I find the solution by myself. The purpose of posting solution here is that may be some one else benefit from it. Infact its a sort of carelessness from my side because i forget to change the value of Property "Default NameSpace" this property contains the old namespace that's why my resource file alwasy point to old namespace

like image 144
Jame Avatar answered Oct 03 '22 23:10

Jame


try getting rid of that second line, ImageList = il;. what it's doing is replacing a class with an instance of a class. not good.

like image 42
jcomeau_ictx Avatar answered Oct 04 '22 00:10

jcomeau_ictx


Right click on Resources.resx, select Properties, find Custom Tool Namespace, set the namespace that you need.

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

Here is a quick tutorial how you can setup your resources so you don't have to cast and think about namespaces: http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx

like image 33
Alex Aza Avatar answered Oct 04 '22 00:10

Alex Aza