6
votes

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:

  1. Create new Azure Function App
  2. Add new Azure Function (http trigger)
  3. Add reference to 32-bit COM component
  4. Call simple test method on COM component
  5. Run locally - works fine
  6. Publish Azure Function
  7. 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?

2

2 Answers

1
votes

It seems that it is not possible to run regsvr32 on function app platform, when running command on Kudu console, it shows "Access Denied".

The solution is to:

1- Create small web service that use COM lib and consume its functionality and host this app on windows VM.

2- Host other part of your you code in function app and instead of reference the function APP to COM , you can call the hosted web service (and pass whatever parameters you want )

Or simply you can deploy full code on VM and don’t use Function APP.

(Thanks to Microsoft support for this answer).

0
votes

There is nothing special involved in loading a COM object in a process. The process already loads a ton of random windows COM objects already. Give it a try and see if it works.

(not enough reputation to post comments)