WinForms Resources, Moved Files

I'm working on a WinForms CLR project and I'm using VS 2022. All was well until I created new folders and moved files - everything was in the base project folder, but then I created lib, include, tests, etc. The directory structure looks like this now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
│   .gitignore
│   gui.h
│   gui.resx
│   MyProject.vcxproj
│   MyProject.vcxproj.filters
│   MyProject.vcxproj.user
│   packages.config
│   README.md
│   resource.aps
│   resource.rc
│
├───images
│       back.png
│       button_build.png
│       button_select_bin.png
│       button_select_lib.png
│       logo.png
│       patch_build.png
│       patch_export.png
│
├───include
│   ├───core
│   │       loader.h
│   │       resource.h
│   │
│   └───gui
│           gui.h
│           gui.resx
│           info.h
│           info.resx
│
├───lib
│       loader.cpp
│
├───res
│       installer_0.cpp
│       installer_1.cpp
│       loader_0.cpp
│       loader_1.cpp
│
├───tests
│       main.cpp
│


I had it working for a time with my main form, gui.h, in the include/gui directory, but after pulling/pushing/merging with a different machine a bunch of times, gui.h/gui.resx are apparently back in the base directory and excluding it and trying to use the other one will throw an exception when I run the program - it throws when trying to do something with resources.

Even a new form that I created inside of the include/gui folder, info.h, doesn't work. It will work with nothing on it, but if I add an image or text with over 200 characters, when I click the link on my main form to open it during runtime, I get the following:


Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.

Could not find any resources appropriate for the specified culture of the neutral culture. Make sure "MyProject.info.resources" was correctly embedded or linked into assembly "MyProject" at compile time, or that all the satellite assemblies required are loadable and fully signed.

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "MyProject.info.resources" was correctly embedded or linked into assembly "MyProject" at compile time, or that all the satellite assemblies required are loadable and fully signed.
   at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at MyProject.info.InitializeComponent() in C:\Users\Admin\source\repos\MyProject\MyProject\include\gui\info.h:line 251
   at MyProject.info..ctor() in C:\Users\Admin\source\repos\MyProject\MyProject\include\gui\info.h:line 20
   at MyProject.gui.link_more_LinkClicked(Object sender, LinkLabelLinkClickedEventArgs e) in C:\Users\Admin\source\repos\MyProject\MyProject\include\gui\gui.h:line 1472
   at System.Windows.Forms.LinkLabel.OnLinkClicked(LinkLabelLinkClickedEventArgs e)
   at System.Windows.Forms.LinkLabel.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Label.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


If everything was still in one folder it would work, but any directories I see in the project file are accurate.. anyone know how I can resolve this?
Last edited on
remove the offending file from the project and put it back in is the first thing I would try.
remove the offending file from the project and put it back in is the first thing I would try.

That is the first thing I tried, unfortunately.

Right now I'm just trying to get around it crashing when I remove gui.h/gui.resx from the base directory and have them in include/gui. The program runs up until this line in the designer-generated code in gui.h:

 
this->button_sb->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button_sb.BackgroundImage")));


'resources' is the culprit. If I remove all images from the form, it succeeds. If I try to step into the line above, the program terminates and compiler says:


vcruntime140d.amd64.pdb contains the debug information required to find the source for the module vcruntime140d.dll

Symbol load:
C:\Users\Admin\source\repos\MyProject\x64\Debug\vcruntime140d.amd64.pdb: Cannot find or open the PDB file.
C:\Windows\System32\vcruntime140d.amd64.pdb: Cannot find or open the PDB file.


Here is the only area in which the word 'resource' appears in my vcxproj file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<ItemGroup>
  <ClInclude Include="include\gui\gui.h">
    <FileType>CppForm</FileType>
  </ClInclude>
  <ClInclude Include="include\core\loader.h" />
  <ClInclude Include="include\core\resource.h" />
  <ClInclude Include="include\gui\info.h">
    <FileType>CppForm</FileType>
  </ClInclude>
</ItemGroup>
<ItemGroup>
  <EmbeddedResource Include="include\gui\gui.resx">
    <SubType>Designer</SubType>
  </EmbeddedResource>
  <EmbeddedResource Include="include\gui\info.resx">
    <SubType>Designer</SubType>
  </EmbeddedResource>
</ItemGroup>
<ItemGroup>
  <ResourceCompile Include="resource.rc" />
</ItemGroup>
<ItemGroup>
  <ClCompile Include="lib\loader.cpp" />
  <ClCompile Include="tests\main.cpp" />
</ItemGroup>


Here are the contents of a folder I didn't include in the original post:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
└───x64
    └───Debug
        │   .NETFramework,Version=v4.7.2.AssemblyAttributes.cpp
        │   .NETFramework,Version=v4.7.2.AssemblyAttributes.obj
        │   gmock-all.obj
        │   gtest-all.obj
        │   MyProject.Build.CppClean.log
        │   MyProject.exe.recipe
        │   MyProject.include.gui.gui.resources
        │   MyProject.include.gui.info.resources
        │   MyProject.log
        │   MyProject.vcxproj.AssemblyReference.cache
        │   MyProject.vcxproj.FileListAbsolute.txt
        │   MyProject.vcxproj.GenerateResource.cache
        │   loader.obj
        │   main.obj
        │   resource.res
        │   vc143.pdb
        │
        └───MyProject.tlog
                CL.command.1.tlog
                Cl.items.tlog
                CL.read.1.tlog
                CL.write.1.tlog
                MyProject.lastbuildstate
                link.command.1.tlog
                link.read.1.tlog
                link.secondary.1.tlog
                link.write.1.tlog
                metagen.read.1.tlog
                metagen.write.1.tlog
                rc.command.1.tlog
                rc.read.1.tlog
                rc.write.1.tlog
                ResGen.command.1.tlog
                ResGen.read.1.tlog
                ResGen.write.1.tlog


Update: Everything works if I move the resx files back into the base directory and edit their locations in the project file. I would like to sort everything in this folder into their own categorized subdirectories, but having the headers where I want them is good enough for now..
Last edited on
see if this helps, then.
Tools-> Options-> Debugging-> Symbols. Select checkbox "Microsoft Symbol Servers"

or try repair the VS install. You can also ensure vs has write permissions to everything, or check that it can't try to write places its blocked.
A lot of the files you showed in both posts are not ones you want to manually mess with, especially the ones in the x64 folder you showed. They are "house-keeping" files created and maintained by the VS IDE.

I suspect the VS created and maintained solution and project files are corrupted and/or not fully updated.

1. Try rebuilding your solution/project:

With your project loaded into the IDE: Build -> Rebuild (name of your project) or Build -> Rebuild Solution.

1a. Clean and rebuild:

Build -> Clean Solution or Build -> Clean (name of your project)

Then build/rebuild your project/solution.

Most time that solves any build issues.

2. Something else to try if step 1/1a didn't work, the manual "stomp on the project until it squeals like a stuck pig...."

With VS not running navigate in Files Explorer to the root of your solution. Where your .sln file resides. There's a hidden folder you need to unhide and delete. In Files Explorer View -> check-mark Hidden items. You should now see a .vs folder. Delete that folder.

Within your project folder delete the x64 folder. The one your showed the second time around.

Do NOT delete your project's 3 .vcxproj files!

Restart the IDE and load your solution/project. Do a build or rebuild, VS should recreate all the "house-keeping" files it needs from scratch.

If either of those attempts didn't work the last resort:

3. Create a new solution/project and copy the files you created over to the new folder. Sort the files into the folder structure you want and then add the existing files to your new project.

Project -> Add Existing Item...

Select the files you want to add to your project.

With the folder structure you want you will had to do this "adding existing items" multiple times.

Once you've added all your files do a solution or project build/rebuild.

If you are still having problems there's probably some issue(s) with your personally maintained files, likely not taking into account your files are now in different folder locations.
I will second that ... was thinking poke at it a time or two more and then start a new project with the source and let the tool figure it out if nothing has worked. But maybe the most efficient thing to do is head that direction sooner rather than later.
I'm of the opinion when problems compiling/linking projects arise in the VS IDE to do a rebuild or clean and rebuild first, most times that clears up the problems.

If that doesn't work start a new solution/project and copy the user created files without piece-mealing individual files. Less aggravating and time-wasting that way.

If THAT latter approach doesn't work "burn it to the ground" and start completely over with a new solution/project, creating new source files from scratch. So one is very attentive to what is being typed.

Keeping the old source files as reference, but not using them in the new project.

But then my experience comes from being a self-taught programming hobbyist.
If you use source control you shouldn't need to manually copy things out or recreate source files manually, and you can tell when something unexpected changed a project or solution file.

I just had a very annoying situation (not Visual Studio, but still related) where building some of the projects caused the project files themselves to change, which made other projects then fail to build. Some weird inter-destructive thing was happening, but reverting the project files to whatever is the latest in the branch you're working on fixes it.

Not that the above would have helped OP's situation, since it was one major, destructive thing that happened all at once. Maybe I would have tried changing just one thing at a time so that I knew exactly what change caused a error.

Everything works if I move the resx files back into the base directory and edit their locations in the project file
So you're saying you had to revert <EmbeddedResource Include="include\gui\gui.resx"> back to not be in its own subfolder? Are you moving the files through Visual Studio's interface, or outside of VS? If it's outside, maybe there's a dangling reference somewhere to the file.

I also recommend using 'findstr' or 'grep'. grep can easily be used recursively with the -r parameter to find every instance of a string, like a file that it can't find that you are still referencing somewhere.
Last edited on
If you use source control

Not everyone uses that, I know for most of my projects I don't. I should be more pro-active. ¯\_(ツ)_/¯

recommend using 'findstr' or 'grep'.

The VS IDE can find or find & replace in the current opened file(s) in the IDE, all the files in the current project opened or not or within all the files in the solution if you have multiple projects grouped together.

Not everyone compiles via the command-line so findstr or grep isn't a easily usable option.
Registered users can post here. Sign in or register to post.