Twitterizer-对象引用未设置为对象的实例

本文关键字:对象 实例 设置 对象引用 Twitterizer- | 更新日期: 2023-09-27 18:26:27

我注意到Twitterizer的一个问题,它一直运行良好,直到我的客户在她的账户中添加了一条包含Photobucket支持的图像的推文。

然后我们开始得到上面的Object引用错误。花了一两个小时才确定是推特引起了这个问题,我现在已经删除了这个问题。但是我该如何解决这个问题呢?

我的代码在下面,这是一个非常基本的解决方案,用于拉时间线:

OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = AccessToken;
tokens.AccessTokenSecret = AccessTokenSecret;
tokens.ConsumerKey = ConsumerKey;
tokens.ConsumerSecret = ConsumerSecret;
try
{
  UserTimelineOptions opts = new UserTimelineOptions();
  opts.IncludeRetweets = false;
  opts.UseSSL = true;
  opts.Count = 5;
  /* Throws Exception -> */ TwitterResponse<TwitterStatusCollection> timeLine =  TwitterTimeline.UserTimeline(tokens, opts);
  uxTweets.DataSource = timeLine.ResponseObject;
  uxTweets.DataBind();
}
catch
{
  uxError.Text = "<p class='"p1'">Twitter isn't configured correctly. Twitter is not responding.</p>";
}

更新了Brian的堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.]
   Twitterizer.Entities.Converter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) +1355
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueProperty(JsonReader reader, JsonProperty property, Object target, Boolean gottenCurrentValue, Object currentValue) +165
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonReader reader, Object target) +476
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id) +702
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) +110
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) +867
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) +92
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, String reference, JsonArrayContract contract) +495
   Newtonsoft.Json.Serialization.<>c__DisplayClass1.<CreateAndPopulateList>b__0(IList l, Boolean isTemporaryListReference) +98
   Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType, Action`2 populateList) +554
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract) +103
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) +61
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) +119
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) +130
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) +94
   Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) +47
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) +105
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings settings) +74
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value) +42
   Twitterizer.Core.SerializationHelper`1.Deserialize(Byte[] webResponseData, DeserializationHandler deserializationHandler) +91
   Twitterizer.Core.TwitterCommand`1.ExecuteCommand() +2867
   Twitterizer.TwitterTimeline.UserTimeline(OAuthTokens tokens, UserTimelineOptions options) +48
   DataComuniqueUtils.Twitter.Page_Load(Object sender, EventArgs e) in C:'Users'Paul Stoker'Documents'Visual Studio 2010'Projects'DataComuniqueUtils'DataComuniqueUtils'Twitter.ascx.cs:41
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Twitterizer-对象引用未设置为对象的实例

我一直有这个问题。将Newtonsoft.json.dll降级为4.3.*为我解决了这个问题。

这是Twitterizer库中的一个新错误。我还没有机会确定原因,但在某些情况下,Twitter API返回的数据结构似乎发生了一些变化(我认为这与实体数据有关)。

或者,这是一个更糟糕的场景:这是JSON.NET库中的一个新错误,Twitterizer使用它自动将JSON数据读取到对象中。