0

Okay - I'm confused.

If I have an embedded resource file called light.sms.txt, then it is not embedded, but if I change it to light.sms1.txt, then it is embeded ... emm .. why?

Here's what I do...

  1. Create a new WinForm project
  2. Add a text file called light.sms.txt and change build action to Embedded resource
  3. Paste this code in Form1 ...
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Static embededResources As String() = GetType(Form1).Assembly.GetManifestResourceNames()
    MsgBox(embededResources.Length.ToString)
End Sub
  1. Run the app - the result is 3
  2. Change the embbeded filename to light.sms1.txt
  3. Run the app - the result is now 4

Why doesn't "light.sms.txt" get embedded?

MojoDK
  • 4,410
  • 10
  • 42
  • 80
  • I have tried your code and first it did not show up. But after **Cleaning** and **Building** it worked with both filenames. – Code Pope May 01 '20 at 10:57
  • I've tried cleaning and rebuild - still doesn't show up. This is wierd. – MojoDK May 01 '20 at 11:00
  • One thing confirmed, only `.sms` tag names aren't showing up. I've tried @CodePope's trick, that didn't work. I've tried creating a new project and **this time**, I created `new.txt` and assigned to **Embedded resource**, it showed up, but as soon as I renamed it to `light.sms.txt`, it failed. Lastly when I replaced `.sms` to `-sms` and `.smss` (for testing), it worked. It's a weird error. I'm recommending you to rename the file instead. – Rohan Bari May 01 '20 at 11:04
  • It's a problem to rename files - I'm adding 7,000+ files (Fontawesome) and it woul be a nightmare to manage renaming files that does not work. – MojoDK May 01 '20 at 11:06
  • I have observed similar behavior in the following thread: https://stackoverflow.com/questions/21637830/getmanifestresourcestream-returns-null#answer-27851799 – Code Pope May 01 '20 at 11:06
  • Have you checked on how the file is represented in the .vbp file? It might be that Visual Studio is getting confused, but you can hand-edit the .vbp file to fix the problem. You can right-click on the project, choose "Unload", then right-click again, and choose "Edit" to load it in Visual Studio. – Craig May 01 '20 at 13:25

1 Answers1

0

For debugging purposes, you can use the following code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim getName As String

    Static embededResources As String() = GetType(Form1).Assembly.GetManifestResourceNames()
    For Each index In embededResources
        getName += index + vbCrLf
    Next

    MsgBox(getName)
End Sub

You'll get to know that when the filename is light.sms.txt as embedded resources, it doesn't adds it to the embeddedResources array. But when you changes the filename, it shows up and counts +1 value.

The above code's output (before name change vs. after name change):

Before      After

That's the reason of it. You may replace the file name to light-sms.txt instead.

Rohan Bari
  • 7,482
  • 3
  • 14
  • 34
  • @MojoDK I'm not sure about that, you may remove the "sms" tag. I've just seen it works perfect without `sms`. Better replace the `light.sms.txt` to `light-sms.txt` – Rohan Bari May 01 '20 at 10:56