[英]ASP.net Core 1.1.0 uploading file to azure storage - Visual Studio 2017
I imported a project from Visual Studio 2015 into Visual Studio 2017, I had an upload service that worked in 2015 that took a posted IFormFile
and uploaded to a container in Azure Storage. 我将项目从Visual Studio 2015导入到Visual Studio 2017中,我有一个上载服务在2015年工作,该服务使用了发布的IFormFile
并上载到Azure存储中的容器。
I have the following code: 我有以下代码:
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;
}
I'm getting an error on the line using (var fileStream = file.OpenReadStream())
that says: 我在using (var fileStream = file.OpenReadStream())
的行上收到一条错误消息,内容为:
"Module 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' should be referenced" “应该引用模块'System.Private.CoreLib,版本= 4.0.0.0,区域性=中性,PublicKeyToken = 7cec85d7bea7798e'”
I looked around to try to find that, tried to go to add a reference like I have in the past, and there isn't an option to even select COM objects? 我环顾四周以尝试找到它,试图像过去一样添加一个引用,甚至没有选择COM对象的选项?
Any idea what's up? 知道发生了什么吗?
"Module 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' should be referenced" “应该引用模块'System.Private.CoreLib,版本= 4.0.0.0,区域性=中性,PublicKeyToken = 7cec85d7bea7798e'”
According to your mentioned that it indicates that System.Private.CoreLib is not loaded 根据您提到的,它表明未加载System.Private.CoreLib
Please have a try to add it with the following code in the Startup.cs : 请尝试在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();
}
For my case, i had the similar problem. 就我而言,我有类似的问题。 By updating Resharper to the version 2017.2 EAP 3, it solved my problem. 通过将Resharper更新到版本2017.2 EAP 3,它解决了我的问题。 If you're also using Resharper, try to update it : 如果您还使用Resharper,请尝试对其进行更新:
Download & install 2017.2 EAP 3 https://www.jetbrains.com/resharper/eap/ 下载并安装2017.2 EAP 3 https://www.jetbrains.com/resharper/eap/
My code to upload a file : 我上传文件的代码:
[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(); file.OpenReadStream(); ==> is working also without error ==>也正常工作
For info : https://youtrack.jetbrains.com/issue/RSRP-464676#u=1494270865373 有关信息: https : //youtrack.jetbrains.com/issue/RSRP-464676#u=1494270865373
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.