Is it possible to use an In-Proc COM DLL with Azure Functions?
I am migrating my web service to Azure Functions. One of the components has a dependency on a legacy 32-bit COM DLL. This would normally require the DLL to be regsvr32-ed on the system where it will be used. As that seems not possible with Azure Functions is it possible to use such legacy implementations?
Or would it be necessary to revert to a classic cloud service to support this? (My preference would be use the Consumption service plan and benefit from "serverless" architecture.)
Steps:
- Create new Azure Function App
- Add new Azure Function (http trigger)
- Add reference to 32-bit COM component
- Call simple test method on COM component
- Run locally - works fine
- Publish Azure Function
- Open function http path - Azure Function fails
Error log reports exception:
Could not load file or assembly 'Interop.MyCOMLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Exception while executing function: Legacy Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Legacy ---> System.IO.FileNotFoundException : Could not load file or assembly 'Interop.MyCOMLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. at async Functions.Legacy.Run(HttpRequestMessage req,TraceWriter log) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1.Start[TStateMachine](TStateMachine& stateMachine) at Functions.Legacy.Run(HttpRequestMessage req,TraceWriter log) at lambda_method(Closure ,Legacy ,Object[] )
at Microsoft.Azure.WebJobs.Host.Executors.TaskMethodInvoker 2.InvokeAsync(TReflected instance,Object[] arguments) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker 2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) End of inner exception
Also, if I go to the solution's Dependencies | COM then select the Interop.Lib and select to Embed Interop Types then with this change, after publish, on calling the publushed function:
"Retrieving the COM class factory for component with CLSID {D84F92D7-FFFF-4C16-B939-EC98E3A6EBC0} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."
Thus, the challenge is how to register the COM classes with Azure Functions?