![](/img/trans.png)
[英]Failed to publish ASP.NET Core Angular Project to Azure with Visual Studio 2017
[英]ASP.net Core 1.1.0 uploading file to azure storage - Visual Studio 2017
我將項目從Visual Studio 2015導入到Visual Studio 2017中,我有一個上載服務在2015年工作,該服務使用了發布的IFormFile
並上載到Azure存儲中的容器。
我有以下代碼:
public async Task<string> UploadFileToBlob(IFormFile file, string fileName)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AppSettings.AzureStorageConnectionString);
// Create a blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Get a reference to a container
CloudBlobContainer container = blobClient.GetContainerReference(AppSettings.AzureStorageContainer);
// If container doesn’t exist, create it.
await container.CreateIfNotExistsAsync(BlobContainerPublicAccessType.Blob, null, null);
// Get a reference to a blob
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
// Create or overwrite the blob with the contents of a local file
using (var fileStream = file.OpenReadStream()) // file.OpenReadStream())
{
await blockBlob.UploadFromStreamAsync(fileStream);
}
return blockBlob.Uri.AbsoluteUri;
}
我在using (var fileStream = file.OpenReadStream())
的行上收到一條錯誤消息,內容為:
“應該引用模塊'System.Private.CoreLib,版本= 4.0.0.0,區域性=中性,PublicKeyToken = 7cec85d7bea7798e'”
我環顧四周以嘗試找到它,試圖像過去一樣添加一個引用,甚至沒有選擇COM對象的選項?
知道發生了什么嗎?
“應該引用模塊'System.Private.CoreLib,版本= 4.0.0.0,區域性=中性,PublicKeyToken = 7cec85d7bea7798e'”
根據您提到的,它表明未加載System.Private.CoreLib
請嘗試在Startup.cs中使用以下代碼添加它:
public void ConfigureServices(IServiceCollection services)
{
var assembly = typeof(Startup).GetTypeInfo().Assembly;
var assemblies = assembly.GetReferencedAssemblies().Select(x => MetadataReference.CreateFromFile(Assembly.Load(x).Location))
.ToList();
assemblies.Add(MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Private.Corelib")).Location));
services.AddMvc();
}
就我而言,我有類似的問題。 通過將Resharper更新到版本2017.2 EAP 3,它解決了我的問題。 如果您還使用Resharper,請嘗試對其進行更新:
下載並安裝2017.2 EAP 3 https://www.jetbrains.com/resharper/eap/
我上傳文件的代碼:
[HttpPost]
public async Task<IActionResult> UploadFile(IFormFile file)
{
string filePath = "UploadedFiles/" + Guid.NewGuid() + Path.GetExtension(file.FileName);
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
return Json("file uploaded successfully");
}
file.OpenReadStream(); ==>也正常工作
有關信息: https : //youtrack.jetbrains.com/issue/RSRP-464676#u=1494270865373
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.