Visual studio Resource files are being stored as string

Merc 20 Reputation points
2024-10-24T16:15:29.2066667+00:00

I updated to vs2022 17.11.5. In the older vs2022, i was able to add a resource file through project properties. The set up was almost automatic. And when I needed the resource file I just call it using My.resource.[fileName] and get a byte() stream of the file.

Now, i can't add it through the project properties. Instead, I second click the project, I use the 'add new item', then, instead of adding a class file i add a resource file. The 'Resource Explorer' opens up. I click on the red '+' button. For the 'Type' I choose 'File' from the drop down and then choose the actual file using file explorer. However, the files i choose doesn't save as a byte() object. It saves as a string. Even files like PDFs, zips, etc. I tried going into the properties of the resource file and change the type, but that didn't work.

Also, i dont have the ability to add it as a global resource. I can only add it to forms, components, .rsx files, etc.

Any help is appreciated.

Res Explorer

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,903 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,191 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2024-10-24T18:16:08.9133333+00:00

    To work around the limitation, try an alternative. Add the file to your project (not to resources) using Add Existing command. The file will appear in Solution Explorer. Select it, go to its properties, and specify “Build Action: Embedded resource”.

    Then use this code:

    
    Dim stream As Stream = Assembly.GetEntryAssembly().GetManifestResourceStream("MyNamespace.MyFile.ext")
    
    Dim bytes As Byte() = New BinaryReader(stream).ReadBytes(stream.Length)
    
    

    Replace MyNamespace, MyFile and ext with corresponding program namespace, filename, extension. (To clarify the resource names, see the Dim names = Assembly.GetEntryAssembly().GetManifestResourceNames() variable during debugging).


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.