Как исправить ошибку Unable to cast object of type
При работе с библиотекой YoutubeExplode(https://github.com/Tyrrrz/YoutubeExplode) возникла такая ошибка:
System.InvalidCastException:
"Unable to cast object of type '<OfTypeIterator>d__61`1[YoutubeExplode.Videos.Streams.AudioOnlyStreamInfo]'
to type 'YoutubeExplode.Videos.Streams.AudioOnlyStreamInfo'."
Как я могу ее исправить? Вот код:
using YoutubeExplode;
using IStreamInfo = YoutubeExplode.Videos.Streams.AudioOnlyStreamInfo;
private async void btnDownload_Click(object sender, RoutedEventArgs e)
{
var youtube = new YoutubeClient();
var streamManifest = await youtube.Videos.Streams.GetManifestAsync("bnsUkE8i0tU");
var streamInfo = streamManifest.GetAudioOnly();
if (streamInfo != null)
{
var stream = await youtube.Videos.Streams.GetAsync((IStreamInfo)streamInfo);
await youtube.Videos.Streams.DownloadAsync((IStreamInfo)streamInfo, Path.Combine(LoadDirectory, $"video.mp3") );
}
}