Exit Error 139

im making an audio recorder using NAUDIO but everytime i run it exits with code 139 this my Program.cs
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Data;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;
using NAudio.Wave;

class Program
{
static void Main()
{
Console.WriteLine("Enter To Stop");

var fileName = "recording.wav";

using (var waveIn = new WaveInEvent())
{
waveIn.WaveFormat = new WaveFormat(44100, 1);

using (var waveFileWriter = new WaveFileWriter(fileName, waveIn.WaveFormat))
{
waveIn.DataAvailable += (s, e) =>
{
waveFileWriter.Write(e.Buffer, 0, e.BytesRecorded);
};

waveIn.RecordingStopped += (s, e) =>
{
waveFileWriter.Dispose();
waveIn.Dispose();
};

waveIn.StartRecording();

Console.ReadLine();

waveIn.StopRecording();
}
}

Console.WriteLine($"Recording stopped And Audio saved to {fileName}");
}
}
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Data;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;
using NAudio.Wave;

class Program
{
static void Main()
{
Console.WriteLine("Enter To Stop");

var fileName = "recording.wav";

using (var waveIn = new WaveInEvent())
{
waveIn.WaveFormat = new WaveFormat(44100, 1);

using (var waveFileWriter = new WaveFileWriter(fileName, waveIn.WaveFormat))
{
waveIn.DataAvailable += (s, e) =>
{
waveFileWriter.Write(e.Buffer, 0, e.BytesRecorded);
};

waveIn.RecordingStopped += (s, e) =>
{
waveFileWriter.Dispose();
waveIn.Dispose();
};

waveIn.StartRecording();

Console.ReadLine();

waveIn.StopRecording();
}
}

Console.WriteLine($"Recording stopped And Audio saved to {fileName}");
}
}
and this is my Program.csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" />
</ItemGroup>

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" />
</ItemGroup>

</Project>
1 Reply
Anchy
Anchy•5mo ago
do you have any more information than error code 139, like a stack trace?