Skip to main content

Notifications

Microsoft Dynamics AX forum
Unanswered

Getting error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

Posted on by Microsoft Employee

Hi,

Someone guide me to resolve the Error.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ServiceModel.FaultException: The provided asset id [000000002] is invalid

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at References.AssetsService.AssetsPort.saveAsset(saveAssetRequest1 request)
at References.AssetsService.AssetsPortClient.References.AssetsService.AssetsPort.saveAsset(saveAssetRequest1 request)
at References.AssetsService.AssetsPortClient.saveAsset(saveAssetRequest saveAssetRequest)
at Dynamics.Ax.Application.InterfaceBatch.assetservice() in InterfaceBatch.AssetService.xpp:line 366

Categories:
  • Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    RE: Getting error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

    Yes, I know it's taken from LogisticsLocation, but that's not what either I or the error message were talking about. The message says that you're trying to use it as an asset ID. It seems that you the value in a wrong and you're not aware of it, but I can't comment on the code of your service as I've never seen it (you gave us just a snippet of the client code).

    If you can't find the bug just by looking at your code, use the debugger to find the problem at runtime. Note that AX code called from services is executed in CIL, therefore you would need the Visual Studio debugger attached to the AOS process. As usual, you can find details in documentation (Debugging in Microsoft Dynamics AX 2012).

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

    yes this "000000002" id is present in "logisticsLocation".

    It is customized services.

  • Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    RE: Getting error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

    Using location  ID as asset ID looks suspicious. Are you sure that asset ID 000000002 exists and that the whole logic makes sense?

    Also, what service are you calling?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

    Hi Martin,

    I am Accessing the dll in AX.

    Exception is throwed in "assetclient.saveAsset(request);"

    I am having code like this.

    request.set_Id(logisticsLocation.LocationId ? logisticsLocation.LocationId : logisticsLocation.Inv_LocationId); //Asset id "000000002"is taken from logisticsLocation table.

    request.set_purchaseOrder(salesTable.PurchorderFormNum);

    utcDateTimeRoute = WMSPickingRoute::find(wmsOrderTransTmp.routeId).ActivationDateTime;

    netDttm = utcDateTimeRoute; // Marshals.

    request.set_purchaseDate(netDttm);   request.set_assetClassName(InventTable::getassetclassName(wmsOrderTransTmp.itemId));       request.set_serialNumber(InventDim::find(wmsOrderTransTmp.inventDimId).inventSerialId);

    request.set_createdDate(Global::utcDateTime2SystemDateTime(time)); request.set_createdDateSpecified(true);

    request.set_customFields(customField);

    assetclient.saveAsset(request); //above exception is throws in this line

    assetclient.Close();

    assetclient.Dispose();

    can guide me to resolve the error.

  • Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    RE: Getting error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

    Unfortunately you forgot to provide any information about what you're doing. Anyway, the error says that "The provided asset id [000000002] is invalid", so that's what you should focus on.

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,115 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,971 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans