title: Can C#(.NET 6) call managed/unmanaged C++ dll?
body: <p>I'm attempting to call a c++ DLL(WinSDK: 10.0.18362.0, Platform Toolset: VS 2017 v141) from C#(the target framework is .NET 6.0) on ARM, and I compiled them for the ARM64 platform but got an exception when it was running:</p>
  <pre><code>System.DllNotFoundException: Unable to load DLL &quot;Calculate.dll&quot; or one of its dependencies: The specified module could not be found.(0x8007007E)   at ConsoleApp1.Program.Sum(int a, int b)
  </code></pre>
  <p><strong>I'm sure I copied the DLL to the application directory and the program which was compiled for x64 platform worked.</strong></p>
  <p>C# Console Application Code:</p>
  <pre><code>internal class Program
      {
          [DllImport(@&quot;Calculate.dll&quot;, CallingConvention = CallingConvention.Cdecl)]
          static extern int Sum(int a, int b);
          public static void Main(string[] args)
          {
              try
              {
                  Console.WriteLine(&quot;Input NumberA:&quot;);
                  int numberA = Convert.ToInt32(Console.ReadLine());
  
                  Console.WriteLine(&quot;Input NumberB:&quot;);
                  int numberB = Convert.ToInt32(Console.ReadLine());
  
                  Console.WriteLine($&quot;The numberA is:{numberA}; the numberB is:{numberB}, the Sum is:{Sum(numberA, numberB)}&quot;);
  
              }
              catch (Exception ex)
              {
                  Console.WriteLine($&quot;ex:{ex}&quot;);
              }
              Console.ReadLine();
          }
      }
  </code></pre>
  <p>Calculate.h code:</p>
  <pre><code>#pragma once
  
  extern &quot;C&quot; __declspec(dllexport) int Sum(int a, int b);
  
  class Calculate
  {
  public:
  
  };
  </code></pre>
  <p>Calculate.cpp code:</p>
  <pre><code>#include &quot;Calculate.h&quot;
  #include &quot;iostream&quot;
  using namespace std;
  
  int Sum(int a, int b)
  {
      if (a - (int)a != 0 || b - (int)b != 0)
      {
          cout &lt;&lt; &quot;Please input a integrate&quot; &lt;&lt; endl;
          return -1;
      }
      return a + b;
  }
  </code></pre>
  <p>I want to know if C#(.NET 6.0) can call managed/unmanaged C++ DLL?
  Are there any suggestions? Thanks in advance!</p>