I have a .net 4.0 Framework WCF service. I referenced this WCF to a .NET Framework 2.0 Website (not a web application, just a website).
But when I invoke a method of the WCF I get an exception like:
There was an error generating the XML document.
And the Inner Exception is:
System.Uri cannot be serialized because it does not have a parameterless constructor.
I do have a parameterless consturctor and the one which was inherited in my WCF as below:
//Service Class
public class MyWcfService : IWcfService
{
//I even put this hoping to make it work
public MyWcfService()
{
}
public MyEntity GetEntity(ArgumentObject arg)
{
return DoGetMyEntity(arg);
}
}
[Serializable]
public class MyEntity : EntityBase
{
public DateTime LastUpdate { set; get; }
//Here is the parameterless constructor
public MsisdnInformation()
{
this.LastUpdate = DateTime.Now;
}
}
[Serializable]
public class EntityBase
{
//Here is the parameterless constructor
public EntityBase()
{
}
}
This WCF is working with other projects (but those projects are .NET 3.0 or later framework projects. Some of those projects are Website and some of those are WepApplication.
So far, on my internet search I found nothing to help my case.
What do I need to do to fix this error?
System.Uri
class cannot be serialized because it doesn't have a parameterless constructor. So, don't try to serialize it. The .NET 2.0 site is using the XML Serializer to access your service, and that serializer requires all types to have a parameterless constructor. – John Saunders