Comments (11)
you have to define the MyType in a shared library, and reference it both, on the client and the server.
tell me, if that works.
from serialize.linq.
This all happens well before any WCF usage, since it fails when it's converting the Expression I made to the ExpressionNode.
from serialize.linq.
Full code to my test console app:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Security;
using System.ServiceModel;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Globalization;
using Serialize.Linq;
using Serialize.Linq.Extensions;
using Serialize.Linq.Nodes;
using System.Linq.Expressions;
class Program
{
public class MyType
{
public int Id { get; set; }
}
static void Main(string[] args)
{
var ids = new List<int> { 1, 2, 3, 4, 5, 6 };
Expression<Func<MyType, bool>> expression1 = mt => mt.Id == 1 || mt.Id == 5 || mt.Id == 6;
var node1 = expression1.ToExpressionNode();
try
{
Expression<Func<MyType, bool>> expression2 = mt => ids.Contains(mt.Id);
var node2 = expression2.ToExpressionNode();
}
catch
{
}
}
}
Not using the WCF service in this, but it will break inside the try
block.
from serialize.linq.
fixed in commit: c4e3ce8
from serialize.linq.
Nice! My ExpressionNode gets created fine now. I have one more issue, but I'm thinking it's because I'm not implementing your library correctly. I'm getting an exception when serialization occurs:
System.ServiceModel.CommunicationException was unhandled
Message=There was an error while trying to serialize parameter http://tempuri.org/:query. The InnerException message was 'Type 'System.Int32[]' with data contract name 'ArrayOfint:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
Source=mscorlib
I'm almost certain my code isn't using your serializers at all. I saw you added all the known type code to the DataSerializer class, but my code never hits GetKnownTypes, nor any of the To[Format] extension methods. I think I'm missing some small step somewhere. Like I said, I don't think this is a bug, just me not using the library correctly. I'm getting the ExpressionNode, and passing it to my service. Works find with expressions like x => x.Id == 5
, but when I introduce the .Contains
into it, it breaks when serializing.
from serialize.linq.
is it possible for you to switch from List to int[], like
var ids = new [] { 1, 2, 3, 4, 5, 6 };
from serialize.linq.
Actually, that's what I did. First run I got that error for the List<int>
, so I tried int[]
. Same error, just with int[]
. The exception message I included above was for the array.
from serialize.linq.
hmm. can you try to build a unit test that reproduces the problem.
it is hard for me to reproduce it.
from serialize.linq.
Not a unit test per say, but code you can run in a console app to see what I'm talking about.
[DataContract]
public class Person
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
[ServiceContract]
public interface IPersonService
{
[OperationContract]
Person[] GetAllPersons();
[OperationContract]
Person[] QueryPersons(ExpressionNode query);
}
public class PersonService : IPersonService
{
private IList<Person> _persons = new List<Person>
{
new Person { FirstName="Bill", LastName="Gates" },
new Person { FirstName="John", LastName="Doe" },
new Person { FirstName="Jane", LastName="Smith" },
new Person { FirstName="Fred", LastName="Gates" }
};
public Person[] GetAllPersons()
{
return _persons.ToArray();
}
public Person[] QueryPersons(ExpressionNode query)
{
var expression = query.ToExpression<Func<Person, bool>>();
return _persons.Where(expression.Compile()).ToArray();
}
}
static void Main(string[] args)
{
ServiceHost personHost = null;
try
{
personHost = new ServiceHost(typeof(PersonService));
ServiceEndpoint productEndpoint = personHost.AddServiceEndpoint(typeof(IPersonService), new NetTcpBinding(), "net.tcp://localhost:9010/ProductService");
personHost.Open();
Console.WriteLine("The Product service is running and is listening on:");
Console.WriteLine("{0} ({1})", productEndpoint.Address.ToString(), productEndpoint.Binding.Name);
Console.WriteLine("\nPress any key to stop the service.");
var myBinding = new NetTcpBinding();
var myEndpoint = new EndpointAddress("net.tcp://localhost:9010/ProductService");
var myChannelFactory = new ChannelFactory<IPersonService>(myBinding, myEndpoint);
IPersonService client = null;
try
{
client = myChannelFactory.CreateChannel();
// This works fine.
var persons = client.GetAllPersons();
Console.WriteLine("{0} persons", persons.Count());
Expression<Func<Person, bool>> expression1 = p => p.LastName == "Gates";
// This works fine.
var matches1 = client.QueryPersons(expression1.ToExpressionNode());
Console.WriteLine("{0} persons", matches1.Count());
var firstNames = new string[] { "Bill", "Jim", "Teddy", "Jane" };
Expression<Func<Person, bool>> expression2 = p => firstNames.Contains(p.FirstName);
// This will break.
var matches2 = client.QueryPersons(expression2.ToExpressionNode());
Console.WriteLine("{0} persons", matches2.Count());
((ICommunicationObject)client).Close();
}
catch
{
if (client != null)
{
((ICommunicationObject)client).Abort();
}
}
Console.ReadKey();
}
finally
{
if (personHost.State == CommunicationState.Faulted)
{
personHost.Abort();
}
else
{
personHost.Close();
}
}
}
The only one to break is when I'm involving an array.
from serialize.linq.
this is different, i think this now on WCF. WCF uses its own DataContractSerializer.
Find here http://msdn.microsoft.com/en-us/library/ee358759.aspx an example on binding an own datacontractresolver. maybe i will add one in the next version.
thanks for testing and reporting.
from serialize.linq.
Oh, I thought the library worked with WCF already, as one of your blog posts on the library was using it with WCF. No worries, thanks!
from serialize.linq.
Related Issues (20)
- bug when using expressions that contain dynamic HOT 1
- Question on LambdaExpression serialization HOT 1
- .net 5.0 problem HOT 2
- Serialize expression when it is a property of a class? HOT 2
- Cannot Serialize Expression Converted From Func HOT 3
- How to Revice Post arguments in core 3.1
- Change of License HOT 6
- Expression.Default not supported in serialization HOT 2
- Question about deserialization security: HOT 1
- Need your help with other issue HOT 2
- "System.InvalidOperationException: Sequence contains no matching element" during SerializeText HOT 1
- Known type cannot be an interface
- Error converting type: Bug or implementation issue - please help HOT 3
- Undefined variable error when using ToString in lambda expression HOT 2
- Deploy the latest build to NuGet HOT 3
- Serialize Linq Expression not working - Workaround / Suggestion HOT 2
- Target framework net standard 2.0 & 2.1 HOT 3
- Changes from 2.x to 3.x HOT 2
- Error when serializing an expression with nested method calls
- Method serialization issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serialize.linq.