0

I am using Microsoft Visual Studio Community 2019 Preview Version 16.6.0 Preview 1.0, .NET Core 3.1 create WinForm application . I follow this video https://youtu.be/lxbUcU4Q5Fk?t=317

File WindowsFormApp1.csproj

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

</Project>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            StreamReader reader = new StreamReader(asm.GetManifestResourceStream("WindowsFormsApp1.Files.hello.txt"));
            textBox1.Text = reader.ReadToEnd();
        }
    }
}

When click button [Get text] Error:

System.ArgumentNullException: 'Value cannot be null. (Parameter 'stream')'

enter image description here

enter image description here

enter image description here

How to fix it?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Sir Rufo Mar 21 '20 at 05:37
  • no, let's specific – Vy Do Mar 21 '20 at 05:41

1 Answers1

0

Right click on hello.txt in Solution Explorer and in Properties set its build action to Embedded Resource.

weichch
  • 9,306
  • 1
  • 13
  • 25