2

I have a C++/CLI project that wraps around an unmanaged C compression library, and this project is referenced by an MVC3 project that calls the C++ Compress function.

Everything works fine locally, but when I publish the solution to the Azure cloud, I get an error saying it could not find the module/dll:

Could not load file or assembly 'LZGEncoder.DLL' or one of its dependencies. The specified module could not be found.

Why can't it find the DLL file? is it going to the wrong place or being compiled at all? Is there any way I can check? Thanks!

Shahin Dohan
  • 6,149
  • 3
  • 41
  • 58

4 Answers4

6

The problem was that the Visual C++ 2010 Runtime libraries were missing from the cloud side.

What I did was add the Visual C++ 2010 Redistributable package to the project, along with a script to silently install it at start up, and now the native dll's work. You also need this if you're using native C dll's.

Steps:

1) Download Visual C++ 2010 Redistributable Package, and add it to your project.

2) Create a new batch file and add this to it:
vcredist_x64.exe /q /norestart
exit /b 0

3) Open the ServiceDefinition.csdef file and add this under the relevant WebRole element:

<Startup>
  <Task commandLine="InstallVCRedist.bat" executionContext="elevated" taskType="simple" />  
</Startup>  

UPDATE:
Visual C++ 2012 is out and the same script works, though everyone should make sure Azure is running atleast Windows Server 2008 R2, otherwise the start-up task will hang and the role will never start (until you kill the vcredist process in the task manager via RDP).

Shahin Dohan
  • 6,149
  • 3
  • 41
  • 58
  • How to add ServiceDefinition.csdef to my existing project in VS 2012 express web version? – newman Apr 21 '14 at 21:35
  • Can you please be specific where to put vcredist_x64.exe and InstallVCRedist.bat? In which project and folder? I put them in bin folder of the asp.net project and mark them all 'copy always', but it doesn't seem to work. Not sure how to debug the problem. Any tip is much appreciated! – newman May 01 '14 at 03:24
  • 1
    @miliu It doesn't really matter where you put them. I copied both files to the root folder of my solution, then added them to my solution via Visual Studio. The bin folder contains the output of the build, you shouldn't put static stuff in there, the 'copy always' is what copies the file to the bin folder eventually. – Shahin Dohan May 01 '14 at 06:31
3

IF you want to verify about what is on Azure VM, just try to unzip your CSPKG file and then again unzip .CSSX file (just rename CSSX to zip) and match that every references is all there. This way you can match what is on VM. Once you verify what DLL is missing in VS, select the Reference DLL and set its property "Copy Local" as "True".

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65
  • I will try this tomorrow at work, thanks. When you say missing DLL, you mean it could be depending on some other DLL's that are not available on the cloud but only locally? – Shahin Dohan Jun 20 '12 at 16:50
  • Yes, exactly.. When using native reference in manged project, you would need to provide all the DLL required for your native reference. Also sometimes you may need to install native runtime on Azure VM to get all the native references. (it may not be the cases with you but it sure is possible to install VC++ runtine to get a native reference working, but it all depend on what native reference you are using) – AvkashChauhan Jun 20 '12 at 16:59
  • Yes it was indeed the case that I needed the VC++ 2010 runtime libraries, or I could've compiled the project with VS2008 since Azure uses the older libraries out of the box. I would vote your answer up but I can't do that yet. – Shahin Dohan Jun 21 '12 at 14:14
  • Thanks for the confirmation.. I am glad it worked for you.. now sure how do u install VC++ runtime but you may need to use Startup task to get it done in your Azure Role VM. – AvkashChauhan Jun 21 '12 at 15:25
  • Already answered that and listed the steps to do it, but I have to wait till tomorrow to select my own answer. I basically just upload the VC++ package and a script to install it, and add a startup task inside the WebRole XML element in ServiceDefinition.csdef. Cheers! – Shahin Dohan Jun 21 '12 at 15:41
1

You need to place all dlls in the folder which is exist on live server. If you add refrence from your local and that location is not exist on live than you cannot build code on live. So make sure that all the dlls are exist on the live before deploy code on live.

0

Make sure the C++ dll and the unmanaged C library (if it's a .dll and not just source) are both included in your service package, and make sure the compiler's dumping the C++ library in the right place. This article has a decent walkthrough.

MNGwinn
  • 2,394
  • 17
  • 18