在ExpressionSerialization.dll中找不到匹配的类型

时间:2014-05-12 16:04:38

标签: c# wcf serialization expression-trees

我使用ExpressionSerialization库来序列化表达式树,但是给我一个错误

Could not find a matching type

WCF服务:

public class Person
{      
    public int ID { get; set; }
    public string Name { get; set; }
}
[ServiceContract]
public interface IService1
{
    [OperationContract(Name = "GetByPredicate")]
    List<Person> Get(XElement expression);
    [OperationContract]
    List<Person> Get();
}

public class Service1 : IService1
{
    private readonly List<Person> _persons;
    public Service1()
    {
        var p = new List<Person>
        {
            new Person() {ID = 1, Name = "A"},
            new Person() {ID = 2, Name = "B"},
            new Person() {ID = 3, Name = "C"},
            new Person() {ID = 4, Name = "D"},
            new Person() {ID = 5, Name = "E"},
            new Person() {ID = 6, Name = "F"},
            new Person() {ID = 7, Name = "G"},
            new Person() {ID = 8, Name = "H"}
        };

        _persons = p;
    }
    public List<Person> Get(XElement expression)
    {
        var s = new ExpressionSerializer();
        var exp = s.Deserialize<Func<Person, bool>>(expression).Compile();
        return _persons.Where(exp).ToList();
    }

    public List<Person> Get()
    {
        return _persons;
    }
}

WCF代理:

public class Class1
{
    public List<Person> Get(Expression<Func<Person, bool>> expression)
    {
        var exp = new ExpressionSerialization.ExpressionSerializer().Serialize(expression);

        var srv = new Service1Client();
        var lst = srv.GetByPredicate(exp);
        srv.Close();
        return lst;
    }

    public List<Person> Get()
    {
        var srv = new Service1Client();
        var lst = srv.Get();
        srv.Close();
        return lst;
    }
}

控制台测试:

        var prx = new ClassLibrary1.Class1();
        var lst = prx.Get(x => x.ID > 3);

但是当运行项目时,ExpressionSerialization会给我一个错误:

Could not find a matching type

Inner Exception : null
Message : Could not find a matching type
Parameter name: ClassLibrary1.ServiceReference1.Person

Stack Trace :    at ExpressionSerialization.TypeResolver.GetType(String typeName) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\TypeResolver.cs:line 161
   at ExpressionSerialization.ExpressionSerializer.ParseNormalTypeFromXmlCore(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 375
   at ExpressionSerialization.ExpressionSerializer.ParseTypeFromXmlCore(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 363
   at ExpressionSerialization.ExpressionSerializer.ParseTypeFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 355
   at ExpressionSerialization.ExpressionSerializer.ParseParameterExpressionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 332
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXmlNonNull(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 60
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 41
   at ExpressionSerialization.ExpressionSerializer.ParseMemberExpressionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 179
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXmlNonNull(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 70
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 41
   at ExpressionSerialization.ExpressionSerializer.ParseBinaryExpresssionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 404
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXmlNonNull(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 55
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 41
   at ExpressionSerialization.ExpressionSerializer.ParseLambdaExpressionFromXml(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 258
   at ExpressionSerialization.ExpressionSerializer.ParseExpressionFromXmlNonNull(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 62
   at ExpressionSerialization.ExpressionSerializer.Deserialize(XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 25
   at ExpressionSerialization.ExpressionSerializer.Deserialize[TDelegate](XElement xml) in c:\Users\Hamed\Desktop\Expression-Tree-Serializer-master\ExpressionSerialization\ExpressionSerializer(Deserialize).cs:line 30
   at WcfService1.Service1.Get(XElement expression) in e:\...\WcfService1\WcfService1\Service1.svc.cs:line 33
   at SyncInvokeGet(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

任何人都可以解释如何解决这个问题?

以及如何在Client和WCF项目中使用此库?

0 个答案:

没有答案