nenoNaninu / TypedSignalR.Client.TypeScript

TypeScript source generator to provide strongly typed SignalR clients by analyzing C# type definitions.
MIT License
90 stars 9 forks source link

System.ArgumentNullException in setup code #107

Closed Montellese closed 1 year ago

Montellese commented 1 year ago

Hey, thanks a lot for your work. I've already tried Tapper to transpile my DTOs into TypeScript which works great but I'd also like to transpile my SignalR hub. Unforunately I always get the following output when running dotnet tsrts --project myproject.csproj --output generated:

Start loading the csproj of path\to\myproject.csproj.
Create Compilation...
======== Exception ========
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at Tapper.DefaultTypeMapperProvider.AddTypeMapper(ITypeMapper typeMapper)
   at TypedSignalR.Client.TypeScript.App.TranspileCore(Compilation compilation, String outputDir, NewLineOption newLine, Int32 indent, Boolean referencedAssembliesTranspilation, SerializerOption serializerOption, NamingStyle namingStyle, EnumStyle enumStyle, MethodStyle methodStyle, Boolean enableAttributeReference) in /home/runner/work/TypedSignalR.Client.TypeScript/TypedSignalR.Client.TypeScript/src/TypedSignalR.Client.TypeScript.Generator/App.cs:line 101
   at TypedSignalR.Client.TypeScript.App.Transpile(String project, String output, NewLineOption newLine, Boolean assemblies, SerializerOption serializer, NamingStyle namingStyle, EnumStyle enum, MethodStyle method, Boolean attribute) in /home/runner/work/TypedSignalR.Client.TypeScript/TypedSignalR.Client.TypeScript/src/TypedSignalR.Client.TypeScript.Generator/App.cs:line 55

I've reduced my project to the following C# code:

using System.Threading.Tasks;
using TypedSignalR.Client;

namespace MyProject
{
    [Hub]
    public interface IServer
    {
        Task Connect();
    }
}

Do you have any idea what the problem could be. Looking at the exception the problem seems to be that https://github.com/nenoNaninu/TypedSignalR.Client.TypeScript/blob/ea4ef672b51286fcb3840985e7bb43618b8ee12c/src/TypedSignalR.Client.TypeScript/TypeMappers/StreamTypeMapper.cs#L13 results in Assign being null.

Montellese commented 1 year ago

OK I think I figured out what the issue is. My project is targeting .NET Standard 2.0 but System.Collections.Generic.IAsyncEnumerable<> has been introduced in .NET Standard 2.1. So I changed the target framework to .NET Standard 2.1 and then I got the next issue with https://github.com/nenoNaninu/TypedSignalR.Client.TypeScript/blob/ea4ef672b51286fcb3840985e7bb43618b8ee12c/src/TypedSignalR.Client.TypeScript/TypeMappers/StreamTypeMapper.cs#L37 since System.Threading.Channels.ChannelReader<> is not available in .NET Standard 2.1.

What is the minimum supported framework and is there any way to support older frameworks as well?

nenoNaninu commented 1 year ago

The easiest solution is to add the following packages.

<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="System.Threading.Channels" Version="7.0.0" />

However, it is better to work correctly with netstandard2.0, so I will fix this issue.

nenoNaninu commented 1 year ago

This issue was resolved in v1.7.3. Please try it!

Montellese commented 1 year ago

Thanks a lot for the quick response and fix! It works perfectly fine now.