Question

I have been trying to follow this example (download the source code from a link on the site or here, but I keep running into an error that seems embedded in the example.

My procedure has been as follows (after installing the AppFabric SDK and other dependencies):

  1. Download the source
  2. Create a Service Namespace on the AppFabric.
  3. Import the project into a new Windows Azure project with one Worker Role, make sure that it all compiles and that the default Worker Role Run() method starts and functions.
  4. Configure the method GetInterRoleCommunicationEndpoint in InterRoleCommunicationExtension.cs with the ServiceNameSpace and IssuerSecret from my AppFabric Service Namespace (IssuerName and ServicePath stay default). This is a hard-wiring of my own parameters.
  5. Copy/paste the initialization logic from the "SampleWorkerRole.cs" file in the demo into the OnStart() method of my project's Worker Role
  6. Comment-out references to Tracemanager.* as the demo code does not have the Tracemanager methods implemented and they're not crucial for this test to work. There are about 7-10 of these references (just do a Find -> "Tracemanager" in entire solution).
  7. Build successfully.
  8. Run on local Compute Emulator.

When I run this test, during the initialization of a new InterRoleCommunicationExtension (the first piece of the inter-role communication infrastructure to be initialized, this.interRoleCommunicator = new InterRoleCommunicationExtension();), an error is raised: "Value cannot be null. Parameter name: contractType."

Drilling into this a bit, I follow the execution down to the following method in ServiceBusHostFactory.cs (one of the files from the sample):

public static Type GetServiceContract(Type serviceType) { Guard.ArgumentNotNull(serviceType, "serviceType");

        Type[] serviceInterfaces = serviceType.GetInterfaces();

        if (serviceInterfaces != null && serviceInterfaces.Length > 0)
        {
            foreach (Type serviceInterface in serviceInterfaces)
            {
                ServiceContractAttribute serviceContractAttr = FrameworkUtility.GetDeclarativeAttribute<ServiceContractAttribute>(serviceInterface);

                if (serviceContractAttr != null)
                {
                    return serviceInterface;
                }
            }
        }

        return null;
    }



The serviceType parameter's Name property is "IInterRoleCommunicationServiceContract," which is one of the classes of the demo, and which extends IObservable. The call to serviceType.GetInterfaces() returns the "System.IObservable`1" interface, which is then passed into FrameworkUtility.GetDeclarativeAttribute(serviceInterface);, which has the following code:

public static IList GetDeclarativeAttributes(Type type) where T : class { Guard.ArgumentNotNull(type, "type");

        object[] customAttributes = type.GetCustomAttributes(typeof(T), true);
        IList<T> attributes = new List<T>();

        if (customAttributes != null && customAttributes.Length > 0)
        {
            foreach (object customAttr in customAttributes)
            {
                if (customAttr.GetType() == typeof(T))
                {
                    attributes.Add(customAttr as T);
                }
            }
        }
        else
        {
            Type[] interfaces = type.GetInterfaces();

            if (interfaces != null && interfaces.Length > 0)
            {
                foreach (object[] customAttrs in interfaces.Select(iface => iface.GetCustomAttributes(typeof(T), false)))
                {
                    if (customAttrs != null && customAttrs.Length > 0)
                    {
                        foreach (object customAttr in customAttrs)
                        {
                            attributes.Add(customAttr as T);
                        }
                    }
                }
            }
        }

        return attributes;
    }</code><br>

It is here that the issue arises. After not finding any customAttributes on the "IObservable1" type, it calls type.GetInterfaces(), expecting a return. Even though type is "System.IObservable1," this method returns an empty array, which causes the function to return null and the exception with the above message to be raised.

I am extremely interested in getting this scenario working, as I think the Publish/Subscribe messaging paradigm is the perfect solution for my application. Has anyone been able to get this demo code (from the AppFabric CAT Team itself!) working, or can spot my error? Thank you for your help.

Was it helpful?

Solution

Answered in the original blog post (see link below). Please advise if you are still experiencing problems. We are committed to supporting our samples on best effort basis.

http://blogs.msdn.com/b/appfabriccat/archive/2010/09/30/implementing-reliable-inter-role-communication-using-windows-azure-appfabric-service-bus-observer-pattern-amp-parallel-linq.aspx#comments

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top