已部署的 Azure 函数丢失 Entity Framework.edmx 文件 - FileNotFoundException
Deployed Azure Function is missing Entity Framework .edmx file - FileNotFoundException
我有一个在本地运行良好的 v3 Azure Functions,但在部署后我看到以下与丢失 Entity Framework 文件相关的异常:
2021-10-18T23:37:07.588 [Error] Executed 'MyFunction' (Failed, Duration=1807ms)
Autofac.Core.DependencyResolutionException : An exception was thrown while activating
Autofac.Core.DependencyResolutionException : An exception was thrown while invoking the constructor 'Void .ctor()' on type 'Repository'.
System.IO.FileNotFoundException : Could not find file 'D:\home\site\wwwroot\bin\DAOEntities.edmx'.
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode,FileShare share,FileOptions options)
at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options)
at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,Boolean useAsync)
at System.Xml.XmlWriterSettings.CreateWriter(String outputFileName)
at System.Xml.XmlWriter.Create(String outputFileName,XmlWriterSettings settings)
at System.Data.Entity.Infrastructure.DefaultDbModelStore.Save(Type contextType,DbModel model)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.AsNoTracking() at System.Data.Entity.Infrastructure.DbQuery
1.AsNoTracking()
at lambda_method(Closure ,Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
End of inner exception
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context,IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable
1 parameters)
End of inner exception
at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope,ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context,Service service,IEnumerable
1 parameters,Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context,Service service,IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context,IEnumerable
1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
at Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstance[T](ILifetimeScope scope)
at Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstance[T](IFunctionInstanceEx functionInstance)
at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory1.<>c__DisplayClass1_1.<.ctor>b__0(IFunctionInstanceEx i) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 20 at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory
1.Create(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 26
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs : 44
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize() at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 776
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 101
我在本地注意到 .edmx
文件不是在构建项目时生成的,而是在我使用 func start
启动 运行 项目时创建的。
这可能是权限问题(例如,函数没有对存储 blob 的写入权限)吗?
我发现根本问题与 Run From Package
设置有关。
这会阻止函数应用程序生成 .edmx
文件,因此解决方案是禁用 Run From Package
或使用预先包含的 .edmx
文件部署函数。
来自 MSDN:运行From Package 使 wwwroot 成为只读的,因此您在将文件写入该目录时会收到错误消息。 (https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package)
我有一个在本地运行良好的 v3 Azure Functions,但在部署后我看到以下与丢失 Entity Framework 文件相关的异常:
2021-10-18T23:37:07.588 [Error] Executed 'MyFunction' (Failed, Duration=1807ms)
Autofac.Core.DependencyResolutionException : An exception was thrown while activating
Autofac.Core.DependencyResolutionException : An exception was thrown while invoking the constructor 'Void .ctor()' on type 'Repository'.
System.IO.FileNotFoundException : Could not find file 'D:\home\site\wwwroot\bin\DAOEntities.edmx'.at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode,FileShare share,FileOptions options)
at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options)
at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,Boolean useAsync)
at System.Xml.XmlWriterSettings.CreateWriter(String outputFileName)
at System.Xml.XmlWriter.Create(String outputFileName,XmlWriterSettings settings)
at System.Data.Entity.Infrastructure.DefaultDbModelStore.Save(Type contextType,DbModel model)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.AsNoTracking() at System.Data.Entity.Infrastructure.DbQuery
1.AsNoTracking()
at lambda_method(Closure ,Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
End of inner exception
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context,IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable
1 parameters)
End of inner exception
at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope,ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context,Service service,IEnumerable
1 parameters,Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context,Service service,IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context,IEnumerable
1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
at Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstance[T](ILifetimeScope scope)
at Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstance[T](IFunctionInstanceEx functionInstance)
at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory1.<>c__DisplayClass1_1.<.ctor>b__0(IFunctionInstanceEx i) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 20 at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory
1.Create(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 26
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs : 44
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize() at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 776
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 101
我在本地注意到 .edmx
文件不是在构建项目时生成的,而是在我使用 func start
启动 运行 项目时创建的。
这可能是权限问题(例如,函数没有对存储 blob 的写入权限)吗?
我发现根本问题与 Run From Package
设置有关。
这会阻止函数应用程序生成 .edmx
文件,因此解决方案是禁用 Run From Package
或使用预先包含的 .edmx
文件部署函数。
来自 MSDN:运行From Package 使 wwwroot 成为只读的,因此您在将文件写入该目录时会收到错误消息。 (https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package)