none
.NET Standard 2.0 and System.Security.Crytography.Cng RRS feed

  • Question

  • Hi,

    I am trying to create a .NET Standard 2.0 library that can be called by a .NET 4.7.2 application.

    I am getting an error: System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Security.Cryptography.Cng, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

    Here are the steps (in my little test setup);

    1.) Create a .NET Standard 2.0 library in Visual Studio 2017

    2.) Get a NuGet package for System.Security.Crytography.Cng (it gives me version 4.5.0 as the latest version)

    3.) In the library dll, make a call to System.Security.Crytography.Cng  (all compiles ok)

    4.) Create a simple command line program in .NET 4.7.2 and reference this .NET Standard 2.0 library.  (all compiles ok).

    5.) Run the command line application.  When the library is called, gives the error: System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Security.Cryptography.Cng, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

    Thoughts on the issue?

    -------------------

    Code Sample:

    COMMAND LINE APP (.NET FRAMEWORK 4.7.2)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp
    {
      class Program
      {
        static void Main(string[] args)
        {
          int x = ClassLibrary1.Class1.GetEncryptedValue();
        }
      }
    }

    ==========================

    CLASS LIBRARY (.NET STANDARD 2.0)

    using System;

    namespace ClassLibrary1
    {
      static public class Class1
      {
        static public int GetEncryptedValue()
        {
          int i = 3;

          System.Security.Cryptography.AesCng aes = new System.Security.Cryptography.AesCng();

          return i;
        }

      }
    }


    greenstone90

    Tuesday, April 30, 2019 2:44 AM

Answers

  • Hi

    Thank for posting here.

    For your question, you want to solve the exception that you got.

    I have reproduced your problem, you could try to add reference(System.Security.Crytography.Cng) for Console application to solve the exception.

    Result:https://1drv.ms/u/s!Ast0x04bo32WggJbSDyUTN7AhjAk​​​​​​​

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, April 30, 2019 7:46 AM
    Moderator

All replies

  • Hi

    Thank for posting here.

    For your question, you want to solve the exception that you got.

    I have reproduced your problem, you could try to add reference(System.Security.Crytography.Cng) for Console application to solve the exception.

    Result:https://1drv.ms/u/s!Ast0x04bo32WggJbSDyUTN7AhjAk​​​​​​​

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, April 30, 2019 7:46 AM
    Moderator
  • Thanks Jack for you're great answer and showing me in the video!


    greenstone90

    Tuesday, April 30, 2019 4:38 PM