<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic RE: Tip: How to Load Assembly DLLs Dynamically in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59509#M13143</link>
    <description>&lt;a href="https://community.blueprism.com/t5/user/viewprofilepage/user-id/38903"&gt;@StefanSchnell&lt;/a&gt;, you can even bundle your DLL inside VBO as base64 string - Abbyy does that in their VBO (zip+base64 actually).&lt;BR /&gt;It works if you just have a few methods in dll, but problem is that you dont have namespace anymore and missing all the enums etc.&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Andrey Kudinov&lt;BR /&gt;Project Manager&lt;BR /&gt;MobileTelesystems PJSC&lt;BR /&gt;Europe/Moscow&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
    <pubDate>Mon, 11 Jan 2021 11:39:00 GMT</pubDate>
    <dc:creator>AndreyKudinov</dc:creator>
    <dc:date>2021-01-11T11:39:00Z</dc:date>
    <item>
      <title>Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59503#M13137</link>
      <description>Hello Community,&lt;BR /&gt;in my opinion dynamic loading of dotNET assembly DLLs at the runtime a necessity. Therefore here a first approach how this possibility can be realized.&lt;BR /&gt;&lt;BR /&gt;At first I developed a tiny library, which I packed in a NuGet.&lt;BR /&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;//-Begin----------------------------------------------------------------

using System;

namespace test {

  public class nuget {

    public string mtest(string Input = "") {
      if(String.IsNullOrEmpty(Input)) {
        return "Hello World";
      } else {
        return "Hello " + Input;
      }
    }

  }

}

//-End------------------------------------------------------------------​&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;In the next step I installed this NuGet package at the target system in the UserProfile directory.&lt;/P&gt;
&lt;PRE class="language-php"&gt;&lt;CODE&gt;nuget.exe Install TestNuget -Source "%cd%" -OutputDirectory "%USERPROFILE%\.nuget"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="media" style="overflow: hidden; zoom: 1;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13429.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13589i25EB632791F9F07E/image-size/large?v=v2&amp;amp;px=999" role="button" title="13429.png" alt="13429.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;And with a Code Stage I call the method of this library dynamically, independently from the customizing in the Code Options.&lt;/P&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;//-Begin----------------------------------------------------------------

Result = string.Empty;
ErrRet = string.Empty;

string UserDir = Environment.GetEnvironmentVariable("UserProfile");
string DLLPath = UserDir + "\\.nuget\\TestNuget.1.0.0\\lib\\net40";

try {

  //-Loads assembly-----------------------------------------------------
  Assembly TestNugetDLL = Assembly.LoadFile(DLLPath + "\\TestNuget.dll");

  //-Gets the class type------------------------------------------------
  Type TestNugetClass = TestNugetDLL.GetType("test.nuget");
  if(TestNugetClass == null) {
    return;
  }

  //-Gets the method----------------------------------------------------
  MethodInfo mtest = TestNugetClass.GetMethod("mtest");

  //-Creates instance of the class--------------------------------------
  object TestNugetObj = Activator.CreateInstance(TestNugetClass);

  //-Call method without parameter--------------------------------------
  var oResult = mtest.Invoke(TestNugetObj, new object[] { null });
  Result = oResult.ToString();
  Result += Environment.NewLine;

  //-Call method with parameter-----------------------------------------
  oResult = mtest.Invoke(TestNugetObj, new object[] { "Stefan" });
  Result += oResult.ToString();

} catch(Exception ex) {
  ErrRet = ex.Message;
}

//-End------------------------------------------------------------------&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Only the namespace System.Reflection must be included.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13430.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13590iC4D31E1B53F82061/image-size/large?v=v2&amp;amp;px=999" role="button" title="13430.png" alt="13430.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13431.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13591i13D76288EBB1B2D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="13431.png" alt="13431.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Yes, including the library and calling the methods is "a bit cumbersome". But this approach offers a great possibility, to c&lt;SPAN style="font-family: 'Noto Sans', sans-serif;"&gt;all methods of an assembly which are not in the program directory of BP. This separation simplifies especially the deployment of libraries.&lt;BR /&gt;&lt;BR /&gt;Enjoy it.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Stefan&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Stefan Schnell&lt;BR /&gt;Senior Systems Engineer at BWI GmbH&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Jan 2021 16:28:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59503#M13137</guid>
      <dc:creator>StefanSchnell</dc:creator>
      <dc:date>2021-01-06T16:28:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59504#M13138</link>
      <description>Hi Stefan,&lt;BR /&gt;&lt;BR /&gt;Thanks for you contribution.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Jhogel Ponne&lt;BR /&gt;Senior RPA&lt;BR /&gt;Ernst &amp;amp; Young&lt;BR /&gt;America/Panama&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Jan 2021 20:41:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59504#M13138</guid>
      <dc:creator>jhogelp</dc:creator>
      <dc:date>2021-01-06T20:41:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59505#M13139</link>
      <description>Hello Community,&lt;BR /&gt;to verify my approach I tried to use the integration of &lt;A href="https://www.autoitscript.com" target="_blank" rel="noopener" title="AutoIt Scripting Language"&gt;AutoIt scripting language&lt;/A&gt;, I have &lt;A href="https://forum.uipath.com/t/one-size-fits-all" target="_blank" rel="noopener" title="One Size Fits All"&gt;described the basic approach here&lt;/A&gt; in the context of different RPA platforms.&lt;BR /&gt;I was particularly interested in using the existing NuGet package.&lt;BR /&gt;&lt;BR /&gt;I installed the existing NuGet package in the user directory.&lt;BR /&gt;
&lt;DIV class="media" style="overflow: hidden; zoom: 1;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13384.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13547i1BEF102E960C7779/image-size/large?v=v2&amp;amp;px=999" role="button" title="13384.png" alt="13384.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;BR /&gt;In the next step I build an object to use the AutoIt library.&amp;nbsp;&lt;BR /&gt;
&lt;DIV class="media" style="overflow: hidden; zoom: 1;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13385.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13548iADDA116B60CEB6A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="13385.png" alt="13385.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;BR /&gt;
&lt;DIV class="media" style="overflow: hidden; zoom: 1;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13386.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13549i993FD6B5B1CAE69B/image-size/large?v=v2&amp;amp;px=999" role="button" title="13386.png" alt="13386.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;BR /&gt;Here the Code Stage:&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;//-Begin----------------------------------------------------------------

//-Initialization of output variables-----------------------------------
Result = string.Empty;
ErrorMessage = string.Empty;

//-Check if file exists-------------------------------------------------
if(!File.Exists(AutoItFileName)) {
  ErrorMessage = "File not found";
  Console.WriteLine(ErrorMessage);
  return;
}

string UserDir = Environment.GetEnvironmentVariable("UserProfile");
string DLLPath = UserDir + "\\.nuget\\AutoIt4dotNET.1.0.0\\lib\\net40";

try {

  //-Loads AutoIt assembly----------------------------------------------
  Assembly AutoItDLL = Assembly.LoadFile(DLLPath + "\\AutoIt4dotNET.dll");

  //-Gets the class type------------------------------------------------
  Type AutoItClass = AutoItDLL.GetType("AutoIt4dotNET");
  if(AutoItClass == null) {
    return;
  }

  //-Gets the method----------------------------------------------------
  MethodInfo Run = AutoItClass.GetMethod("Run");

  //-Creates instance of the class--------------------------------------
  object AutoIt = Activator.CreateInstance(AutoItClass);

  //-Call method--------------------------------------------------------
  var oResult = Run.Invoke(AutoIt, new object[] {
    AutoItFileName,
    Arguments,
    Convert.ToInt32(TimeOut),
    x64,
    "", //-Path to AutoIt if local available, not necessary here
    OutputDebug
  });
  Result = oResult.ToString();

} catch(Exception ex) {
  ErrorMessage = ex.Message;
}

//-End------------------------------------------------------------------​&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;It works as expected.&lt;BR /&gt;
&lt;DIV class="media" style="overflow: hidden; zoom: 1;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="13387.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/13554iF98A421C4891CB09/image-size/large?v=v2&amp;amp;px=999" role="button" title="13387.png" alt="13387.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;BR /&gt;This approach shows us how to use libraries of NuGet packages with BP, with the advantage that the libraries no longer have to be stored in the BP program directory. In addition, we also see how AutoIt can be seamlessly integrated with BP via its CLI.&lt;BR /&gt;&lt;BR /&gt;Enjoy it.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Stefan&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Stefan Schnell&lt;BR /&gt;Senior Systems Engineer at BWI GmbH&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jan 2021 06:14:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59505#M13139</guid>
      <dc:creator>StefanSchnell</dc:creator>
      <dc:date>2021-01-07T06:14:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59506#M13140</link>
      <description>Hello, Stefan,&lt;BR /&gt;&lt;BR /&gt;excellent piece of work! I like your posts very much! Thanks for your contributions here!&lt;BR /&gt;&lt;BR /&gt;However, I have one question - when you use this approach (I haven't had time to play with it that's why I am asking) - you are not getting syntax errors from Code Stage? BP is able to understand references thanks to System.Reflection or....?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Zdeněk Kabátek&lt;BR /&gt;Head of Professional Services&lt;BR /&gt;NEOOPS&lt;BR /&gt;&lt;A href="http://www.neoops.com/" target="test_blank"&gt;http://www.neoops.com/&lt;/A&gt;&lt;BR /&gt;Europe/Prague&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jan 2021 16:59:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59506#M13140</guid>
      <dc:creator>zdenek.kabatek</dc:creator>
      <dc:date>2021-01-07T16:59:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59507#M13141</link>
      <description>Hello &lt;SPAN&gt;&lt;SPAN&gt;Zdeněk,&lt;BR /&gt;&lt;BR /&gt;thank you very much for your reply.&lt;BR /&gt;&lt;BR /&gt;I got no syntax errors, all works well and as expected.&lt;BR /&gt;As attachment a tiny video.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Stefan&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;DIV contenteditable="false" style="position: relative; height: 0px; overflow: hidden; padding-bottom: 56.25%;"&gt;&lt;IFRAME width="560" height="315" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" src="https://www.youtube.com/embed/H1Qa62k2iOA" class="hl-embedded-video" frameborder="0" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" data-mce-fragment="1"&gt;&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Stefan Schnell&lt;BR /&gt;Senior Systems Engineer at BWI GmbH&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Jan 2021 05:51:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59507#M13141</guid>
      <dc:creator>StefanSchnell</dc:creator>
      <dc:date>2021-01-08T05:51:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59508#M13142</link>
      <description>Hello Community,&lt;BR /&gt;&lt;BR /&gt;with the &lt;A href="https://community.blueprism.com/communities/community-home/digestviewer/view-question?ContributedContentKey=3a88f770-ab89-462d-b675-52838de9e41e" target="_blank" rel="noopener"&gt;knowledge of how to use dynamic data type&lt;/A&gt; is it possible to simplify the code and make it better understandable.&lt;BR /&gt;The call method section now consists of only one line.&lt;BR /&gt;&lt;BR /&gt;Enjoy it.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Stefan&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;//-Begin----------------------------------------------------------------

//-Initialization of output variables-----------------------------------
Result = string.Empty;
ErrorMessage = string.Empty;

//-Check if file exists-------------------------------------------------
if(!File.Exists(AutoItFileName)) {
  ErrorMessage = "File not found";
  Console.WriteLine(ErrorMessage);
  return;
}

string UserDir = Environment.GetEnvironmentVariable("UserProfile");
string DLLPath = UserDir + "\\.nuget\\AutoIt4dotNET.1.0.0\\lib\\net40";

try {

  //-Loads AutoIt assembly----------------------------------------------
  Assembly AutoItDLL = Assembly.LoadFile(DLLPath + "\\AutoIt4dotNET.dll");

  //-Gets the class type------------------------------------------------
  Type AutoItClass = AutoItDLL.GetType("AutoIt4dotNET");
  if(AutoItClass == null) {
    return;
  }

  //-Gets the method----------------------------------------------------
  MethodInfo Run = AutoItClass.GetMethod("Run");

  //-Creates instance of the class--------------------------------------
  dynamic AutoIt = Activator.CreateInstance(AutoItClass);

  //-Call method--------------------------------------------------------
  Result = AutoIt.Run(
    AutoItFileName,
    Arguments,
    Convert.ToInt32(TimeOut),
    x64,
    "", //-Path to AutoIt if local available, not necessary here
    OutputDebug
  );

} catch(Exception ex) {
  ErrorMessage = ex.Message;
}

//-End------------------------------------------------------------------​&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Stefan Schnell&lt;BR /&gt;Senior Systems Engineer at BWI GmbH&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Sat, 09 Jan 2021 17:23:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59508#M13142</guid>
      <dc:creator>StefanSchnell</dc:creator>
      <dc:date>2021-01-09T17:23:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59509#M13143</link>
      <description>&lt;a href="https://community.blueprism.com/t5/user/viewprofilepage/user-id/38903"&gt;@StefanSchnell&lt;/a&gt;, you can even bundle your DLL inside VBO as base64 string - Abbyy does that in their VBO (zip+base64 actually).&lt;BR /&gt;It works if you just have a few methods in dll, but problem is that you dont have namespace anymore and missing all the enums etc.&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Andrey Kudinov&lt;BR /&gt;Project Manager&lt;BR /&gt;MobileTelesystems PJSC&lt;BR /&gt;Europe/Moscow&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Jan 2021 11:39:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59509#M13143</guid>
      <dc:creator>AndreyKudinov</dc:creator>
      <dc:date>2021-01-11T11:39:00Z</dc:date>
    </item>
    <item>
      <title>RE: Tip: How to Load Assembly DLLs Dynamically</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59510#M13144</link>
      <description>&lt;a href="https://community.blueprism.com/t5/user/viewprofilepage/user-id/769"&gt;@AndreyKudinov&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Hello Andrey,&lt;BR /&gt;thank you very much for this interesting hint.&lt;BR /&gt;Best regards&lt;BR /&gt;Stefan​&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Stefan Schnell&lt;BR /&gt;Senior Systems Engineer at BWI GmbH&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Jan 2021 19:07:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Tip-How-to-Load-Assembly-DLLs-Dynamically/m-p/59510#M13144</guid>
      <dc:creator>StefanSchnell</dc:creator>
      <dc:date>2021-01-11T19:07:00Z</dc:date>
    </item>
  </channel>
</rss>

