Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type resources does not exist in namespace error

Got another problem. I had almost finished my project but felt like I had to change the namespace of the project. But instead of using refactor --> rename , I selected my namespace, edit --> find and replace and replaced my whole solution with a different namespace (so everywhere in the solution where for example the namespace or text "name1" exists, is now changed into "name2").

But now I get around 16 errors all saying the same thing: "The type or namespace "resources" does not exist in namespace name1".

     this.centerPanel.BackgroundImage = global::login_DragDrop.Properties.Resources.oeftest;

So for example in this line of code (mainly in the designer.cs) resources is colored red?

Any hints on how to fix this?

like image 365
user3644837 Avatar asked May 17 '14 01:05

user3644837


4 Answers

You need to run the code generation on the resource file to get the correct namespace there as well.

Follow these steps:

  • Open the project properties (right click > properties)
    • click the Application section
    • Enter your prefered Default namespace
    • Close and save your properties
  • navigate in the solution explorer to your Resouces.resx file (under Properties)
    • Right-click the Resources.resx file
    • Choose 'Run Custom Tool' (or alt+L)

This runs the code generation for the resource files again. The generated code makes that you have strongly typed access to the values in your resource strings.

like image 67
rene Avatar answered Oct 31 '22 02:10

rene


Run Custom Tool did not work for me. But I found if I added a resource the problem fixed itself.

Follow these steps:

  • Open the project properties (right click > properties)
  • Click the Resources section
  • In the Add Resource drop down select Add Existing File
  • Select any resource file. (I picked an existing image file)
    • At this point my errors disappeared.
  • Select the resource you just added
  • Click Remove Resource (to clean up)
  • Close and save your properties

Late (very) response I know but there you go.

like image 7
mohnston Avatar answered Oct 31 '22 02:10

mohnston


In my case the Resource.Designer.cs file was somehow excluded from project... Clicked on show hidden files (show all files), included it in project with a right-click and it was fixed. Phew..

like image 3
Nick Kovalsky Avatar answered Oct 31 '22 02:10

Nick Kovalsky


You most likely have tried to add another resource file with the same name as an already existing resource. To fix this simply delete the corresponding line in the Resources.resx file, for example you will see two lines that have the same "Data name" :

  <data name="button" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\Resources\button.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>
like image 1
kino Avatar answered Oct 31 '22 04:10

kino