Search code examples
azureazure-deployment

worker role fails in csrun.exe but works fine when run directly from VS(F5 in VS)


I was just upgrading my project from sdk 1.3 to 1.7. I have create a post build event using cspack(copyOnly) that creates a cspkg directory. I am getting the below error from the worker role when I deploy it to the compute emulator using csrun.exe.

System.BadImageFormatException: Could not load file or assembly 'file:///C:\AzureBookWriter\bin\Release\AzureBookWriter.cspkg\roles\BookWriterWorker\approot\WorkerRole1.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

I notice errors while deploying the service on Azure as well. I am thinking that the errors are the same that I noticed in csrun.

However, when I F5 in VS the app deploys fine to the emulator and runs fine. I am wondering why I am seeing the errors while deploying my package. Do I need to add any additional configs?

Thanks, Kunal


Solution

  • Figured out. This was not obvious. In the csdef I had to include

         <Runtime>
           <EntryPoint>
             <NetFxEntryPoint assemblyName="WorkerRole1.dll" targetFrameworkVersion="v4.0"/> 
           </EntryPoint> 
         </Runtime>   
         <Imports>
           <Import moduleName="Diagnostics" />
         </Imports>
    

    under worker role.

    This will create a WaWorkerHost.exe.config in base\64 and everything will work fine