Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 匿名托管的DynamicMethods程序集:无法隐式转换类型';字符串';至';int';_C#_Azure Functions_Azure Http Trigger - Fatal编程技术网

C# 匿名托管的DynamicMethods程序集:无法隐式转换类型';字符串';至';int';

C# 匿名托管的DynamicMethods程序集:无法隐式转换类型';字符串';至';int';,c#,azure-functions,azure-http-trigger,C#,Azure Functions,Azure Http Trigger,我正在开发一个AZURE函数。该函数的目的是 计算模块的状态:失败、允许通过、通过或区分通过。当我运行代码时,我得到了这个错误。我在mark处得到了一个错误,因为它是一个整数 Executed 'Function1' (Failed, Id=90c68ac4-4bc1-4446-9ad4-2b15e8ea8a00, Duration=145230ms) System.Private.CoreLib: Exception while executing function: Function1. A

我正在开发一个AZURE函数。该函数的目的是 计算模块的状态:失败、允许通过、通过或区分通过。当我运行代码时,我得到了这个错误。我在mark处得到了一个错误,因为它是一个整数

Executed 'Function1' (Failed, Id=90c68ac4-4bc1-4446-9ad4-2b15e8ea8a00, Duration=145230ms)
System.Private.CoreLib: Exception while executing function: Function1. Anonymously Hosted DynamicMethods Assembly: Cannot implicitly convert type 'string' to 'int'.
班级:

class MarkEntry
{
    public string StudentNumber { get; set; }
    public string Name { get; set; }
    public int Mark { get; set; }
    public string Module { get; set; }
}
}

Azure函数接受4个输入,并检查学生是否通过了允许的考试:

    [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            MarkEntry obj = new MarkEntry();
            string responseMessage ="";
            string respmaessage="";
            string result="";
            log.LogInformation("C# HTTP trigger function processed a request.");

            obj.StudentNumber = req.Query["studentnumber"];
           obj.Name = req.Query["name"];
           obj.Module = req.Query["module"];
            obj.Mark =Convert.ToInt32(req.Query["mark"]);


            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            obj.StudentNumber = obj.StudentNumber ?? data?.name;
            obj.Name = obj.Name ?? data?.name;
            obj.Module = obj.Module ?? data?.name;
           obj.Mark = obj.Mark.ToString() ?? data?.obj.Mark.Tostring();







            if (string.IsNullOrEmpty(obj.StudentNumber))
            {
                respmaessage = "Enter a student number";
                return new OkObjectResult(respmaessage);

            }


            if (string.IsNullOrEmpty(obj.Name))
            {
                respmaessage = "Enter a student Name";
                return new OkObjectResult(respmaessage);

            }
         
            
            if (string.IsNullOrEmpty(obj.Module))
            {
                respmaessage = "Enter Student Module";
                return new OkObjectResult(respmaessage);

            }


            if (obj.Mark<49)
            {
                result = "Condoned Pass";

            }

            responseMessage = string.Format($"Student Number: {obj.StudentNumber}" + "\n" +
$"Student Name: {obj.Name}" + "\n" + $"Student Mark: {obj.Mark}" + "\n" +
$"Student Module: {obj.Module}" + "\n" + $"Student Result: {result}"
                );
              

            return new OkObjectResult(responseMessage);

        }
    }
[FunctionName(“Function1”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
MarkEntry obj=新的MarkEntry();
字符串响应消息=”;
字符串respmessage=“”;
字符串结果=”;
LogInformation(“C#HTTP触发器函数处理了一个请求。”);
obj.StudentNumber=请求查询[“StudentNumber”];
对象名称=请求查询[“名称”];
对象模块=请求查询[“模块”];
obj.Mark=Convert.ToInt32(请求查询[“Mark”]);
string requestBody=等待新的StreamReader(req.Body).ReadToEndAsync();
动态数据=JsonConvert.DeserializeObject(requestBody);
obj.StudentNumber=obj.StudentNumber??数据?.name;
对象名称=对象名称??数据?名称;
对象模块=对象模块??数据?名称;
obj.Mark=obj.Mark.ToString()?数据?.obj.Mark.ToString();
if(string.IsNullOrEmpty(obj.StudentNumber))
{
respmessage=“输入学生编号”;
返回新的OkObjectResult(响应消息);
}
if(string.IsNullOrEmpty(obj.Name))
{
respmessage=“输入学生姓名”;
返回新的OkObjectResult(响应消息);
}
if(string.IsNullOrEmpty(对象模块))
{
respmessage=“进入学生模块”;
返回新的OkObjectResult(响应消息);
}

if(obj.Mark类
MarkEntry
具有定义为整数类型的
Mark
属性。在azure函数中,我们实例化该类

MarkEntry obj=newmarkentry();

然后在函数的第13行左右

obj.Mark=obj.Mark.ToString()?数据?.obj.Mark.ToString();

看起来我们正试图给这个整数分配一个字符串值。
不确定这是否可行?

行转换.ToInt32(请求查询[“标记]);似乎是导致问题的原因。检查您在请求查询[“标记”]中收到了什么。请求查询[“标记”]下收到了一个整数