c# - 从 .NET Core 应用程序 P/Invoke Fusion.dll
问题描述
我正在将 .NET 应用程序迁移到 .NET Core,该应用程序需要执行的任务之一是枚举 .NET 全局程序集缓存的程序集(是的,我知道我的.NET Core 应用程序本身不使用GAC,但我的应用程序的目的之一是创建完整 .NET Framework GAC 中的内容的清单)
我尝试 P/Invoke 的任何方法都会Fusion.dll
给我同样的错误:
未处理的异常:System.DllNotFoundException:无法加载 DLL 'Fusion.dll' 或其依赖项之一:找不到指定的模块。(来自 HRESULT 的异常:0x8007007E)
代码示例:
class Program
{
static void Main(string[] args)
{
GacUtility.CreateAssemblyCache(out var x, 0);
}
}
public class GacUtility
{
[DllImport("Fusion.dll")]
public static extern int CreateAssemblyCache(out object asmCache, int reserved);
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
</Project>
注意:我知道CreateAssemblyCache
期望 an 的正确签名IAssemblyName
并且我在我的代码中拥有该权利,这给了我同样的错误。我在object
上面使用来简化可复制的示例。
解决方案
将平台更改为 x64,并指定 dllImport 的完整路径,以及对 IntPtr 而不是对象的签名对我有用,
class Program
{
static void Main(string[] args)
{
GacUtility.CreateAssemblyCache(out IntPtr x, 0);
}
}
public class GacUtility
{
[DllImport(@"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\fusion.dll")]
public static extern int CreateAssemblyCache(out IntPtr asmCache, int reserved);
}
然而,对于 x86,它奇怪地没有
推荐阅读
- android - 在午夜增加共享偏好的数量
- ansible - 从两个数组 Ansible 中获取差异
- vue.js - Vuetify - 清除 v-text-field 时如何触发方法
- html - 均匀间隔图标,无论它们是否有通知徽章
- ios - HTTP 加载失败(错误代码:-1005 [4:-4]) - 但不是 Alamofire
- firebase - 2个日期之间的firebase实时数据库查询日期不匹配任何内容
- python - 使用 python 子进程从无限运行的程序中读取
- node.js - 如何使用 Nginx 通过 express 路由器加载页面
- python - 用户提交表单后,Django视图不呈现数据
- java - 我可以使用 spring boot 覆盖遗留生成代码的 jdbc 目录吗?