Bob2004
Bob2004

Reputation: 31

Thrift in .NET Core - Generated C# Code does not compile

I am trying to use Thrift in a .NET Core project, but for some reason the C# code generated by the Thrift compiler does not work.

I have created a very simple .thrift file to use as a test, which looks like this:

namespace netcore Management

service ManagementService {
    void Ping()
}

I have put this in an empty class library (which my other projects will depend on), and have added the following code to my .csproj file to compile it:

<Target Name="PreBuild" BeforeTargets="_GenerateRestoreProjectSpec;Restore;Compile">
    <Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
        <Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
    </Exec>
    <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r management.thrift" />
</Target>

This appears to work correctly, and a ManagementService.cs file is created in my project containing the auto-generated code.

However, this auto-generated code does not compile! When I try, MSBuild throws these errors:

The type or namespace name 'Ping_args' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'Ping_result' could not be found (are you missing a using directive or an assembly reference?)

Looking through the code myself, it does indeed appear that these two variables are not declared anywhere. Could anyone tell me why this might be? Is there a problem with my .thrift file, perhaps?

Upvotes: 2

Views: 845

Answers (1)

Jake
Jake

Reputation: 1334

Seems to be caused by having both union and hashcode. -gen netcore:wcf,union,serial,hashcode is generating as Ping_args when the type is PingArgs.

Removing either gets rid of that cast.

Upvotes: 1

Related Questions