Why Does Command Line C# Interactive (csi.exe) Ignore Explicit Assembly Reference?









up vote
0
down vote

favorite
1












Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208



Windows 7 64 bit



NBitcoin 4.1.1.68



====



System.Security.Cryptography.Algorithms version 4.3.0.0 has an SHA256Managed class that I want to use in C# Interactive (csi.exe).



I added that assembly to the GAC with the gacutil -i [path_to_dll] command. I launched csi with an /r:[path_to_dll_dir]/System.Security.Cryptography.Algorithms.dll command line option.



On top of that, after csi started, I also did an #r "[path_to_dll]" reference. Belt and suspenders type stuff. I know. But I guess I was hoping the overkill would force it to do the right thing.



My application uses a class from a third-party library. The following code was copied pretty much verbatim from the third-party method my app calls. If I run the following code in csi, it works fine...



using System;
using System.Security.Cryptography;

byte b = Guid.NewGuid().ToByteArray();

var sha = new SHA256Managed();

byte c = sha.ComputeHash(b, 0, 15);


Now, here's the thing. That third-party class defines a method that calls SHA256Managed.ComputeHash(byte, int, int) exactly like the code above.



For the sake of discussion, let's refer to the third party class and method as Foo.m().



The problem is, when I call the third party Foo.m() from csi, csi balks with...



Could not load type 'System.Security.Cryptography.SHA256Managed' from assembly 'System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
+ Third.Party.Foo.m(byte, int, int)


Remember I explicitly added the version 4.3.0.0 crypto algorithm assembly into the GAC. Plus I explictly referenced the dll with both #r and /r:. So what gives?



I can see in the FusLogVw binding logs that csi is loading the version 4.0.0.0 assembly; in spite of me explicitly insisting on using version 4.3.0.0. System.Security.Cryptography.Algorithms version 4.0.0.0 does not have an SHA256Managed class.



Please help me figure out how to make csi use the assembly I tell it to use? Bear in mind, that it uses the right version for code written directly in csi. So why is it not using the correct assembly version for the exact same code in a third-party library?










share|improve this question





















  • What version of assembly referenced by library?
    – PetSerAl
    Nov 11 at 23:57










  • Version 4.3.0, @PetSerAl—as far as I can tell by traversing the link I provided above: a third-party library -> System.Net.Http -Version 4.3.3 -> System.Security.Cryptography.X509Certificates -Version 4.3.0 -> System.Security.Cryptography.Algorithms -Version 4.3.0
    – deduper
    Nov 12 at 0:14











  • ... Also, calling the third-party library in VS 2017's C# Interactive window works as expected. And I have confirmed that that one uses v4.3.0.0 of the assembly.
    – deduper
    Nov 12 at 0:18










  • Are you sure that you are referencing .NET Framework version of NBitcoin assembly and not .NET Core one?
    – PetSerAl
    Nov 12 at 0:24











  • No actually, @PetSerAl. I am not 100% sure. I'm new to .NET. Too new to know what the difference between the two are, I'm afraid. So I only assumed csi was using .NET framework. What steps do I take to determine for sure which one is being referenced?
    – deduper
    Nov 12 at 0:29














up vote
0
down vote

favorite
1












Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208



Windows 7 64 bit



NBitcoin 4.1.1.68



====



System.Security.Cryptography.Algorithms version 4.3.0.0 has an SHA256Managed class that I want to use in C# Interactive (csi.exe).



I added that assembly to the GAC with the gacutil -i [path_to_dll] command. I launched csi with an /r:[path_to_dll_dir]/System.Security.Cryptography.Algorithms.dll command line option.



On top of that, after csi started, I also did an #r "[path_to_dll]" reference. Belt and suspenders type stuff. I know. But I guess I was hoping the overkill would force it to do the right thing.



My application uses a class from a third-party library. The following code was copied pretty much verbatim from the third-party method my app calls. If I run the following code in csi, it works fine...



using System;
using System.Security.Cryptography;

byte b = Guid.NewGuid().ToByteArray();

var sha = new SHA256Managed();

byte c = sha.ComputeHash(b, 0, 15);


Now, here's the thing. That third-party class defines a method that calls SHA256Managed.ComputeHash(byte, int, int) exactly like the code above.



For the sake of discussion, let's refer to the third party class and method as Foo.m().



The problem is, when I call the third party Foo.m() from csi, csi balks with...



Could not load type 'System.Security.Cryptography.SHA256Managed' from assembly 'System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
+ Third.Party.Foo.m(byte, int, int)


Remember I explicitly added the version 4.3.0.0 crypto algorithm assembly into the GAC. Plus I explictly referenced the dll with both #r and /r:. So what gives?



I can see in the FusLogVw binding logs that csi is loading the version 4.0.0.0 assembly; in spite of me explicitly insisting on using version 4.3.0.0. System.Security.Cryptography.Algorithms version 4.0.0.0 does not have an SHA256Managed class.



Please help me figure out how to make csi use the assembly I tell it to use? Bear in mind, that it uses the right version for code written directly in csi. So why is it not using the correct assembly version for the exact same code in a third-party library?










share|improve this question





















  • What version of assembly referenced by library?
    – PetSerAl
    Nov 11 at 23:57










  • Version 4.3.0, @PetSerAl—as far as I can tell by traversing the link I provided above: a third-party library -> System.Net.Http -Version 4.3.3 -> System.Security.Cryptography.X509Certificates -Version 4.3.0 -> System.Security.Cryptography.Algorithms -Version 4.3.0
    – deduper
    Nov 12 at 0:14











  • ... Also, calling the third-party library in VS 2017's C# Interactive window works as expected. And I have confirmed that that one uses v4.3.0.0 of the assembly.
    – deduper
    Nov 12 at 0:18










  • Are you sure that you are referencing .NET Framework version of NBitcoin assembly and not .NET Core one?
    – PetSerAl
    Nov 12 at 0:24











  • No actually, @PetSerAl. I am not 100% sure. I'm new to .NET. Too new to know what the difference between the two are, I'm afraid. So I only assumed csi was using .NET framework. What steps do I take to determine for sure which one is being referenced?
    – deduper
    Nov 12 at 0:29












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208



Windows 7 64 bit



NBitcoin 4.1.1.68



====



System.Security.Cryptography.Algorithms version 4.3.0.0 has an SHA256Managed class that I want to use in C# Interactive (csi.exe).



I added that assembly to the GAC with the gacutil -i [path_to_dll] command. I launched csi with an /r:[path_to_dll_dir]/System.Security.Cryptography.Algorithms.dll command line option.



On top of that, after csi started, I also did an #r "[path_to_dll]" reference. Belt and suspenders type stuff. I know. But I guess I was hoping the overkill would force it to do the right thing.



My application uses a class from a third-party library. The following code was copied pretty much verbatim from the third-party method my app calls. If I run the following code in csi, it works fine...



using System;
using System.Security.Cryptography;

byte b = Guid.NewGuid().ToByteArray();

var sha = new SHA256Managed();

byte c = sha.ComputeHash(b, 0, 15);


Now, here's the thing. That third-party class defines a method that calls SHA256Managed.ComputeHash(byte, int, int) exactly like the code above.



For the sake of discussion, let's refer to the third party class and method as Foo.m().



The problem is, when I call the third party Foo.m() from csi, csi balks with...



Could not load type 'System.Security.Cryptography.SHA256Managed' from assembly 'System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
+ Third.Party.Foo.m(byte, int, int)


Remember I explicitly added the version 4.3.0.0 crypto algorithm assembly into the GAC. Plus I explictly referenced the dll with both #r and /r:. So what gives?



I can see in the FusLogVw binding logs that csi is loading the version 4.0.0.0 assembly; in spite of me explicitly insisting on using version 4.3.0.0. System.Security.Cryptography.Algorithms version 4.0.0.0 does not have an SHA256Managed class.



Please help me figure out how to make csi use the assembly I tell it to use? Bear in mind, that it uses the right version for code written directly in csi. So why is it not using the correct assembly version for the exact same code in a third-party library?










share|improve this question













Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208



Windows 7 64 bit



NBitcoin 4.1.1.68



====



System.Security.Cryptography.Algorithms version 4.3.0.0 has an SHA256Managed class that I want to use in C# Interactive (csi.exe).



I added that assembly to the GAC with the gacutil -i [path_to_dll] command. I launched csi with an /r:[path_to_dll_dir]/System.Security.Cryptography.Algorithms.dll command line option.



On top of that, after csi started, I also did an #r "[path_to_dll]" reference. Belt and suspenders type stuff. I know. But I guess I was hoping the overkill would force it to do the right thing.



My application uses a class from a third-party library. The following code was copied pretty much verbatim from the third-party method my app calls. If I run the following code in csi, it works fine...



using System;
using System.Security.Cryptography;

byte b = Guid.NewGuid().ToByteArray();

var sha = new SHA256Managed();

byte c = sha.ComputeHash(b, 0, 15);


Now, here's the thing. That third-party class defines a method that calls SHA256Managed.ComputeHash(byte, int, int) exactly like the code above.



For the sake of discussion, let's refer to the third party class and method as Foo.m().



The problem is, when I call the third party Foo.m() from csi, csi balks with...



Could not load type 'System.Security.Cryptography.SHA256Managed' from assembly 'System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
+ Third.Party.Foo.m(byte, int, int)


Remember I explicitly added the version 4.3.0.0 crypto algorithm assembly into the GAC. Plus I explictly referenced the dll with both #r and /r:. So what gives?



I can see in the FusLogVw binding logs that csi is loading the version 4.0.0.0 assembly; in spite of me explicitly insisting on using version 4.3.0.0. System.Security.Cryptography.Algorithms version 4.0.0.0 does not have an SHA256Managed class.



Please help me figure out how to make csi use the assembly I tell it to use? Bear in mind, that it uses the right version for code written directly in csi. So why is it not using the correct assembly version for the exact same code in a third-party library?







c# .net roslyn nbitcoin csi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 22:14









deduper

1619




1619











  • What version of assembly referenced by library?
    – PetSerAl
    Nov 11 at 23:57










  • Version 4.3.0, @PetSerAl—as far as I can tell by traversing the link I provided above: a third-party library -> System.Net.Http -Version 4.3.3 -> System.Security.Cryptography.X509Certificates -Version 4.3.0 -> System.Security.Cryptography.Algorithms -Version 4.3.0
    – deduper
    Nov 12 at 0:14











  • ... Also, calling the third-party library in VS 2017's C# Interactive window works as expected. And I have confirmed that that one uses v4.3.0.0 of the assembly.
    – deduper
    Nov 12 at 0:18










  • Are you sure that you are referencing .NET Framework version of NBitcoin assembly and not .NET Core one?
    – PetSerAl
    Nov 12 at 0:24











  • No actually, @PetSerAl. I am not 100% sure. I'm new to .NET. Too new to know what the difference between the two are, I'm afraid. So I only assumed csi was using .NET framework. What steps do I take to determine for sure which one is being referenced?
    – deduper
    Nov 12 at 0:29
















  • What version of assembly referenced by library?
    – PetSerAl
    Nov 11 at 23:57










  • Version 4.3.0, @PetSerAl—as far as I can tell by traversing the link I provided above: a third-party library -> System.Net.Http -Version 4.3.3 -> System.Security.Cryptography.X509Certificates -Version 4.3.0 -> System.Security.Cryptography.Algorithms -Version 4.3.0
    – deduper
    Nov 12 at 0:14











  • ... Also, calling the third-party library in VS 2017's C# Interactive window works as expected. And I have confirmed that that one uses v4.3.0.0 of the assembly.
    – deduper
    Nov 12 at 0:18










  • Are you sure that you are referencing .NET Framework version of NBitcoin assembly and not .NET Core one?
    – PetSerAl
    Nov 12 at 0:24











  • No actually, @PetSerAl. I am not 100% sure. I'm new to .NET. Too new to know what the difference between the two are, I'm afraid. So I only assumed csi was using .NET framework. What steps do I take to determine for sure which one is being referenced?
    – deduper
    Nov 12 at 0:29















What version of assembly referenced by library?
– PetSerAl
Nov 11 at 23:57




What version of assembly referenced by library?
– PetSerAl
Nov 11 at 23:57












Version 4.3.0, @PetSerAl—as far as I can tell by traversing the link I provided above: a third-party library -> System.Net.Http -Version 4.3.3 -> System.Security.Cryptography.X509Certificates -Version 4.3.0 -> System.Security.Cryptography.Algorithms -Version 4.3.0
– deduper
Nov 12 at 0:14





Version 4.3.0, @PetSerAl—as far as I can tell by traversing the link I provided above: a third-party library -> System.Net.Http -Version 4.3.3 -> System.Security.Cryptography.X509Certificates -Version 4.3.0 -> System.Security.Cryptography.Algorithms -Version 4.3.0
– deduper
Nov 12 at 0:14













... Also, calling the third-party library in VS 2017's C# Interactive window works as expected. And I have confirmed that that one uses v4.3.0.0 of the assembly.
– deduper
Nov 12 at 0:18




... Also, calling the third-party library in VS 2017's C# Interactive window works as expected. And I have confirmed that that one uses v4.3.0.0 of the assembly.
– deduper
Nov 12 at 0:18












Are you sure that you are referencing .NET Framework version of NBitcoin assembly and not .NET Core one?
– PetSerAl
Nov 12 at 0:24





Are you sure that you are referencing .NET Framework version of NBitcoin assembly and not .NET Core one?
– PetSerAl
Nov 12 at 0:24













No actually, @PetSerAl. I am not 100% sure. I'm new to .NET. Too new to know what the difference between the two are, I'm afraid. So I only assumed csi was using .NET framework. What steps do I take to determine for sure which one is being referenced?
– deduper
Nov 12 at 0:29




No actually, @PetSerAl. I am not 100% sure. I'm new to .NET. Too new to know what the difference between the two are, I'm afraid. So I only assumed csi was using .NET framework. What steps do I take to determine for sure which one is being referenced?
– deduper
Nov 12 at 0:29












1 Answer
1






active

oldest

votes

















up vote
0
down vote













TL;DR: The csi newb that I am, after installing the third-party lib for the first time two days ago, I copied its dll plus all its dependencies into a subdirectory of csi's bin directory to get csi to find and load it.




Long Answer: After bouncing some ideas off of the knowledgeable and helpful C# expert @PetSerAl, I eventually figured out what the answer to my original question was.



A FusLogVw Assembly Binding Log Entry that I encountered very soon after installing the third-party lib, lead to me putting the third-party dll into a sub directory of csi's bin dir. That appears to have inadvertently thwarted csi's assembly lookup mechanism from doing a complete probe of all the locations it should have looked for assemblies. As a result, csi was finding and referencing its own preinstalled older version of System.Security.Cryptography.Algorithms which is distributed with csi as part of the original VS 2017 installation.



Consequently, that made csi ignore both the subsequent /r: and #r references to the Algorithm dll that I was passing it. So it wasn't finding the non-existent SHA256Managed type in its own, older 4.0.0.0 version of the assembly it had in its bin dir. That's what caused the assembly binder error reported in the original post.



Removing the third-party assembly and co from csi's bin subdir did the trick. From there, getting csi to work correctly with the third-party library was just a matter of launching csi with the right assembly references...



C:>csi /u:NBitcoin /u:NBitcoin.Crypto /u:System.Security.Cryptography /lib:[my_vs_2017_project_dir]binReleasenet461;[my_vs_2017_home_dir]2017CommunityMSBuild15.0binRoslyn /r:System.Data.dll /r:System.Drawing.dll /r:System.IO.Compression.FileSystem.dll /r:System.Numerics.dll /r:System.Runtime.Serialization.dll /r:System.Xml.dll /r:System.Xml.Linq.dll /r:Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Newtonsoft.Json.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Buffers.dll /r:[my_nuget_repo_pkgs_dir]system.net.http4.3.4libnet46System.Net.Http.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Net.Requests.dll /r:[my_nuget_repo_pkgs_dir]nbitcoin4.1.1.68libnet461NBitcoin.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.algorithms4.3.0libnet461System.Security.Cryptography.Algorithms.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.csp4.3.0libnet46System.Security.Cryptography.Csp.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.encoding4.3.0libnet46System.Security.Cryptography.Encoding.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.primitives4.3.0libnet46System.Security.Cryptography.Primitives.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.x509certificates4.3.0libnet461System.Security.Cryptography.X509Certificates.dll 
Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208
Copyright (C) Microsoft Corporation. All rights reserved.

Type "#help" for more information.
>
> Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
Hello World! L2emt8acTdsGMXzJfAMSARUvKvP8xUCULcQbpiY76EpeyvKyrir2
>


I'm pretty sure there's a less verbose way to pass all those /r: and /u: options on csi startup. But just getting it to find and load the correct assemblies is the main thing.






share|improve this answer






















    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',
    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%2f53253773%2fwhy-does-command-line-c-sharp-interactive-csi-exe-ignore-explicit-assembly-ref%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    TL;DR: The csi newb that I am, after installing the third-party lib for the first time two days ago, I copied its dll plus all its dependencies into a subdirectory of csi's bin directory to get csi to find and load it.




    Long Answer: After bouncing some ideas off of the knowledgeable and helpful C# expert @PetSerAl, I eventually figured out what the answer to my original question was.



    A FusLogVw Assembly Binding Log Entry that I encountered very soon after installing the third-party lib, lead to me putting the third-party dll into a sub directory of csi's bin dir. That appears to have inadvertently thwarted csi's assembly lookup mechanism from doing a complete probe of all the locations it should have looked for assemblies. As a result, csi was finding and referencing its own preinstalled older version of System.Security.Cryptography.Algorithms which is distributed with csi as part of the original VS 2017 installation.



    Consequently, that made csi ignore both the subsequent /r: and #r references to the Algorithm dll that I was passing it. So it wasn't finding the non-existent SHA256Managed type in its own, older 4.0.0.0 version of the assembly it had in its bin dir. That's what caused the assembly binder error reported in the original post.



    Removing the third-party assembly and co from csi's bin subdir did the trick. From there, getting csi to work correctly with the third-party library was just a matter of launching csi with the right assembly references...



    C:>csi /u:NBitcoin /u:NBitcoin.Crypto /u:System.Security.Cryptography /lib:[my_vs_2017_project_dir]binReleasenet461;[my_vs_2017_home_dir]2017CommunityMSBuild15.0binRoslyn /r:System.Data.dll /r:System.Drawing.dll /r:System.IO.Compression.FileSystem.dll /r:System.Numerics.dll /r:System.Runtime.Serialization.dll /r:System.Xml.dll /r:System.Xml.Linq.dll /r:Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Newtonsoft.Json.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Buffers.dll /r:[my_nuget_repo_pkgs_dir]system.net.http4.3.4libnet46System.Net.Http.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Net.Requests.dll /r:[my_nuget_repo_pkgs_dir]nbitcoin4.1.1.68libnet461NBitcoin.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.algorithms4.3.0libnet461System.Security.Cryptography.Algorithms.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.csp4.3.0libnet46System.Security.Cryptography.Csp.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.encoding4.3.0libnet46System.Security.Cryptography.Encoding.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.primitives4.3.0libnet46System.Security.Cryptography.Primitives.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.x509certificates4.3.0libnet461System.Security.Cryptography.X509Certificates.dll 
    Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208
    Copyright (C) Microsoft Corporation. All rights reserved.

    Type "#help" for more information.
    >
    > Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
    Hello World! L2emt8acTdsGMXzJfAMSARUvKvP8xUCULcQbpiY76EpeyvKyrir2
    >


    I'm pretty sure there's a less verbose way to pass all those /r: and /u: options on csi startup. But just getting it to find and load the correct assemblies is the main thing.






    share|improve this answer


























      up vote
      0
      down vote













      TL;DR: The csi newb that I am, after installing the third-party lib for the first time two days ago, I copied its dll plus all its dependencies into a subdirectory of csi's bin directory to get csi to find and load it.




      Long Answer: After bouncing some ideas off of the knowledgeable and helpful C# expert @PetSerAl, I eventually figured out what the answer to my original question was.



      A FusLogVw Assembly Binding Log Entry that I encountered very soon after installing the third-party lib, lead to me putting the third-party dll into a sub directory of csi's bin dir. That appears to have inadvertently thwarted csi's assembly lookup mechanism from doing a complete probe of all the locations it should have looked for assemblies. As a result, csi was finding and referencing its own preinstalled older version of System.Security.Cryptography.Algorithms which is distributed with csi as part of the original VS 2017 installation.



      Consequently, that made csi ignore both the subsequent /r: and #r references to the Algorithm dll that I was passing it. So it wasn't finding the non-existent SHA256Managed type in its own, older 4.0.0.0 version of the assembly it had in its bin dir. That's what caused the assembly binder error reported in the original post.



      Removing the third-party assembly and co from csi's bin subdir did the trick. From there, getting csi to work correctly with the third-party library was just a matter of launching csi with the right assembly references...



      C:>csi /u:NBitcoin /u:NBitcoin.Crypto /u:System.Security.Cryptography /lib:[my_vs_2017_project_dir]binReleasenet461;[my_vs_2017_home_dir]2017CommunityMSBuild15.0binRoslyn /r:System.Data.dll /r:System.Drawing.dll /r:System.IO.Compression.FileSystem.dll /r:System.Numerics.dll /r:System.Runtime.Serialization.dll /r:System.Xml.dll /r:System.Xml.Linq.dll /r:Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Newtonsoft.Json.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Buffers.dll /r:[my_nuget_repo_pkgs_dir]system.net.http4.3.4libnet46System.Net.Http.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Net.Requests.dll /r:[my_nuget_repo_pkgs_dir]nbitcoin4.1.1.68libnet461NBitcoin.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.algorithms4.3.0libnet461System.Security.Cryptography.Algorithms.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.csp4.3.0libnet46System.Security.Cryptography.Csp.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.encoding4.3.0libnet46System.Security.Cryptography.Encoding.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.primitives4.3.0libnet46System.Security.Cryptography.Primitives.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.x509certificates4.3.0libnet461System.Security.Cryptography.X509Certificates.dll 
      Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208
      Copyright (C) Microsoft Corporation. All rights reserved.

      Type "#help" for more information.
      >
      > Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
      Hello World! L2emt8acTdsGMXzJfAMSARUvKvP8xUCULcQbpiY76EpeyvKyrir2
      >


      I'm pretty sure there's a less verbose way to pass all those /r: and /u: options on csi startup. But just getting it to find and load the correct assemblies is the main thing.






      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        TL;DR: The csi newb that I am, after installing the third-party lib for the first time two days ago, I copied its dll plus all its dependencies into a subdirectory of csi's bin directory to get csi to find and load it.




        Long Answer: After bouncing some ideas off of the knowledgeable and helpful C# expert @PetSerAl, I eventually figured out what the answer to my original question was.



        A FusLogVw Assembly Binding Log Entry that I encountered very soon after installing the third-party lib, lead to me putting the third-party dll into a sub directory of csi's bin dir. That appears to have inadvertently thwarted csi's assembly lookup mechanism from doing a complete probe of all the locations it should have looked for assemblies. As a result, csi was finding and referencing its own preinstalled older version of System.Security.Cryptography.Algorithms which is distributed with csi as part of the original VS 2017 installation.



        Consequently, that made csi ignore both the subsequent /r: and #r references to the Algorithm dll that I was passing it. So it wasn't finding the non-existent SHA256Managed type in its own, older 4.0.0.0 version of the assembly it had in its bin dir. That's what caused the assembly binder error reported in the original post.



        Removing the third-party assembly and co from csi's bin subdir did the trick. From there, getting csi to work correctly with the third-party library was just a matter of launching csi with the right assembly references...



        C:>csi /u:NBitcoin /u:NBitcoin.Crypto /u:System.Security.Cryptography /lib:[my_vs_2017_project_dir]binReleasenet461;[my_vs_2017_home_dir]2017CommunityMSBuild15.0binRoslyn /r:System.Data.dll /r:System.Drawing.dll /r:System.IO.Compression.FileSystem.dll /r:System.Numerics.dll /r:System.Runtime.Serialization.dll /r:System.Xml.dll /r:System.Xml.Linq.dll /r:Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Newtonsoft.Json.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Buffers.dll /r:[my_nuget_repo_pkgs_dir]system.net.http4.3.4libnet46System.Net.Http.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Net.Requests.dll /r:[my_nuget_repo_pkgs_dir]nbitcoin4.1.1.68libnet461NBitcoin.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.algorithms4.3.0libnet461System.Security.Cryptography.Algorithms.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.csp4.3.0libnet46System.Security.Cryptography.Csp.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.encoding4.3.0libnet46System.Security.Cryptography.Encoding.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.primitives4.3.0libnet46System.Security.Cryptography.Primitives.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.x509certificates4.3.0libnet461System.Security.Cryptography.X509Certificates.dll 
        Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208
        Copyright (C) Microsoft Corporation. All rights reserved.

        Type "#help" for more information.
        >
        > Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
        Hello World! L2emt8acTdsGMXzJfAMSARUvKvP8xUCULcQbpiY76EpeyvKyrir2
        >


        I'm pretty sure there's a less verbose way to pass all those /r: and /u: options on csi startup. But just getting it to find and load the correct assemblies is the main thing.






        share|improve this answer














        TL;DR: The csi newb that I am, after installing the third-party lib for the first time two days ago, I copied its dll plus all its dependencies into a subdirectory of csi's bin directory to get csi to find and load it.




        Long Answer: After bouncing some ideas off of the knowledgeable and helpful C# expert @PetSerAl, I eventually figured out what the answer to my original question was.



        A FusLogVw Assembly Binding Log Entry that I encountered very soon after installing the third-party lib, lead to me putting the third-party dll into a sub directory of csi's bin dir. That appears to have inadvertently thwarted csi's assembly lookup mechanism from doing a complete probe of all the locations it should have looked for assemblies. As a result, csi was finding and referencing its own preinstalled older version of System.Security.Cryptography.Algorithms which is distributed with csi as part of the original VS 2017 installation.



        Consequently, that made csi ignore both the subsequent /r: and #r references to the Algorithm dll that I was passing it. So it wasn't finding the non-existent SHA256Managed type in its own, older 4.0.0.0 version of the assembly it had in its bin dir. That's what caused the assembly binder error reported in the original post.



        Removing the third-party assembly and co from csi's bin subdir did the trick. From there, getting csi to work correctly with the third-party library was just a matter of launching csi with the right assembly references...



        C:>csi /u:NBitcoin /u:NBitcoin.Crypto /u:System.Security.Cryptography /lib:[my_vs_2017_project_dir]binReleasenet461;[my_vs_2017_home_dir]2017CommunityMSBuild15.0binRoslyn /r:System.Data.dll /r:System.Drawing.dll /r:System.IO.Compression.FileSystem.dll /r:System.Numerics.dll /r:System.Runtime.Serialization.dll /r:System.Xml.dll /r:System.Xml.Linq.dll /r:Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Microsoft.Extensions.Logging.Abstractions.dll /r:[my_vs_2017_project_dir]binReleasenet461Newtonsoft.Json.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Buffers.dll /r:[my_nuget_repo_pkgs_dir]system.net.http4.3.4libnet46System.Net.Http.dll /r:[my_vs_2017_project_dir]binReleasenet461System.Net.Requests.dll /r:[my_nuget_repo_pkgs_dir]nbitcoin4.1.1.68libnet461NBitcoin.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.algorithms4.3.0libnet461System.Security.Cryptography.Algorithms.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.csp4.3.0libnet46System.Security.Cryptography.Csp.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.encoding4.3.0libnet46System.Security.Cryptography.Encoding.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.primitives4.3.0libnet46System.Security.Cryptography.Primitives.dll /r:[my_nuget_repo_pkgs_dir]system.security.cryptography.x509certificates4.3.0libnet461System.Security.Cryptography.X509Certificates.dll 
        Microsoft (R) Visual C# Interactive Compiler version 2.9.0.63208
        Copyright (C) Microsoft Corporation. All rights reserved.

        Type "#help" for more information.
        >
        > Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
        Hello World! L2emt8acTdsGMXzJfAMSARUvKvP8xUCULcQbpiY76EpeyvKyrir2
        >


        I'm pretty sure there's a less verbose way to pass all those /r: and /u: options on csi startup. But just getting it to find and load the correct assemblies is the main thing.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 at 12:15

























        answered Nov 12 at 3:54









        deduper

        1619




        1619



























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53253773%2fwhy-does-command-line-c-sharp-interactive-csi-exe-ignore-explicit-assembly-ref%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto