我有一個在本地運行良好的 v3 Azure 函式,但在部署后,我看到以下與缺少物體框架檔案相關的例外:
2021-10-18T23:37:07.588 [Error] Executed 'MyFunction' (Failed, Duration=1807ms)
Autofac.Core.DependencyResolutionException:激活
Autofac.Core.DependencyResolutionException 時拋出例外:呼叫建構式時拋出例外在型別 'Repository' 上使 .ctor()' 無效。
System.IO.FileNotFoundException:找不到檔案“D:\home\site\wwwroot\bin\DAOEntities.edmx”。在 System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
在 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)
在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
在 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.InternalSet1.Initialize()
在 System.Data.Entity.Internal.Linq.InternalSet1.AsNoTracking() at System.Data.Entity.Infrastructure.DbQuery1.AsNoTracking()
在 lambda_method (Closure ,Object[] )
在 Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() 在 Autofac.Core.Activators.Reflection.ReflectionActivator
的內部例外結束。 ActivateInstance(IComponentContext背景關系,IEnumerable的1個引數) 內部例外結束 在Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable的1 parameters) 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,IEnumerable1 個引數,物件和實體)
在 Autofac.ResolutionExtensions.ResolveService(IComponentContext 背景關系,服務服務,IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context,IEnumerable1 個引數)
在 Autofac.ResolutionExtensions.Resolve[TService](IComponentContext 背景關系)
在 Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstancedJobActivator. ](ILifetimeScope 范圍)
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.ActivatorInstanceFactory1.Create(IFunctionInstanceEx functionInstance) at C:\projects\azure -webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs:26
在 Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance) 在 C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs : 44
在 Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize() 在 C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:776
在 C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor 的異步 Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancelationToken) 處。秒:101
我在本地注意到該.edmx檔案不是在構建專案時生成的——而是在我開始使用func start.
這可能是權限問題(例如,該函式沒有對存盤 blob 的寫訪問權限)?
uj5u.com熱心網友回復:
我發現根本問題與Run From Package設定有關。這會阻止函式應用生成.edmx檔案,因此解決方案是禁用Run From Package或使用.edmx預先包含的檔案部署函式。
來自 MSDN:從包運行使 wwwroot 只讀,因此將檔案寫入此目錄時會收到錯誤。(https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339818.html
