web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Managed code dependency problem?

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

I have a problem with my managed code. Basically I wanna do web request using RestSharp package from dynamic ax. Is it possible to do that? 

I've created a managed code project that send a web request using RestSharp and I deployed them on client and server. I added RestSharp into my project via Nuget Package Manager. 

But when I call the function, Ax returns error message: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. 
at ApprovalRequestHelper.ApprovalRequester.sendRequest(String url, String jsonToSend) 
--- End of inner exception stack trace --- 
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
at Microsoft.Dynamics.AX.ManagedInterop.ClrBridgeImpl.InvokeClrStaticMethod(ClrBridgeImpl* , Char* pszClassName, Char* pszMethodName, Char* assemblyName, Int32 argsLength, ObjectWrapper** arguments, Boolean* argsAreByRef, Boolean* isException)

So my method signature is: ApprovalRequestHelper.ApprovalRequester.sendRequest(String url, String jsonToSend) 
I've check on the VSAssemblies folder and I see ApprovelRequestHelper dll. So there is nothing wrong with the dll and the function itself. From the error message, I think the error lies on the dependency of RestSharp.dll. Somehow it's not detected by AX or CIL (I dunno). Is the package dependency not deployed into AX together with my managed code dll when I deploy my project?

For what it's worth, I've enable hot-swapping assembly, Restart server. I've checked that if I remove the RestSharp package and the code that depends on it, My function runs without error.

Please enlighten me if you have any clue how to solve this. Thanks! If I ask on the wrong forum, I'm sorry.

*This post is locked for comments

I have the same question (0)
  • Konrad U Profile Picture
    804 on at

    I have not really done this but in Visual Studio projects would the RestSharp.dll be listed as a resource? Souds like it should be if it was added via nuget but sometimes strange stuff happens. Works in development but does not deploy correctly.

  • Community Member Profile Picture
    on at

    8176.aa.png

    Here is the debug folder of my C# project. But on the VSAssembly folder I only see ApprovalRequestHelper.dll. I tried to copy the RestSharp.dll into the VSAssemblies folder, but the folder is always refreshed if I restart the ax client. I tried to add it to the AOT reference, but the function still also fails.

    Here is my VSAssemblies folder.

    2018_2D00_05_2D00_20-22_5F00_54_5F00_55_2D00_Clipboard.png

  • Konrad U Profile Picture
    804 on at

    Here are the ax references I found.

    msdn.microsoft.com/.../gg881320.aspx;MSPPError=-2147217396

    This references where to put it and how to compile:

    msdn.microsoft.com/.../cc586538.aspx

  • Luc Champoux Profile Picture
    15 on at

    Hi, This issue has been posted quite a while ago, but have you ever been able to resolve it ?

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    It's possible. But it won't work without deploying RestSharp.dll into a location where AX can find it. For instance, you can manually copy it to the 'bin' folder of both AX client and the AOS server.

    There are also some possibilities of automated deployment, but let's discuss it later if needed, based on your actual requirements.

  • Luc Champoux Profile Picture
    15 on at

    Hi,

    Eventhough my dependent DLL was GAC-ed and copied in the bin folder of the AX client and server, i kept on getting the sames error. 

    My API call uses TLS 1.2 and AX seems to call using a lower version by default.

    Adding this line of code before calling my API fixed everything.

    -> System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Tls12);

    Good day

    Luc

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    Can you explain that, please? Setting the SSL for network communication seems completely unrelated to the fact that an assembly can't be loaded.

  • Luc Champoux Profile Picture
    15 on at

    Oops. You are right Martin it's unrelated. With all the research I had done I forgot I was a step further down with my issue. The dependency was now loading. But I was getting another message (which I solved setting the SSL protocol before calling my API)

    For your benefit the error was

    "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host"

    Force TLS1.2: System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Tls12);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans