简体   繁体   English

ASP.net Core 1.1.0将文件上传到Azure存储-Visual Studio 2017

[英]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.

相关问题 无法使用Visual Studio 2017将ASP.NET Core Angular项目发布到Azure - Failed to publish ASP.NET Core Angular Project to Azure with Visual Studio 2017 Visual Studio 2017发布asp.net核心 - visual studio 2017 publish asp.net core Visual Studio 2017 Asp.Net Core 项目不会在构建时复制依赖的 dll 文件 - Visual Studio 2017 Asp.Net Core project doesn't copy dependent dll file on build 使用ASP.Net core2在Azure存储中下载文件 - Download file in azure storage using ASP.Net core2 将asp.net核心React-Redux WebApp从VS2017迁移到Visual Studio Code? - Migrate asp.net core React-Redux WebApp from VS2017 to Visual Studio Code? Visual Studio 2017中的ASP.NET Core Angular模板无法使用“ SyntaxError:意外令牌”生成 - ASP.NET Core Angular template in Visual Studio 2017 fails to build with “SyntaxError: Unexpected token” 将Visual Studio Community 2017 Asp.Net Core 2项目部署到远程IIS计算机 - Deploy a Visual Studio Community 2017 Asp.Net Core 2 project to remote IIS machine Visual Studio 2017 不会在 ASP.NET Core MVC 项目中创建新的空 MVC 控制器 - Visual Studio 2017 does not create a new empty MVC controller in ASP.NET Core MVC project 如何在Visual Studio 2017 ASP.NET核心Web应用程序中集成Bootstrap 4? - How to integrate Bootstrap 4 in Visual Studio 2017 ASP.NET Core Web Application? 单击发布为Visual Studio 2017中的ASP.NET Core 2.0项目没有任何作用 - Clicking Publish for an ASP.NET Core 2.0 project in Visual Studio 2017 does nothing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM