After update to vs2022, adding a resource file to my project saves the file as a string

victor marcano 0 Reputation points
2024-10-14T11:53:35.9366667+00:00

I updated to vs2022. In the old vs, 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.etc and get a byte() stream.

Now, i can't add it through the project properties. I use the 'add new item', then instead of choosing a class file i choose a resource file. A new window pops up and i can add a file. However, the file doesn't save as a byte() object. It saves as a string. I tried going into the properties of the resource file but that didn't work.

Any help is appreciated.

Developer technologies Visual Studio Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.5K Reputation points
    2024-10-14T16:31:05.39+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.GetExecutingAssembly().GetManifestResourceNames() variable during debugging).

    0 comments No comments

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.