Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Calling console application from crm plugin

Posted on by Microsoft Employee

Hello,

I am trying to call a simple console application  from a crm 2011 plugin on post update.

This is the code from my plugin:

                StreamReader output = null;
                StreamReader error = null;
                try
                {
                    Process p = new Process();
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.FileName = @"D:\TotalSoft\ConsoleApplication8\bin\Debug\ConsoleApplication8.exe";
                    p.StartInfo.Arguments = (string)entity.GetAttributeValue("ts_status");
                    p.Start();
                    p.WaitForExit();
                    output = p.StandardOutput;
                    error = p.StandardError;
                }
                catch (Exception ex)
                {
                    Entity qm = new Entity("new_lmtinterfacelog");
                    qm["new_errormessage"] = "There was an error when trying to call the backloop application. Exception: " + ex.Message + "---StackTrace: " + ex.StackTrace + "---StandardError: " + error.ReadToEnd() + "---StandardOutput: " + output.ReadToEnd();
                    qm["new_name"] = "Backloop exception";
                    service.Create(qm);
                }

Every time i trigger a post upodate i get the error: Cannot find file specified and the address is correct(@"D:\TotalSoft\ConsoleApplication8\bin\Debug\ConsoleApplication8.exe").

Any ideas guys???

tnx

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calling console application from crm plugin

    Francesco Picchi

    Could you elaborate on why calling a console application from a plugin is one of the worst things to do from a plug-in?  

    I am attempting do write a project that does something similar.  I have no clear cut final goal of my project but I just want to find the full capabilities of the plug-in.

    Somethings I attempted to do in my CRM Plugin is, 

    -  Open a console application (both local and also from our company network)

    -  Create a folder on my desktop

    -  Open a file

    -  Establish a MySql or PostgreSQL connection (And just open it - simply for testing purposes).  

    My company is uncertain of what we want the plugin to do but we want to get an idea of what is possible.  For example, one of the main things we wanted to do with the plugin is, say for example:

    1)  User creates a new customer contact

    2)  Once the new contact is made, open a console application that will add the credentials of this new customer to a different database

    As I mentioned above, I attempted to perform each of these basic tasks within the execute method of the plugin.  Every time I attempted to call a function from one of their respective libraries, I would receive a error that seems to reference the library.  

    -  For example

    1)  If I were to set up a mysql connection (With the correct connection string) and then call mySQLconnection.open()

    -  I would be thrown an error on //Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    2)  If I were to create a new folder on my desktop (Or anywhere really), and then call Directory.CreateDirectory(folderPath)

    -  I would recieve a similar error to the one above except it refers to the library this method is from, FileIOPermission

    Could you elaborate on why these are bad practices for the plugin?  

    Would these occurs if I were to attempt any of these basic task within any .net class library project?  or is it only because this is a plugin?

    I have also seen suggesstions for giving my project, "Full Trust" permissions.  Unfortunately that is not even an open to set in my properties, why is this?  Can I give it full trust else where?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calling console application from crm plugin

    Hi Horia88,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calling console application from crm plugin

    Hi Horia88,

    Honestly, rather than try to call an application console from plugin (bad scenario), I would like to focus on why a plugin console should be called up and if there isnt another standard way to call it throught Azure listener, Web Service or a Scheduled Task with short intervals.

    Believe me, calling a console application from a plugin is one of the worst things you can do with a plugin ...

    Please describe what job this console do and why you need to call it in real time from a plugin.

    Thanks.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: Calling console application from crm plugin

    Check how you registered you plugin. If you have registered as sandbox mode it wont work. For Sandbox mode  access to the file system is restricted for security reasons. You should select as "None" . for more info pls check on the below article.

    crmbusiness.wordpress.com/.../understanding-plugin-sandbox-mode

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Calling console application from crm plugin

    Can you try to copy the file to the backend server (using the exact same path)?

    Have a feeling that is where the plugin is looking for the file.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Calling console application from crm plugin

    If it's an async plugin (or if it's a sandbox plugin), the plugin may be running on the other server (it'll only run in IIS if it's a synchronous non-sandboxed plugin)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calling console application from crm plugin

    Yes, it is deployed on the same server. The crm has front and back end server. I have deployed it on the front end server where the CRM is published in IIS.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Calling console application from crm plugin

    Hi,

     do you have that console application deployed on the CRM server?(and, if you have differnt CRM server roles, exactly which server depends on the server role/plugin type)

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans