TweetSharp with Win8.1 C# got 3 errors, need help


  • I need help guys, thanks.

    Error 1 The type 'System.Net.HttpStatusCode' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
    Error 2 Operator '==' cannot be applied to operands of type 'System.Net.HttpStatusCode' and 'System.Net.HttpStatusCode'
    Error 3 The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.

    using System.Net;

           async void  MainPage_Loaded(object sender, RoutedEventArgs e)

                if (NetworkInterface.GetIsNetworkAvailable())
                    //Obtain keys by registering your app on https://dev.twitter.com/apps
                    var service = new TwitterService("my key", "my secret");
                    service.AuthenticateWith("access token", "acess token");

                    //ScreenName is the profile name of the twitter user.
                    service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions() { ScreenName = "the_appfactory" }, (ts, rep ) =>
                        if (rep.StatusCode == System.Net.HttpStatusCode.OK)
                            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => 
                            { tweetList.ItemsSource = ts; 


                    // MessageBox.Show("Please check your internet connestion.");
                    MessageDialog dialog = new MessageDialog("unable to synthesize text");
                    await dialog.ShowAsync();


    Thursday, November 20, 2014 1:49 AM

All replies

  • The first error sounds like you're trying to use a library that is built against .Net Framework 2.0. You can use only libraries built against the .Net Core Framework in Windows Store apps. See .NET for Windows Runtime apps

    The second may be a cascading error from the same thing.

    The third error contains the solution in its text: mark the lambda expression with the 'async' modifier.

    Thursday, November 20, 2014 2:56 AM
  • Hi Rob,

    Thank you.

    Maybe TweetSharp is old version. But I can't find any newer version. also I saw it reply on Hammock and Newtownsoft.Json.

    Do you think, Win8.1 provides all the things needed, and no need to use TweetSharp/Hammock/Newtownsoft?

    can you point some resources or sample code to build universal Apps with Win8.1 to access Tweet API


    Thursday, November 20, 2014 3:46 AM
  • I cannot comment on 3rd party toolkits.

    You should be able to call Twitter's REST API with Windows.Web.Http.HttpClient. See How to connect to an HTTP server using Windows.Web.Http and interpret JSON with Windows.Data.Json. See Using JavaScript Object Notation (JSON)

    Thursday, November 20, 2014 6:12 AM
  • Hi rob, thank you again.

    I read the first link you provided.

    System.Net.Http.HttpClient in the System.Net.Http namespace for C# and VB.
    Note  Not supported on Windows Phone.
    if it is not for Windows Phone, then which will support, store app, desktop and phone.

    or should implement them separately. How?

    Thursday, November 20, 2014 3:58 PM
  • Windows.Web.Http.HttpClient can be used from Windows Store, Windows Phone, and desktop apps:

    Minimum supported client

    Windows 8.1 [Windows Store apps, desktop apps]

    Minimum supported server

    Windows Server 2012 R2 [Windows Store apps, desktop apps]

    Minimum supported phone

    Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

    Thursday, November 20, 2014 5:24 PM
  • Hi Rob,

    How to handle oAuth with Windows.Web.Http, or need System.Net.Http?

    I do find some thing, but a little old. http://blogs.msdn.com/b/henrikn/archive/2012/02/16/extending-httpclient-with-oauth-to-access-twitter.aspx. 

    Friday, November 21, 2014 4:10 AM
  • For OAuth use the WebAuthenticationBroker See the Web authentication broker sample

    The link you posted is not for a Windows Runtime app.

    Friday, November 21, 2014 4:32 AM
  • Hi Rob,

    Hope you had a very good weekend. Thank you for your help.

    Why the sample solution is implemented with mixed C++ and C#? for demonstration purpose or C# has difficulty to implement AuthFilters?

    Monday, November 24, 2014 4:40 PM
  • Hi Rob,

    I need your help. the Web Authentication broker sample got error on line 279

    string GetResponse = await httpClient.GetStringAsync(new Uri(TwitterUrl));

    in Scenario2_oAuthTwitter.xaml.cs

    at debug breakpoint 279 line: the value of  TwitterUrl


    System.Exception: Unauthorized (401).

    Response status code does not indicate success: 401 (Authorization Required).
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at WebAuthentication.Scenario2.<GetTwitterRequestTokenAsync>d__25.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at WebAuthentication.Scenario2.<Launch_Click>d__4.MoveNext()

    Could you please help that? thanks

    Thursday, November 27, 2014 2:48 AM