silverlight MatchTimeoutInMilliseconds 错误:解决 DomainServiceClientCodeGenerator

silverlight MatchTimeoutInMilliseconds bug : resolve DomainServiceClientCodeGenerator

银光 5 .Net 框架 4

我正在尝试针对 RIA 代码生成器中的最新错误实施解决方法 "MatchTimeoutInMilliseconds could not be found" https://connect.microsoft.com/VisualStudio/feedback/details/1988437/generated-code-for-silverlight-references-matchtimeoutinmilliseconds-which-does-not-exist

我正在尝试使用 Lazebnyy 的解决方法,但我似乎无法解决 DomainServiceClientCodeGenerator

Lazebnyy 写道:

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>

.

无论我怎么尝试,我似乎都无法解析 DomainServiceClientCodeGenerator

[DomainServiceClientCodeGenerator(typeof(MyServicesEntityGenerator),"C#")]
  1. 我得到了 Nuget 包 RIAServices.T4 版本 4.2.0,
  2. 将服务器端服务项目中的引用添加到 Microsoft.ServiceModel.DomainServices.Tools.dll Microsoft.ServiceModel.DomainServices.Tools.TextTemplate.dll
  3. 我在代码中包含了命名空间

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

通过命名空间挖掘,我能找到的只有 DomainServiceClientCodeGeneratorAttributeIDomainServiceClientCodeGenerator

谁能告诉我如何解决我丢失的 DomainServiceClientCodeGenerator

我终于让它工作了。该项目需要参考 System.ComponentModel.Composition

这条关键信息来自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.

...

(对于任何想知道的人,这并没有为我解决 MatchTimeoutInMilliseconds 错误)

我花了大约 4 个小时才开始工作 Silverlight 5 + Ria Services SP1Visual Studio 2012 + Windiws 7 + 中创建的项目。 NET Framework 4 in Visual Studio 2015 + Windows 10 以修复此错误。

最初我根本无法在 Visual Studio 2015 中使用它。

所以我安装了 Visual Studio 2013(完整类型安装)+ Service Pack 5,我得到了更少的错误。

之后我安装了所有旧的 Silverlight 东西,比如 WPF Toolkit 然后我打开了解决方案,唯一的错误是关于

silverlight MatchTimeoutInMilliseconds bug : resolve DomainServiceClientCodeGenerator

因此,我安装了 .Net Framework 4.6.2 Preview

,无需对项目属性进行额外更改

AND THIS ERROR GONE!!!

我很好地编译了这个解决方案,之后我能够在 Visual Studio 2015 下编译它。

我希望我所花的时间对某人有所帮助。