除非安装了visual studio,否则无法使用C++/CLI DLL

Bis*_*hoy 8 c# stl c++-cli visual-c++ snowcrash

介绍

我正在开发一种可以解释和使用API​​蓝图的工具.

我创建了一个新的控制台应用程序,添加了SnowCrash.NET nuget包并编写了这段代码:

    static void Main(string[] args)
    {
        snowcrashCLR.Blueprint blueprint;
        snowcrashCLR.Result result;

        var path = args.Length > 1 ? args[1] : @"c:\";

        snowcrashCLR.SnowCrashCLR.parse(path, out blueprint, out result);
        if (result != null)
        {
            var warnings = result.GetWarningsCs();
            foreach (var warning in warnings)
            {
                Console.WriteLine("{0}: {1}", warning.code, warning.message);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

问题

当我将代码(复制bin文件夹)部署到与开发环境不同的计算机时,我收到指向SnowCrash.dll的FileNotFoundException

这是一个来自错误消息的snapshop:

无法加载文件或程序集"snowcrashCLR.DLL"或其依赖项之一.指定的模块无法找到.

细节:

[FileNotFoundException: Could not load file or assembly 'snowcrashCLR.DLL' or one of its dependencies. The specified module could not be found.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
   System.Reflection.Assembly.Load(String assemblyString) +28
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的

  • 我在两台机器上使用sysinternal procmon进行比较,看起来我的dev机器(运行正常)正在加载这个DLL:

加载图像 C:\ Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualC.STLCLR\v4.0_2.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualC.STLCLR.dll

  • 我的计算机,应用程序正常工作,安装了这些运行时
MS Visual C++ 2005 Redist (x64)
MS Visual C++ 2008 Redist (x64) 9.0.30729.4148
MS Visual C++ 2008 Redist (x64) 9.0.30729.6161
MS Visual C++ 2008 Redist (x86) 9.0.30729.4148
MS Visual C++ 2008 Redist (x86) 9.0.30729.6161
MS Visual C++ 2010 x64 Redist - 10.0.40219
MS Visual C++ 2013 x64 Redist - 12.0.30501
MS Visual C++ 2013 x86 Redist - 12.0.30501
Run Code Online (Sandbox Code Playgroud)
  • 在出现错误(不起作用)的计算机上,我安装了相同的上述运行时列表,但这并没有解决问题或使其工作.

  • 我在那台计算机上安装了visual studio,以前没有工作,当我尝试我的应用程序时,它工作正常

如果您有更好的知识或类似问题的战斗伤痕,我们将非常感谢您的帮助.

Bis*_*hoy 2

通过对互联网进行大量挖掘,我发现 SnowCrash DLL 缺少运行所需的依赖项,即 Visual C++ 运行时 2012 x86。

由于它是一个混合(托管 CLR + 本机)DLL,因此它需要 VC++ 运行时附带的 C++ MFC 库。并且它必须是正确的版本才能正常运行。

通过此 MSDN URL将运行时安装到目标计算机上解决了我的问题。