I have a v3 Azure Function that runs fine locally, but after it's deployed I see the following exception related to a missing Entity Framework file:
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
I've noticed locally that the .edmx
file isn't generated when the project is built -- instead it's created when I start running the project using func start
.
Could this be a permissions issue (e.g. with the function not having write access to the storage blob)?
CodePudding user response:
I've found that the root issue is related to the Run From Package
setting.
This prevents the function app from generating the .edmx
file, so the solution is to either disable Run From Package
or to deploy the function with the .edmx
file pre-included.
From MSDN: Run From Package makes wwwroot read-only, so you will receive an error when writing files to this directory. (https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package)