Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I receiving this StackOverflowException?

I'm not sure what's going on here, it authenticates with the Twitter API just fine.

But when it gets to the point where it should post to twitter, it throws a StackOverflowException that says:

An unhandled exception of type 'System.StackOverflowException' 
occurred in mscorlib.dll

I'm pretty baffled. The code below is what leads up to and ultimately causes the exception.

    void StartValidation()
    {
        Console.Clear();
        //Start Status thread
        var status = TextAndUi.GetStatisThread();
        status.Start("Validating");

        //Check for Messages
        var tweetAndSenderData = Imap.GetUnreadMessageAndSender();

        if (tweetAndSenderData != null)
        {
            //Authurize connection and app
            var authenticate = new Authenticate();
            var tweetApp = authenticate.CreateClient();

            //End thread
            status.Abort();
            Console.WriteLine("Validated!");
            Console.Clear();

            //Post tweets
            PostContent("test", tweetApp);

            //Delete messages
            Imap.DeleteMessages();
        }
        else
        {
            //End thread
            status.Abort();
            TextAndUi.ShowSomethingToTheUser("The box is empty, or TTT could not secure a connection", true);
        }
    }

    void PostContent(string myTweet, TwitterService tweetApp)
    {
        if (TextAndUi.MessageIsSuitableLength(myTweet))
        {
                PostTweet(tweetApp, myTweet);
        }
    }

    void PostTweet(TwitterService tweetApp, string tweet )
    {
        var tweetOptions = new SendTweetOptions() {Status = tweet};

        tweetApp.SendTweet(tweetOptions); /*The line that throws the exception*
    }

The library being used is TweetSharp.

Edit: Added CallStack Data

mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6b bytes   
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 bytes  
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x6f bytes   
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes   mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes 
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x41 bytes    
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes   
like image 224
Frostytheswimmer Avatar asked Sep 05 '13 15:09

Frostytheswimmer


People also ask

What causes StackOverflowException?

A StackOverflowException is thrown when the execution stack overflows because it contains too many nested method calls. using System; namespace temp { class Program { static void Main(string[] args) { Main(args); // Oops, this recursion won't stop. } } }

What causes stack overflow C#?

The most-common cause of stack overflow is excessively deep or infinite recursion, in which a function calls itself so many times that the space needed to store the variables and information associated with each call is more than can fit on the stack. An example of infinite recursion in C.


1 Answers

I had the same problem and was able to resolve it. For me, the problem occurred because on Twitter, I had only given my application read-access. To write a tweet from your code, your application must be registered as read/write on twitter.

To do this, I had to first revoke the application from the twitter account I was using it with. Then, I changed the application on dev.twitter so that it was read/write. I then generated a new access token and was able to send tweets from my code.

Hope that helps.

like image 151
Greg B Avatar answered Sep 20 '22 12:09

Greg B