C# Winform:System.ArgumentNullException:';值不能为null。(参数&x27;流&x27;)&x27;
我正在使用Microsoft Visual Studio Community 2019预览版16.6.0预览版1.0、.NET Core 3.1创建WinForm应用程序。我关注这个视频 文件C# Winform:System.ArgumentNullException:';值不能为null。(参数&x27;流&x27;)&x27;,c#,winforms,.net-core,C#,Winforms,.net Core,我正在使用Microsoft Visual Studio Community 2019预览版16.6.0预览版1.0、.NET Core 3.1创建WinForm应用程序。我关注这个视频 文件WindowsFormApp1.csproj <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>WinExe</OutputType>
WindowsFormApp1.csproj
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
单击按钮[获取文本]时出错:
System.ArgumentNullException:'值不能为null。(参数
“流”)
如何修复它?右键单击解决方案资源管理器中的
hello.txt
,并在属性中将其构建操作设置为嵌入式资源这是否回答了您的问题?不,让我们具体谈谈
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();
}
}
}