« How to automate the creation of a Windows Azure 1.3 package in Team Foundation Server (TFS) for a web role hosted in ‘Full IIS’ with multiple sites | Main | How to fix the errors “[UnauthorizedAccessException: Access to the path '[{Guid}-mswapd-lock' is denied.]” or “"Response is not available in this context"" when using Azure Diagnostics 1.3 in a web role hosted in full IIS »

How to fix the error: “The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state” when running a Windows Azure project in the local development fabric/emulator

So you’ve just installed the latest Windows Azure SDK 1.3 or you’ve upgraded your Azure 1.2 SDK.  You press F5 or run your azure project in the local emulator (previously the ‘local development fabric’) you get the error:

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state

In Visual Studio, it might look like this -

image

Bummer.  But don’t worry, below I have details on how to fix this issue.


How to fix the error: “The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state” when running a Windows Azure project in the local development fabric/emulator

If you click on “View Detail…” you’ll see this exception -

image

Here’s the full exception -

System.ServiceModel.CommunicationObjectFaultedException was unhandled
  Message=The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
  Source=mscorlib
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
       at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)
       at Microsoft.WindowsAzure.Hosts.WaIISHost.Program.Main(String[] args)
  InnerException

There seems to be a bug in the Windows Azure SDK 1.3 that causes this exception to occur if your Web.Config file is read-only.  Since many of us use TFS or some other source control system, there’s a high chance your Web.Config is read-only and you will get this error when you run your azure project in the local emulator.

The fix: simply make your Web.Config not read-only.  You can manually change the read-only attribute in windows explorer, but when you get the latest from source control, it will be marked as read-only again.

So a better way is to create a post-build event that marks the Web.Config as not read-only right after compilation, but before your project starts running in the local emulator.

Right-click on your ASP.NET site or WCF web service project and choose Properties > Build Events -

image

In the ‘Post-build event command line’, enter -

attrib -r "$(ProjectDir)Web.Config"

That’s it!  Now you can run your windows azure project in the 1.3 emulator and the stupid exception will no longer occur.

Here’s the original thread in the Windows Azure forums, where I found this solution -

Error deploying locally 29 November 2010 Azure Tools
http://social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/26165c71-f941-4d84-9ef3-649d7bab0066

Good times!


| More



Comments