I use ExpressionSerialization library for serializing Expression Tree but get me an error
Could not find a matching type
WCF Service :
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 Proxy :
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;
}
}
Console Test :
var prx = new ClassLibrary1.Class1();
var lst = prx.Get(x => x.ID > 3);
BUT when run project ExpressionSerialization give me an error :
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)
Can anyone explain how resolve this problem ?
and How use this library in Client and WCF project ?