Skip to content

[BUG] - IAsyncEnumerable not correctly detected in net472 #974

@JustinGrote

Description

@JustinGrote

Continuation of #953 CC @michelebastione

When implementing using a channel in net472, MiniExcel does not detect the IAsyncEnumerable correctly and throws a notImplementException when it goes to GetWriteAdapter instead of GetWriteAsyncAdapter.

If you retarget the below code to net10.0, it works.

Program.cs

using MiniExcelLibs;
static async IAsyncEnumerable<Row> GetRowsAsync()
{
	for (var i = 1; i <= 10; i++)
	{
		await Task.Delay(25);
		yield return new Row(i, $"Item {i}");
	}
}

var outputPath = Path.Combine(Environment.CurrentDirectory, "output.xlsx");

await MiniExcel.SaveAsAsync(outputPath, GetRowsAsync());



public record Row(int Id, string Name);

CSProj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <LangVersion>latest</LangVersion>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MiniExcel" Version="1.44.1" />
    <PackageReference Include="PolySharp" Version="1.16.0" />
    <PackageReference Include="Microsoft.BCL.AsyncInterfaces" Version="10.0.9" />
    <PackageReference Include="System.Threading.Channels" Version="10.0.9" />
  </ItemGroup>

</Project>

Run Result

Unhandled Exception: System.NotImplementedException: The method or operation is not implemented.
   at MiniExcelLibs.WriteAdapter.MiniExcelWriteAdapterFactory.GetWriteAdapter(Object values, Configuration configuration)
   at MiniExcelLibs.OpenXml.ExcelOpenXmlSheetWriter.<WriteValuesAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MiniExcelLibs.OpenXml.ExcelOpenXmlSheetWriter.<CreateSheetXmlAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MiniExcelLibs.OpenXml.ExcelOpenXmlSheetWriter.<SaveAsAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MiniExcelLibs.MiniExcel.<SaveAsAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MiniExcelLibs.MiniExcel.<SaveAsAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Program.<<Main>$>d__0.MoveNext() in C:\Users\justi\Projects\Sandbox\MiniExcelTest\Program.cs:line 5
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Program.<Main>(String[] args)

Likely Problem

var writeAdapterType = typeof(AsyncEnumerableWriteAdapter<>).MakeGenericType(genericArgument!);
writeAdapter = Activator.CreateInstance(writeAdapterType, values, configuration) as IMiniExcelWriteAdapterAsync;
return true;

This code returns false for the IAsyncEnumerable, and is not detecting it correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions