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')'
How to fix it?
右键单击解决方案资源管理器中的hello.txt
并在属性中将其构建操作设置为Embedded Resource 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.