运行Azure功能时路径中的字符非法 [英] Illegal character in path when running azure function

查看:40
本文介绍了运行Azure功能时路径中的字符非法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个整天都在工作的天蓝色功能.大约二十分钟前,尝试单击Visual Studio中的运行"按钮时,我开始出现错误.它会成功构建,然后在启动时显示并显示错误,只是指出路径中的非法字符-Visual Studio".我已经检查了git日志,没有进行任何更改,所以我真的不确定是怎么回事.

So I have an azure function that has been working all day. About twenty minutes ago I started getting an error when trying to click the run button in visual studio. it successfully builds and then when it starts it displays and error the just states an 'illegal character in path - Visual Studio'. Ive checked the git logs and no changes have been made so im really unsure whats wrong.

我附上了问题的图片,以尝试说明问题.

Ive attached a gif of the problem to try illustrate the issue.

我真的尽了我所能想到的一切.这是我已采取的所有步骤的清单.

I really have tried everything I can think of. Heres a list of all the steps ive taken.

  • 重启机器
  • 重新克隆仓库
  • 重新安装Visual Studio 2017&2019
  • 删除了appdata文件夹
  • 清除缓存文件
  • 浏览了调试菜单
  • 系统已还原
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Zupa.Products.ProductsService.Models.Messages.V1;

namespace Zupa.ProductFileUploadFunction
{
    public static class FileUploadProcessor
    {
        private const string FunctionName = nameof(FileUploadProcessor);

        [FunctionName(FunctionName)]
        public static void Run(
            [BlobTrigger("%IncomingContainerPath%/{blobFileName}", Connection = "AzureWebJobsStorage")]Stream inputBlob,
            [ServiceBus("%QueueName%", Connection = "QueueServiceBus")]out string outgoingMessage,
            string blobFileName, ILogger log)
        {
            log.LogInformation($"{FunctionName} Processing blob {Environment.NewLine} Name:{blobFileName + Environment.NewLine} Size: {inputBlob.Length} Bytes");
            outgoingMessage = null;

            var (parsedOrganisationId, parsedUploadId) = (Guid.Empty, Guid.Empty);

            var organisationId = GetPartFromString(blobFileName, "/", 0);
            var fileUploadType = GetPartFromString(blobFileName, "/", 1);
            var isRecognisedFileUploadType = Enum.GetNames(typeof(FileUploadType)).Select(name => name.ToLowerInvariant()).Contains(fileUploadType.ToLowerInvariant());
            var uploadId = GetPartFromString(blobFileName, "/", 2);
            var fileName = GetPartFromString(blobFileName, "/", 3);

            var propertyValidation = new Dictionary<string, bool>()
            {
                {
                    nameof(FileUploadDataEventMessage.OrganisationId),
                    string.IsNullOrEmpty(organisationId) || !Guid.TryParse(organisationId, out parsedOrganisationId)
                },
                {
                    nameof(FileUploadDataEventMessage.FileUploadType),
                    string.IsNullOrEmpty(fileUploadType) || isRecognisedFileUploadType
                },
                {
                    nameof(FileUploadDataEventMessage.UploadId),
                    string.IsNullOrEmpty(uploadId) || !Guid.TryParse(uploadId, out parsedUploadId)
                },
                {
                    nameof(FileUploadDataEventMessage.FileName),
                    string.IsNullOrEmpty(fileName)
                }
            };

            foreach (KeyValuePair<string, bool> propertyValidationPair in propertyValidation)
                LogPropertyInErrorState(log, propertyValidationPair.Value, blobFileName, propertyValidationPair.Key);

            var hasInvalidPathParameters = parsedOrganisationId == Guid.Empty || !isRecognisedFileUploadType || parsedUploadId == Guid.Empty || string.IsNullOrEmpty(fileName);

            outgoingMessage = !hasInvalidPathParameters ? JsonConvert.SerializeObject(new FileUploadDataEventMessage()
            {
                OrganisationId = parsedOrganisationId,
                UploadId = parsedUploadId,
                FileUploadType = Enum.Parse<FileUploadType>(PascalCaseWord(fileUploadType)),
                FileName = fileName,
                Timestamp = DateTimeOffset.Now
            }) : null;

            log.LogInformation($"{FunctionName} Processed blob {Environment.NewLine} Name:{blobFileName + Environment.NewLine} Size: {inputBlob.Length} Bytes");
        }

        private static string GetPartFromString(string inputString, string delimiter, int targetIndex)
        {
            var inputStringParts = inputString.Split(delimiter);

            if (inputStringParts.ElementAtOrDefault(targetIndex) != null)
                return inputStringParts[targetIndex];

            return null;
        }

        private static void LogPropertyInErrorState(ILogger log, bool errorValidationCondition, string fileName, string propertyName)
        {
            var errorMessage = errorValidationCondition ?
                $"{FunctionName} Failed to process blob {Environment.NewLine} Name: {fileName + Environment.NewLine} Missing or invalid {propertyName}" : string.Empty;

            if (!string.IsNullOrEmpty(errorMessage))
                log.LogInformation(errorMessage);
        }

        private static string PascalCaseWord(string input) =>
            input.Substring(0, 1).ToUpperInvariant() + input.Substring(1);
    }
}

该功能似乎不是问题,因为团队的其他成员似乎都没有遇到相同的问题并且可以成功运行该功能.因此,我认为这是系统问题.

It doesn't seem to be the issue with the function as the rest of the team doesn't seem to experience the same issue and can successfully run the function. So im assuming its a system issue.

更新:对于遇到此问题的任何人,我终于找到了解决此问题的方法

UPDATE: For anyone experiencing this issue I have finally found a way to fix it

非常感谢您在媒体上的Tsuyoshi Ushio,请按照以下步骤解决问题,似乎是当Azure功能工具文件在%appdata%/local文件夹中处于错误状态时

Thank you so much Tsuyoshi Ushio over on medium, follow the steps below to resolve the issue seems to be when the azure function tools files get in a bad state within the %appdata%/local folder

推荐答案

对于遇到此问题的任何人,我终于找到了解决问题的方法

For anyone experiencing this issue I have finally found a way to fix it

非常感谢您在媒体上的Tsuyoshi Ushio,请按照以下步骤解决问题,似乎是当Azure功能工具文件在%appdata%/local文件夹中处于错误状态时

Thank you so much Tsuyoshi Ushio over on medium, follow the steps below to resolve the issue seems to be when the azure function tools files get in a bad state within the %appdata%/local folder

https://medium.com/@tsuyoshiushio/visual-studio-2017-2019-fails-when-i-create-an-azure-functions-project-89e993ef31f

这篇关于运行Azure功能时路径中的字符非法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆