Search code examples
c#.netsilverlightria

silverlight MatchTimeoutInMilliseconds bug : resolve DomainServiceClientCodeGenerator


Silverlight 5 .Net Framework 4

I am trying to implement a workaround for the recent bug in the RIA code generator "MatchTimeoutInMilliseconds could not be found" https://connect.microsoft.com/VisualStudio/feedback/details/1988437/generated-code-for-silverlight-references-matchtimeoutinmilliseconds-which-does-not-exist

I'm trying to use the workaround by Lazebnyy, But I can't seem to get DomainServiceClientCodeGenerator to resolve.

Lazebnyy writes:

Install RIAServices.T4 from Nuget in the WebProejct or a Class Library that will contain the the code generation classes. PM> Install-Package RIAServices.T4

Create two classes

[DomainServiceClientCodeGenerator(typeof(MyServicesEntityGenerator),"C#")]
public class MyServicesClientCodeGenerator : CSharpClientCodeGenerator
{
    protected override EntityGenerator EntityGenerator
    {
        get
        {
            return new MyServicesEntityGenerator();
        }
    }
}

public class MyServicesEntityGenerator : CSharpEntityGenerator
{
    protected override void GenerateAttributes(IEnumerable<Attribute>attributes, bool forcePropagation)
    {
        List<Attribute> newAttributes = new List<Attribute>(attributes);
        List<Attribute> regularExpressionAttributes = (from c in attributes where c.GetType() == typeof(RegularExpressionAttribute) select c).ToList();

        newAttributes.RemoveAll(delegate(Attribute attr)
                {
                    return attr.GetType() == typeof(RegularExpressionAttribute);
                });

        base.GenerateAttributes(newAttributes, forcePropagation);

        foreach (RegularExpressionAttribute item in regularExpressionAttributes)
        {
            base.Write(string.Format("[System.ComponentModel.DataAnnotations.RegularExpressionAttribute(@\"{0}\",
            ErrorMessage=@\"{1}\")]\r\n",
            item.Pattern, item.ErrorMessage));
        }
    }
}

Now to hook it all up, in the Silverlight project file we need to tell RIA to use our generator. We have to edit the Silverlight project and add the following element inside the first PropertyGroup just after LinkedServerProject (the order doesn't matter, I just say that as a reference).

<LinkedServerProject>..\RIAServicesLibrary.Web\RIAServicesLibrary.Web.csproj</LinkedServerProject>
<RiaClientCodeGeneratorName>RIAServicesLibrary.Web.Helpers.MyServicesEntityGenerator</RiaClientCodeGeneratorName>

.

No matter what I try, I can't seem to resolve DomainServiceClientCodeGenerator

[DomainServiceClientCodeGenerator(typeof(MyServicesEntityGenerator),"C#")]
  1. I got the Nuget package RIAServices.T4 Version 4.2.0,
  2. Added the references in the server side service project to Microsoft.ServiceModel.DomainServices.Tools.dll Microsoft.ServiceModel.DomainServices.Tools.TextTemplate.dll
  3. I've included the namespaces in the code

    using Microsoft.ServiceModel.DomainServices.Tools;
    using Microsoft.ServiceModel.DomainServices.Tools.TextTemplate.CSharpGenerators;
    using Microsoft.ServiceModel.DomainServices.Tools.TextTemplate;
    

Digging through the namespaces, all I can find is DomainServiceClientCodeGeneratorAttribute and IDomainServiceClientCodeGenerator

Can anyone tell me how to resolve my missing DomainServiceClientCodeGenerator ?


Solution

  • I finally got it working. The project needed reference to System.ComponentModel.Composition

    This key piece of information came from http://jeffhandley.com/archive/2010/10/28/RiaServicesT4WalkUp.aspx

    You’ll notice that I needed to add a reference to Microsoft.ServiceModel.DomainServices.Tools for this to work. That assembly is in our framework (not the Toolkit) and it’s where the DomainServiceClientCodeGeneratorAttribute class is defined. Also, in order for this to compile, I needed to add a reference to System.ComponentModel.Composition (MEF) because that attribute class actually derives from ExportAttribute.

    ...

    (for anyone wondering, this did not solve the MatchTimeoutInMilliseconds bug for me)