简体   繁体   中英

COMException when Service Fabric stateless service returns POCO object graph

I have a stateless service that loads and returns an array of entity objects (POCO using EF). Lazy loading and proxy creation is disabled.

Everything is works just fine as long as I only return a single level graph:

var devices = context.Devices.Where(d => d.ParentHost_Id == hostId);
return Task.FromResult(devices.ToArray());

However, if I want to include another level, things go south in bad way:

var devices = context.Devices.Where(d => d.ParentHost_Id == hostId).Include(d => d.ConnectedDevices);
return Task.FromResult(devices.ToArray());

In this case, my code will load and return the requested objects without any trouble, but somewhere upstream in the call chain Service Fabric throws a COMException which it then handles by calling my service again. This results in a new COMExcetion, and it keeps doing this until I stop it.

{System.Runtime.InteropServices.COMException (0x80071C4C): Undantag från HRESULT: 0x80071C4C
vid Microsoft.ServiceFabric.Services.Communication.FabricTransport.Common.NativeServiceCommunication.IFabricServiceCommunicationClient.EndRequest(IFabricAsyncOperationContext context)
vid Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.EndRequest(IFabricAsyncOperationContext context)}

The Devices class is generated by EF and looks like this:

public partial class Devices
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Devices()
    {
        this.LogValues = new HashSet<LogValues>();
    }

    public long Id { get; set; }
    public int DeviceId { get; set; }
    public int Type { get; set; }
    public string Property { get; set; }
    public string Name { get; set; }
    public Nullable<long> ParentHost_Id { get; set; }

    public virtual Hosts Hosts { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<LogValues> LogValues { get; set; }
    public virtual ConnectedDevices ConnectedDevices { get; set; }
}

Any ideas on why this happens would be appreciated!

Apparently, the problem was that my object graph contained a circular reference (the ConnectedDevice had a reference to Device). I removed it from the EF model and everything is now working as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM