Search code examples
c#thrift

Type or namespace name TSocket could not be found apache thrift C# Visual Studio 2019


Screenshot of installed thrift package and Thrift.dll reference:

Screenshot of installed thrift package and Thrift.dll reference

I am trying to create a simple thrift client in Visual Studio 2019 using C#. I have generated the c# thrift bindings and everything else. However, I get "Type or namespace name "TSocket" could not be found". I have no other errors. Here is a snippet from my setup code:

// imports, namespaces
using System;
using System.Net;
using Thrift;
using Thrift.Transport;
using Thrift.Protocol;
  
TTransport socket1 = new TSocket("hostname", port);
TTransport transport = new TFramedTransport(socket1);
                
(more stuff .....)

I have no other issues with other references to thrift modules within the client. It just can't find "TSocket" somehow. I am super new to c# and thrift.

I am using thrift 0.14.1 and have installed it using the NuGet packages add-on Visual Studio 2019.

What could be the problem? Thanks. screenshot of error

After looking at, it seems "TSocket" is not even listed under Transport as you can see in the screenshot below. screenshot of available modules under Thrift Transport


Solution

  • Thrift 0.14 changed some names and the nested namespace structure. What was Thrift.Transport.TSocket is now Thrift.Transport.Client.TSocketTransport. See if swapping that fixes it.

    If not check your project ref to the Thrift lib. Something like this may help (quoting "The Programmer's Guide to Apache Thrift"):

    "To add the C# Apache Thrift library reference, right-click the References item in the project in the Solution Explorer and choose “Add Reference”. Next use the “Browse...” button to locate the Thrift.dll in thrift/lib/csharp/src/bin/Debug (or wherever). Make sure that there is a check next to the Thrift.dll entry in the Reference Manager dialog and then click OK. After a brief pause Intelisense errors should clear."

    ... or using the package manager:

    "To add a Thrift.dll reference you can simply run the PackageManager install command:

    PM> Install-Package -Prerelease ApacheThrift -ProjectName <your proj name here>
    
    'ApacheThrift 1.0.0-dev' already installed.
    Adding 'ApacheThrift 1.0.0-dev' to tradeServer.
    Successfully added 'ApacheThrift 1.0.0-dev' to tradeServer.
    "