0

I am trying to read a file in my resource file (I have changed Build action to Embedded Resource). I get an Argument Null exception...not sure what I am missing?

Imports System.IO
Imports System.Reflection

Dim assembly As Assembly = Assembly.GetExecutingAssembly()
Dim reader As New StreamReader(Assembly.GetManifestResourceStream("File.sym")) ' Argument Null occurs System.ArgumentNullException: 'Value cannot be null. Parameter name: stream'

' Open the file and start reading each line
Do
    Dim mapping As New Mapping()
    line = reader.ReadLine
    If line Is Nothing Then Continue Do
    m = Regex.Match(line, "([^][]*)]")
    n = m.Groups(1).ToString()
    mapping.n = n 
Lord45
  • 65
  • 8
  • I think You have to set that file (`File.sym`) like a `Embedded Resource` under `Build Action` in `Properties`. Then You can read that file but You missing project name, something like this : `Dim reader As New StreamReader(Assembly.GetManifestResourceStream("*YourProjectName*.File.sym"))` – nelek Dec 07 '22 at 17:16
  • @nelek I tried the YourProjectName, same thing. I did change Build Action to `Embedded`, still says Null. – Lord45 Dec 07 '22 at 17:29
  • @OlivierJacot-Descombes, this might be my issue, but have no idea where to start. Need to dive in more. – Lord45 Dec 07 '22 at 17:30
  • @Lord45 `YourProjectName` must replace with name of your project, how you name it when create. `YourProjectName` is just example. For example : `MyProject.File.sym` or `Tst.File.sym` or whatever... – nelek Dec 08 '22 at 05:49

1 Answers1

0

S/O to OlivierJacot-Descombes.

I needed to add the below line;

Dim resourceName = "TraceConverter.File.sym" 'Added line
Dim reader As New StreamReader(assembly.GetManifestResourceStream(resourceName))
Lord45
  • 65
  • 8