RIA, Azure, and IntelliTrace

IntelliTrace is not supported for the RIA Services framework. There is currently a bug in Visual Studio 2010 IntelliTrace that leads to a runtime exception if RIA Services is instrumented to record call information. Since this is the default tracing option chosen by the Azure SDK tools, it is an easy trap to fall into. If you do enable IntelliTrace, your domain service will always throw the following exception.

IntelliTraceLog

System.Security.VerificationException: Operation could destabilize the runtime
  System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetQueryEntityReturnType
System.ServiceModel.DomainServices.Server.DomainServiceDescription.IsValidMethodSignature
System.ServiceModel.DomainServices.Server.DomainServiceDescription.ValidateMethodSignature
System.ServiceModel.DomainServices.Server.DomainServiceDescription.AddQueryMethod
System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize
System.ServiceModel.DomainServices.Server.DomainServiceDescription.CreateDescription
<>c__DisplayClass8.AnonymousMethod
System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription
System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor
System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory.CreateServiceHost
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost
HostingManager.CreateService
HostingManager.ActivateService
HostingManager.EnsureServiceAvailable
System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest
System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow
ScheduledOverlapped.IOCallback
IOCompletionThunk.UnhandledExceptionFrame
System.Threading._IOCompletionCallback.PerformIOCompletionCallback

On the client, this will appear as the standard “Not Found” CommunicationException.

There are three workarounds for this problem. The first is to disable IntelliTrace altogether. This is the easiest option, but it has the broadest impact. You can disable IntelliTrace by unchecking the checkbox at the bottom of the Publish window.

NoIntellitrace

The second workaround is to only collect Azure events without collecting call information. RIA Services raises some basic Azure events, so this option does have a small advantage over the final option. However, once again we’ve used a broad solution that prevents us from harnessing the full power of IntelliTrace. You can select the events only option in the IntelliTrace Settings window available on the Publish window.

EventIntelliTrace

The last solution is to exclude the RIA Services framework libraries from IntelliTrace call information collection. This solution enables full IntelliTrace support for the rest of your application. On the Modules tab of the IntelliTrace Settings window, you will need to add an exception for *System.ServiceModel.DomainServices.* .

ExcludeIntelliTrace

I’ve tried to capture the significant points about this error so you won’t have to worry much about it yourself. The IntelliTrace bug has been reported to Visual Studio and I’m expecting a fix in their first SP. I’d assume we won’t see that for a while judging by past releases, but I’ll keep you updated if there are better fixes available later on. So for now, just pick a workaround and don’t look back.