Exception: "Could not load file or assembly '' or one of its dependencies. The system cannot find the file specified" in Windows Azure VM

When you deploy your application to Windows
Azure, sometimes, it is possible that your role will not start and in Windows
Azure portal you will see that your role status shows the following cycle with
regard to your service:

 

- Busy

Starting

 

The reason for this "Busy and Starting" cycle
with your role is because:

 

-
When Windows Azure VM starts, it looks for the main
role DLL and depend on the type of role it starts the role host process

-
Depend on role type either web or worker role, the
DLL is loaded into respective host process

o Worker Role:

  • WaWorkerHost.exe for Worker Role

o Web Role:

  • In Windows Azure SDK 1.2 -
    WaWebHost.exe
  • In Windows Azure SDK 1.3: -
    WaIISHost.exe

Note 1: If you are running into Legacy Web Role your web site is also
running in the same process
Note 2: If you are running Full IIS role then your
website is running in W3wp.exe process

-
An exception in your role cause the role host
process (web or worker) to die

-
App Agent use a timing mechanism to check the health
of role and when it finds the role is not running it goes back to launch the
host process to load the role DLL

-
So this cycle keep going forever.

 

When
using Windows Azure SDK 1.3 you have ability to RDP to your Windows Azure VM
after proper RDP setup in your application, you can see the event log for more
clues. In the Application Event log you may see the following error log:

 

Application information:

    Application
domain: /LM/W3SVC/1/ROOT-1-129332781858403709

    Trust
level: Full

    Application
Virtual Path: /

    Application
Path: E:\approot\

    Machine
name: RD00155D329773

Process information:

    Process
ID: 2776

    Process
name: WaWebHost.exe

    Account
name: CIS\8d881dd6-13a2-4ec0-91f6-c8080a7b48d5

Exception information:

    Exception
type: ConfigurationErrorsException

    Exception message: Could not
load file or assembly 'System.ServiceModel.DomainServices.Hosting,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of
its dependencies. The system cannot find the file specified.

   at
System.Web.Configuration.ConfigUtil.GetType(String typeName, String
propertyName, ConfigurationElement configElement, XmlNode node, Boolean
checkAptcaBit, Boolean ignoreCase)

   at
System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName,
String propertyName, ConfigurationElement configElement)

   at
System.Web.Configuration.Common.ModulesEntry..ctor(String name, String
typeName, String propertyName, ConfigurationElement configElement)

   at
System.Web.HttpApplication.BuildIntegratedModuleCollection(List'1 moduleList)

   at
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext)

   at
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,
HttpContext context, MethodInfo[] handlers)

   at
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[]
handlers, IntPtr appContext, HttpContext context)

   at
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr
appContext, HttpContext context)

   at
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of
its dependencies. The system cannot find the file specified.

   at
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark,
Boolean loadTypeFromPartialName, ObjectHandleOnStack type)

   at
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark,
Boolean loadTypeFromPartialName)

   at
System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)

   at
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean
throwOnError, Boolean ignoreCase)

   at
System.Web.Configuration.ConfigUtil.GetType(String typeName, String
propertyName, ConfigurationElement configElement, XmlNode node, Boolean
checkAptcaBit, Boolean ignoreCase)

 

 

 

Based on above error you may have the following potential
issues:

1.
You have 32bit and 64bit binary mixed with your project. You can
use a combination of 32bit and 64bit DLL in your project however please set the
build type for all of your projects to "Any CPU".

2.
You might have some binaries missing when your CSPKG was
uploaded. Please be sure to set the "Copy Local" as TRUE for each any every
binary which are included by you. You don't need to set Copy local for Windows
Azure SDK binaries.

 

Related Articles: 

https://blogs.msdn.com/b/avkashchauhan/archive/2011/02/15/decrypting-windows-azure-package-cspkg-in-windows-azure-sdk.aspx

https://blogs.msdn.com/b/avkashchauhan/archive/2011/01/24/dissection-of-a-windows-azure-sdk-1-3-based-asp-net-web-role-in-full-iis-mode-amp-hwc.aspx