除非安装 visual studio,否则无法使用 C++/CLI DLL
Cannot use a C++/CLI DLL unless visual studio is installed
简介
我正在开发一个可以解释和使用 API 蓝图的工具。
我创建了一个新的控制台应用程序,添加了 SnowCrash.NET nuget package 并编写了这段代码:
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);
}
}
}
问题
当我将代码(复制 bin 文件夹)部署到与我的开发环境不同的计算机时,我得到一个指向 SnowCrash.dll
的 FileNotFoundException
这是错误消息中的快照:
Could not load file or assembly 'snowcrashCLR.DLL' or one of its dependencies. The specified module could not be found.
详情:
[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
到目前为止我尝试了什么
- 我在两台机器上都使用了 sysinternal procmon 进行比较,看起来我的开发机器(运行良好)正在加载这个 DLL:
Load Image
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
在出现错误(无法运行)的计算机上,我安装了与上面相同的运行时列表,但这并没有解决问题或使其运行。
我在那台计算机上安装了 visual studio,之前它不起作用,当我尝试我的应用程序时它起作用了
如果您有更好的知识或遇到类似问题,我们将不胜感激。
通过在互联网上进行大量挖掘,我发现 SnowCrash DLL 缺少 运行 所需的依赖项,即 Visual C++ 运行time 2012 x86。
由于它是一个混合的(托管 CLR + 本机)DLL,它需要 C++ MFC 库,它随 VC++ 运行time 一起提供。它必须是正确的版本才能 运行 正确。
将 this MSDN URL 的 运行time 安装到目标计算机上解决了我的问题。
简介
我正在开发一个可以解释和使用 API 蓝图的工具。
我创建了一个新的控制台应用程序,添加了 SnowCrash.NET nuget package 并编写了这段代码:
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);
}
}
}
问题
当我将代码(复制 bin 文件夹)部署到与我的开发环境不同的计算机时,我得到一个指向 SnowCrash.dll
的 FileNotFoundException这是错误消息中的快照:
Could not load file or assembly 'snowcrashCLR.DLL' or one of its dependencies. The specified module could not be found.
详情:
[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
到目前为止我尝试了什么
- 我在两台机器上都使用了 sysinternal procmon 进行比较,看起来我的开发机器(运行良好)正在加载这个 DLL:
Load Image 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
在出现错误(无法运行)的计算机上,我安装了与上面相同的运行时列表,但这并没有解决问题或使其运行。
我在那台计算机上安装了 visual studio,之前它不起作用,当我尝试我的应用程序时它起作用了
如果您有更好的知识或遇到类似问题,我们将不胜感激。
通过在互联网上进行大量挖掘,我发现 SnowCrash DLL 缺少 运行 所需的依赖项,即 Visual C++ 运行time 2012 x86。
由于它是一个混合的(托管 CLR + 本机)DLL,它需要 C++ MFC 库,它随 VC++ 运行time 一起提供。它必须是正确的版本才能 运行 正确。
将 this MSDN URL 的 运行time 安装到目标计算机上解决了我的问题。