Loading DLLs dynamically from the local disk










1















While the programming takes place and you refer to your files in NuGet packages programming with dependencies is not a so big deal, but I made an extension app to an existing application which relies basically on the same dll files as the main program.



Now I don't want to actually place the extension in our main application directory because it is more handy to have it versatile and have the user or admin copy it a to a place they like to.



In pseudocode the code while programming looks like this:



using Newtonsoft.Json;
...
public void xyz()

JsonSerializer ObjectSerializer = new JsonSerializer();
... Do Stuff ...



I can be perfectly sure to have the fitting dll file in a local directory on the concerning machines, so there is registry key where I can read the actual path out of.



Without dynamically wanting to load the dll the code runs fine,
but I hope that something like this would be possible (in the Program.cs - without any using directives to 3rd party dlls!!! - namespace might be loaded anyway):



private static void Main(string args)

string ProgramPath = FindProgramPath();
System.Reflection.Assembly.LoadFrom(ProgramPath + @"System.Net.Http.Formatting.dll");
System.Reflection.Assembly.LoadFrom(ProgramPath + @"Newtonsoft.Json.dll");
... Do Stuff



Should the logic be wrapped around in another file which will be loaded in the current context, maybe as a resource to be sure that the rest of the needed files are loaded accordingly? Or does somebody else know a way to be independent of the folder location without bloating the actual exe file up?










share|improve this question






















  • Maybe you're looking for assembly binding in app.config? You can set your referenced assemblies to CopyLocal = false and use app.config to specify the path where these assemblies should be searched for.

    – dymanoid
    Nov 14 '18 at 13:48











  • I will check this out, thanks! :)

    – mayen
    Nov 14 '18 at 13:51















1















While the programming takes place and you refer to your files in NuGet packages programming with dependencies is not a so big deal, but I made an extension app to an existing application which relies basically on the same dll files as the main program.



Now I don't want to actually place the extension in our main application directory because it is more handy to have it versatile and have the user or admin copy it a to a place they like to.



In pseudocode the code while programming looks like this:



using Newtonsoft.Json;
...
public void xyz()

JsonSerializer ObjectSerializer = new JsonSerializer();
... Do Stuff ...



I can be perfectly sure to have the fitting dll file in a local directory on the concerning machines, so there is registry key where I can read the actual path out of.



Without dynamically wanting to load the dll the code runs fine,
but I hope that something like this would be possible (in the Program.cs - without any using directives to 3rd party dlls!!! - namespace might be loaded anyway):



private static void Main(string args)

string ProgramPath = FindProgramPath();
System.Reflection.Assembly.LoadFrom(ProgramPath + @"System.Net.Http.Formatting.dll");
System.Reflection.Assembly.LoadFrom(ProgramPath + @"Newtonsoft.Json.dll");
... Do Stuff



Should the logic be wrapped around in another file which will be loaded in the current context, maybe as a resource to be sure that the rest of the needed files are loaded accordingly? Or does somebody else know a way to be independent of the folder location without bloating the actual exe file up?










share|improve this question






















  • Maybe you're looking for assembly binding in app.config? You can set your referenced assemblies to CopyLocal = false and use app.config to specify the path where these assemblies should be searched for.

    – dymanoid
    Nov 14 '18 at 13:48











  • I will check this out, thanks! :)

    – mayen
    Nov 14 '18 at 13:51













1












1








1








While the programming takes place and you refer to your files in NuGet packages programming with dependencies is not a so big deal, but I made an extension app to an existing application which relies basically on the same dll files as the main program.



Now I don't want to actually place the extension in our main application directory because it is more handy to have it versatile and have the user or admin copy it a to a place they like to.



In pseudocode the code while programming looks like this:



using Newtonsoft.Json;
...
public void xyz()

JsonSerializer ObjectSerializer = new JsonSerializer();
... Do Stuff ...



I can be perfectly sure to have the fitting dll file in a local directory on the concerning machines, so there is registry key where I can read the actual path out of.



Without dynamically wanting to load the dll the code runs fine,
but I hope that something like this would be possible (in the Program.cs - without any using directives to 3rd party dlls!!! - namespace might be loaded anyway):



private static void Main(string args)

string ProgramPath = FindProgramPath();
System.Reflection.Assembly.LoadFrom(ProgramPath + @"System.Net.Http.Formatting.dll");
System.Reflection.Assembly.LoadFrom(ProgramPath + @"Newtonsoft.Json.dll");
... Do Stuff



Should the logic be wrapped around in another file which will be loaded in the current context, maybe as a resource to be sure that the rest of the needed files are loaded accordingly? Or does somebody else know a way to be independent of the folder location without bloating the actual exe file up?










share|improve this question














While the programming takes place and you refer to your files in NuGet packages programming with dependencies is not a so big deal, but I made an extension app to an existing application which relies basically on the same dll files as the main program.



Now I don't want to actually place the extension in our main application directory because it is more handy to have it versatile and have the user or admin copy it a to a place they like to.



In pseudocode the code while programming looks like this:



using Newtonsoft.Json;
...
public void xyz()

JsonSerializer ObjectSerializer = new JsonSerializer();
... Do Stuff ...



I can be perfectly sure to have the fitting dll file in a local directory on the concerning machines, so there is registry key where I can read the actual path out of.



Without dynamically wanting to load the dll the code runs fine,
but I hope that something like this would be possible (in the Program.cs - without any using directives to 3rd party dlls!!! - namespace might be loaded anyway):



private static void Main(string args)

string ProgramPath = FindProgramPath();
System.Reflection.Assembly.LoadFrom(ProgramPath + @"System.Net.Http.Formatting.dll");
System.Reflection.Assembly.LoadFrom(ProgramPath + @"Newtonsoft.Json.dll");
... Do Stuff



Should the logic be wrapped around in another file which will be loaded in the current context, maybe as a resource to be sure that the rest of the needed files are loaded accordingly? Or does somebody else know a way to be independent of the folder location without bloating the actual exe file up?







c# .net reflection






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 13:27









mayenmayen

475




475












  • Maybe you're looking for assembly binding in app.config? You can set your referenced assemblies to CopyLocal = false and use app.config to specify the path where these assemblies should be searched for.

    – dymanoid
    Nov 14 '18 at 13:48











  • I will check this out, thanks! :)

    – mayen
    Nov 14 '18 at 13:51

















  • Maybe you're looking for assembly binding in app.config? You can set your referenced assemblies to CopyLocal = false and use app.config to specify the path where these assemblies should be searched for.

    – dymanoid
    Nov 14 '18 at 13:48











  • I will check this out, thanks! :)

    – mayen
    Nov 14 '18 at 13:51
















Maybe you're looking for assembly binding in app.config? You can set your referenced assemblies to CopyLocal = false and use app.config to specify the path where these assemblies should be searched for.

– dymanoid
Nov 14 '18 at 13:48





Maybe you're looking for assembly binding in app.config? You can set your referenced assemblies to CopyLocal = false and use app.config to specify the path where these assemblies should be searched for.

– dymanoid
Nov 14 '18 at 13:48













I will check this out, thanks! :)

– mayen
Nov 14 '18 at 13:51





I will check this out, thanks! :)

– mayen
Nov 14 '18 at 13:51












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301351%2floading-dlls-dynamically-from-the-local-disk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301351%2floading-dlls-dynamically-from-the-local-disk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin