【发布时间】:2013-09-05 15:53:30
【问题描述】:
我不确定这里发生了什么,它可以通过 Twitter API 进行身份验证。
但是当它到达应该发布到推特的地步时,它会抛出一个StackOverflowException,上面写着:
“System.StackOverflowException”类型的未处理异常 发生在 mscorlib.dll 中
我很困惑。下面的代码是导致并最终导致异常的原因。
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*
}
使用的库是 TweetSharp。
编辑:添加 CallStack 数据
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6b 字节 Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 字节 mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(对象状态)+ 0x6f 字节 mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态, bool preserveSyncCtx) + 0xa7 字节 mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading .ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态, bool preserveSyncCtx) + 0x16 bytes mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态) + 0x41 字节 mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 字节
【问题讨论】:
-
发布
SendTweet方法 -
如果您能够在 Visual Studio 中调试它,请打开 Call Stack 窗口(Ctrl + C , D) 你的答案应该就在那里。您可能有方法
a()调用方法b(),再次调用方法a()(直接或间接通过一种或多种其他方法)。 -
@RichardEv 谢谢!不过老实说,没有太多我可以从中收集到。你能从中得到什么吗?
-
是什么让您认为您发布的代码导致了
StackOverflowException?您是否尝试过在代码中设置断点并单步执行直到发生异常? -
怀疑异常发生在 TweetSharp (github.com/danielcrenna/tweetsharp ?) 可能值得将源代码拉到 TweetSharp,并创建一个调试版本来运行...
标签: c# stack-overflow tweetsharp