I got a 'System.Reflection.TargetInvocationException' error when using prefetch paths.

Posts   
 
    
jason...
User
Posts: 14
Joined: 03-Sep-2007
# Posted on: 08-Oct-2007 05:50:11   

There's my working environment here. LLBLGen Pro. V2.5 Generating code for .NET1.0, C#, Adapter

The application was running on a .NET remoting architecture.

Here's the server site code.


public class DataAccess : MarshalByRefObject, IDataAccess
{
    public OrderEntity GetOrder(int orderId)
    {
        OrderEntity order = new OrderEntity(orderId);
        IPrefetchPath2 ppath = new PrefetchPath2(EntityType.OrderEntity);
        ppath.Add(OrderEntity.PrefetchPathCustomer);
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntity(order, ppath);
        }
        return order;
    }

and here's the client code.


string url = "tcp://172.16.1.35:1668/DataAccess";
da = (IDataAccess)Activator.GetObject(typeof(IDataAccess), url);
OrderEntity order = da.GetOrder(1);

Then, I got a 'System.Reflection.TargetInvocationException' error.

But, if the prefetch path code be marked, the application will run well.

ppath.Add(OrderEntity.PrefetchPathCustomer);

I've already tried to work on .NET 2.0 for the same application with prefetch path. Fortunately, it's working.

So, can the prefetch paths work on .NET1.0 and remoting?

jason...
User
Posts: 14
Joined: 03-Sep-2007
# Posted on: 08-Oct-2007 06:02:56   

Sorry, I forgot to memtion that it should not be a prefetch path problem but a remoting issuse in my opinion. Because the same 'TargetInvocationException' error occured when the server site code be changed to


    public OrderEntity GetOrder(int orderId)
    {
        OrderEntity order = new OrderEntity(orderId);
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntity(order);
            CustomerEntity cust = CustomerEntity(order.CustomerId);
            adapter.FetchEntity(cust);
            order.Customer = cust;
        }
        return order;
    }

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 08-Oct-2007 11:17:23   

Most probably this exception is due to some type mismatch. Please make sure both the client and the server are suing the same version of the generated code and the LLBLGen Pro runtime libraries Did you install .NET 1.0 available service packs on both the client and the server?

Would you please try to serialize/deserialize the object on the server into/from a memorystream object and see if it works?

jason...
User
Posts: 14
Joined: 03-Sep-2007
# Posted on: 09-Oct-2007 07:30:52   

I've just installed .NET 1.0 service pack 3, and also tried to serialize/deserialize the object into/from a memorystream object.

This code works.


OrderEntity order1 = new OrderEntity(1);
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, order1);
ms.Flush();
ms.Position = 0;
OrderEntity order2 = (OrderEntity)bf.Deserialize(ms);

But this code dosen't work, and gets an error (TargetInvocationException) at the last line: Deserialize(). The code only be added 2 lines for adding a relation object (CustomerEntity) to OrderEntity from the previous sample code.


OrderEntity order1 = new OrderEntity(1);
CustomerEntity cust = new CustomerEntity(1);
order1.Customer = cust;
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, order1);
ms.Flush();
ms.Position = 0;
OrderEntity order2 = (OrderEntity)bf.Deserialize(ms);

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 09-Oct-2007 10:23:24   

I've been told that .NET 1.0 does have some issues with remoting. You should consider migrating to .NET 1.1.