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 CRM (Archived)

Calling console application from crm plugin

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    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)

  • Community Member Profile Picture
    on at

    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
    34,477 on at

    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)

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at

    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

  • Community Member Profile Picture
    on at

    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
    Community Member Profile Picture
    on at

    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
    on at

    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?

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans