Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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# 在Azure Webjobs中使用MobileServiceContext时引发System.NullReferenceException异常_C#_Asp.net_.net_Azure_Azure Mobile Services - Fatal编程技术网

C# 在Azure Webjobs中使用MobileServiceContext时引发System.NullReferenceException异常

C# 在Azure Webjobs中使用MobileServiceContext时引发System.NullReferenceException异常,c#,asp.net,.net,azure,azure-mobile-services,C#,Asp.net,.net,Azure,Azure Mobile Services,我正在Azure应用程序服务中使用移动应用程序,并且正在运行webjob。问题是webjob中出现错误 Microsoft.Azure.WebJobs.Host.FunctionInvocationException:Microsoft.Azure.WebJobs.Host.FunctionInvocationException:Exception执行函数时异常:Functions.ProcessQueueMessage-->System.NullReferenceException:Objec

我正在Azure应用程序服务中使用移动应用程序,并且正在运行webjob。问题是webjob中出现错误

Microsoft.Azure.WebJobs.Host.FunctionInvocationException:Microsoft.Azure.WebJobs.Host.FunctionInvocationException:Exception执行函数时异常:Functions.ProcessQueueMessage-->System.NullReferenceException:Object reference未设置为对象的实例。在d:\a\1\s\testdev\WebJob create缩略图\Functions.cs中的WebJob\u create缩略图.Functions.ProcessQueueMessage(缩略图缩略图,TextWriter日志):Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker`1.InvokeAsync中lambda\u方法(闭包,函数,对象[])的第35行在Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.d_uu0.MoveNext()---从引发异常的上一个位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务任务)在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务任务任务)在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__31.MoveNext()---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)上从引发异常的上一个位置开始的堆栈结束跟踪在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__2c.MoveNext()---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)上从引发异常的上一个位置开始的堆栈结束跟踪Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext()---内部异常堆栈跟踪的结尾---在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d_13.MoveNext()中的System.Runtime.CompilerServices.TaskWaiter.ValidateEnd(任务任务任务)处的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处的System.Runtime.ExceptionDispatchInfo---从引发异常的上一个位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d_1.MoveNext()上

几乎所有时候都会发生错误,但有时webjob在不更改任何代码的情况下运行良好。 此外,当错误发生时,“Functions.cs:line 35”和第35行在以下代码中“using(MobileServiceContext=new MobileServiceContext())”

public static void ProcessQueueMessage([QueueTrigger("createthumbnailqueue")]  Thumbnail thumbnail, TextWriter log)
{
    log.WriteLine("userId :{0} + thumbnailURL : {1}", thumbnail.Id, thumbnail.ThumbnailUrl);
    Uri thumbnailUri = new Uri(thumbnail.ThumbnailUrl);
    if (thumbnailUri.Host == _storageURLHost)
    {
            using (MobileServiceContext context = new MobileServiceContext())
                {
…
MobileServiceContext是移动应用程序模板项目中的默认上下文,从webjob引用。 MobileServiceContext如下所示

namespace test.Models
{
    public class MobileServiceContext : DbContext, IMobileServiceContext
    {
        private const string connectionStringName = "Name=MS_TableConnectionString";

        public MobileServiceContext() : base(connectionStringName)
        {
        }

        public DbSet<Comment> Comments { get; set; }
        public DbSet<Movie> Movies { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Add(
                new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
                    "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
        }
    }
}
namespace test.Models
{
公共类MobileServiceContext:DbContext、IMobileServiceContext
{
private const string connectionStringName=“Name=MS\u TableConnectionString”;
public MobileServiceContext():基(connectionStringName)
{
}
公共DbSet注释{get;set;}
公共DbSet电影{get;set;}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Add(
新的AttributeToColumnAnnotationConvention属性(
“ServiceTableColumn”,(属性,属性)=>attributes.Single().ColumnType.ToString());
}
}
}

有人告诉我为什么有时会发生此错误以及如何修复它吗?

您100%确定缩略图不为空吗?是的,它不为空。正如我选中的参数一样,包含以下值。(一些值与'x'){“Id”交换):“facebook972811922757829”,“ThumbnailUrl”:“}根据您的描述,我无法重新处理您的问题。您能告诉我您如何将MobileServiceContext引用添加到您的webjobs项目吗?您是否只将所有移动后端项目添加到webjobs?此外,我不建议您使用上下文将记录添加到移动服务后端。我建议您可以尝试使用azure webjobs extensions mobile apps binding,允许您轻松从Azure移动应用程序创建、读取和更新记录。您可以参考本文:这是我所做的。步骤1.在Visal Studio 2017中,使用C#mobile apps模板项目创建新解决方案。该项目在模型文件夹中具有MobileServiceContext类。步骤2.添加webjob pr在webjob中,添加对移动应用程序项目的引用,以便webjob可以使用MobileServiceContext。这就是我将MobileServiceContext添加到webjob的方式。此外,我想做的是将url添加到来自webjob的DB中的记录中。这不是一个好方法吗?你认为使用webjob扩展更好吗?我已经创建了一个test在我的电脑上演示,效果很好。我无法重新设置您的问题。由于此错误有时会发生,因此我们建议您尝试另一种方法来测试它。在我看来,我认为webjob SDK是更新移动记录的更好方法。您100%确定缩略图不为null吗?是的,它不为null。我检查了参数,以下值为包括。(某些值与'x'){“Id”:“facebook972811922757829”,“ThumbnailUrl”:“}交换)根据您的描述,我无法重新编写您的问题。您能告诉我如何将MobileServiceContext引用添加到您的webjobs项目中吗?您是否只是将所有移动后端项目添加到webjobs?此外,我不建议您使用上下文将记录添加到移动服务后端。我建议您可以尝试使用azure webjobs extensions移动应用程序绑定,它允许您轻松地从azure移动应用程序创建、读取和更新记录。你可以参考这篇文章:以下是我所做的。步骤1.在Visal Studio 2017中,使用C#移动应用程序模板项目创建新的解决方案。该项目具有MobileServiceContext