简体   繁体   English

从.NET Core应用程序P /调用Fusion.dll

[英]P/Invoke Fusion.dll from a .NET Core application

I'm migrating a .NET application to .NET Core, and one of the tasks that the app needs to do, is to enumerate assemblies the .NET Global Assembly Cache ( yes, I know my .NET Core app itself doesn't use the GAC, but one of the purposes of my app is to create an inventory of what is in the full .NET Framework GAC ) 我正在将.NET应用程序迁移到.NET Core,该应用程序需要执行的任务之一是枚举.NET全局程序集缓存的程序集( 是的,我知道我的 .NET Core应用程序本身并未使用GAC,但我的应用程序的目的之一是创建完整的.NET Framework GAC中的清单

Any method that I try to P/Invoke in the Fusion.dll gives me the same error: 我尝试在Fusion.dll进行P / Invoke的任何方法Fusion.dll给我同样的错误:

Unhandled Exception: System.DllNotFoundException : Unable to load DLL 'Fusion.dll' or one of its dependencies: The specified module could not be found. 未处理的异常: System.DllNotFoundException :无法加载DLL'Fusion.dll'或其依赖项之一:找不到指定的模块。 (Exception from HRESULT: 0x8007007E) (来自HRESULT的异常:0x8007007E)

Code example: 代码示例:

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>

NB: I know that correct signature of CreateAssemblyCache expects an IAssemblyName and I have that right in my code , which gives me the same error. 注意:我知道正确的CreateAssemblyCache签名需要一个IAssemblyName并且我的代码中具有正确的权限 ,这给了我同样的错误。 I'm using object above to simplify a reproduceable example. 我使用上面的object来简化可重现的示例。

Changing platform to x64, and specifying full path to the dllImport, and the signiture to IntPtr instead of object worked for me, 将平台更改为x64,并指定dllImport的完整路径,并使用IntPtr而不是object的签名对我有用,

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);
}

yet, for x86 it strangely did not 但是,对于x86,奇怪的是没有

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM