开发者

Referencing a 64bit dll in the web app of a WCF RIA Services app hosted in Azure

开发者 https://www.devze.com 2023-03-30 20:22 出处:网络
I have a Silverlight app that uses WCF RIA Services and is hosted in Azure. The web app references Microsoft Z3 dll:

I have a Silverlight app that uses WCF RIA Services and is hosted in Azure.

The web app references Microsoft Z3 dll:

If I reference the 32bit version of this dll, Azure can't host it because it needs the 64bit version. If I reference the 64bit version, RIA Services won't compile.

Either I need to find a way of using the 32bit dll in Azure, or I need to find a way to reference the 63bit dll for开发者_运维技巧 RIA Services.

Any tips on which is the best approach and how?

Thanks

Sam


I thought I would quickly share my approach in case anyone ever needs to do that or something similar again, as the problems will be common to other native C++ libraries in Azure.

The problem was to do with a number of things: Azure not having all the VC++ runtime dlls needed by Z3; the Z3 install not including its other dependencies in its bin; Silverlight RIA Services failing to compile if there are any 64bit dlls either in the solution or in the bin folder; Azure not running the 32bit version of the Z3 dll; Azure not having the F# runtime, etc..

This is how I got it working:

  1. Abstract out an interface for the code that calls Z3 (In my case, having an IXxxAnalyzer interface in XxxAnalyzerCommon.dll)

  2. Don’t add the concrete F# implementation of this interface directly into the solution either as a reference, content, or resource.

  3. Instead, use a .NET zip library to package:

     a. XxxAnalyzer64.dll  (64bit version of the F# implementation of IXxxAnalyzer)
    
     b. XxxAnalyzerCommon.dll
    
     c. FSharp.Core.dll
    
     d. FSharp.PowerPack.dll
    
     e. Microsoft.Z3.dll (64bit version)
    
  4. Add the zip as content to the web project

  5. Add the VC++ redistributable (64bit) vcredist_x64.exe as content to the web project

  6. Create an Azure startup task that silently installs the VC++ redist when its first deployed.

  7. Create an Azure Local Storage Resource in your role configuration

  8. At startup, extract the zip to the local storage (if it’s not already there)

  9. Use MEF (the Managed Extensibility Framework) to dynamically import the concrete IAnalyzer by using a DirectoryCatalog pointing at the local storage – so the project doesn’t need to have any direct reference or dependency on XxxAnalyzer64.dll.

There was also a problem with the FSharp.PowerPack.dll strongly referencing an earlier version of FSharp.Core.dll, which I had to use an Assembly Redirect statement in the web.config to resolve.


There is an effort to make Z3 available on Azure for other webservices in general. This is in active development, but it's not live yet. We anticpate that many other webservices will also want to use this functionality, which is why I would be very interested in your requirements regarding the interface to the service. Do you require an incremental, high-performance interface or is a simple textual file interface sufficient for your application?


One way around this is to enable 32 bit binaries on Azure. This can be done by running:

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.enable32BitAppOnWin64:true

On startup. This can be specified by adding a startup task in service definitions to run this in a cmd script.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号