更新 看起来问题与此有关。我有这段代码要处理:
dynamic facebookResponse = facebookClient.Batch(new FacebookBatchParameter(HttpMethod.Get, "me"), new FacebookBatchParameter(HttpMethod.Get, "me", new { fields = "picture.type(large)" }));
Errr 不知道为什么会这样!
我发现了一些奇怪的行为 HttpWebRequest。
// Send the image to blob storage.
var url = facebookResponse[1]["picture"]["data"]["url"];
byte[] imageBytes;
var request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 5000;
request.ReadWriteTimeout = 20000;
var response = (HttpWebResponse)request.GetResponse();
var validationResults = _imageService.UploadProfilePicture(response, url, newUserId).ToList();
在最后一行它抛出一个错误,'object' does not contain a definition for 'ToList'
但如果我取出最后一行之前的所有行,它将进入函数。
可能的线程问题?
编辑:_imageService 只是通过 Ninject 传递给控制器的依赖项。
这是 UploadProfilePicture 函数:
public IEnumerable<ValidationResult> UploadProfilePicture(Stream s, string fileName, int userId)
{
if (s == null) throw new ArgumentNullException("s");
if (userId <= 0) throw new ArgumentNullException("userId");
if (s.Length <= 0)
{
yield return new ValidationResult("", GlobalResources.FileContainsNoContent);
yield break;
}
var maxProfilePictureSize = int.Parse(ConfigurationManager.AppSettings[ConfigurationManagerConstants.BlobMaxProfilePictureSize]);
if (s.Length > maxProfilePictureSize)
{
yield return new ValidationResult("", string.Format(GlobalResources.ProfilePictureMustBeNoGreaterThan,
ConfigurationManager.AppSettings[ConfigurationManagerConstants.BlobMaxProfilePictureSizeFriendlyText]));
yield break;
}
const string defaultExtensionType = ".jpg";
var container = GetCloudBlobContainer(ConfigurationManager.AppSettings[ConfigurationManagerConstants.BlobImageContainerName]);
var uniqueBlobName = string.Format(ConfigurationManager.AppSettings[ConfigurationManagerConstants.BlobUserProfilePicturePath], userId, defaultExtensionType);
var blob = container.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = "image/jpeg";
var uploadImageExtension = Path.GetExtension(fileName);
if (!string.IsNullOrWhiteSpace(uploadImageExtension) && !uploadImageExtension.Equals(defaultExtensionType, StringComparison.InvariantCultureIgnoreCase))
{
using (var ms = new MemoryStream())
{
ImageBuilder.Current.Build(s, ms, new ResizeSettings("format=jpg"));
ms.Seek(0, SeekOrigin.Begin);
blob.UploadFromStream(ms);
}
}
else
{
blob.UploadFromStream(s);
}
}