C#Azure MediaServices上传文件会引发错误

我正在使用MVC4testing项目来尝试将文件上载到Azure媒体服务。

我可以创build我的CloudMediaContext罚款。 我也可以创build一个IAsset,并在其中创build一个IAssetFile。 但是,当我尝试上传一个新的文件,我得到以下exception:

Server Error in '/' Application. Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=3.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 

我不确定这个错误是否在MVC4中,不能从自己的directoy上传文件? 根据错误,我有一些缺less的引用或程序集,但我唯一添加的是Azure.MediaServices,它安装了Azure MediaServices .NET SDK的NuGet包…

这是上传的HomeController代码:

 [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { string localStorage = Server.MapPath("~/UploadedMedia"); string uploadedFileName = file.FileName; if (!Directory.Exists(localStorage)) Directory.CreateDirectory(localStorage); file.SaveAs(string.Format(@"{1}\{0}", file.FileName, localStorage)); _mediaServicesContext = new MediaServicesContext(); _mediaServicesContext.UploadFile(string.Format(@"{1}\{0}", file.FileName, localStorage)); return View(new UploadModel() { FileName = uploadedFileName, Post = true, Result = true }); } 

这是我的MediaServices类(做这个工作)

 public class MediaServicesContext { #region ATTRIBUTES private const string MEDIACONTEXTNAMEKEY = "MediaServiceAccountName"; private const string MEDIACONTEXTPASSKEY = "MediaServiceAccountAccessKey"; private const string MEDIASTORAGENAMEKEY = "StorageAccountName"; private const string MEDIASTORAGEPASSKEY = "StorageAccountAccessKey"; private readonly CloudMediaContext _mediaContext; #endregion #region CTORS public MediaServicesContext() { _mediaContext = new CloudMediaContext(accountName: ConfigurationManager.AppSettings[MEDIACONTEXTNAMEKEY], accountKey: ConfigurationManager.AppSettings[MEDIACONTEXTPASSKEY]); } #endregion #region PROPERTIES public CloudMediaContext MediaContext { get { return _mediaContext; } } #endregion #region METHODS public void UploadFile(string path) { // Create a .NET console app // Set the project properties to use the full .NET Framework (not Client Profile) // With NuGet Package Manager, install windowsazure.mediaservices // add: using Microsoft.WindowsAzure.MediaServices.Client; var uploadFilePath = path; var context = _mediaContext; var uploadAsset = context.Assets.Create(Path.GetFileNameWithoutExtension(uploadFilePath), AssetCreationOptions.None); var assetFile = uploadAsset.AssetFiles.Create(Path.GetFileName(uploadFilePath)); assetFile.Upload(uploadFilePath); } #endregion } 

出于某种原因,下面解决了我的问题。

在NuGet PackageManager控制台中,我输入以下内容:

 PM> Install-Package WindowsAzure.Storage 

这似乎已经更新了Microsoft.WindowsAzure.Storage依赖项,并允许我的程序正常工作。 非常奇怪,微软。