Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法加载DLL';Dll1.dll';:此操作仅在应用程序容器的上下文中有效。(HRESULT的例外:0x8007109A)_C#_C++_Asp.net_.net_Dll - Fatal编程技术网

C# 无法加载DLL';Dll1.dll';:此操作仅在应用程序容器的上下文中有效。(HRESULT的例外:0x8007109A)

C# 无法加载DLL';Dll1.dll';:此操作仅在应用程序容器的上下文中有效。(HRESULT的例外:0x8007109A),c#,c++,asp.net,.net,dll,C#,C++,Asp.net,.net,Dll,我有一个ASP.NET应用程序,它试图用pjkK.< /p>从C++ dll调用方法(称为DLL1.DLL)。 这是Dll1.cpp: Tester::Tester() { } void Tester::hello() { int i = 0; } DLL_API void Tester_hello(Tester* pObj) { pObj->hello(); } DLL_API Tester* Tester_Create() { return new Tester();

我有一个ASP.NET应用程序,它试图用pjkK.< /p>从C++ dll调用方法(称为DLL1.DLL)。 这是Dll1.cpp:

Tester::Tester() {

}

void Tester::hello() {
    int i = 0;
}

DLL_API void  Tester_hello(Tester* pObj) { pObj->hello(); }

DLL_API Tester* Tester_Create() { return new Tester(); }

DLL_API void Tester_Delete(Tester* pObj) { delete pObj; }
这是DLL.h:

#define DLL_API __declspec(dllexport)

class DLL_API Tester {
public:
    Tester();
    void hello();
};
这就是我试图在asp.net应用程序中加载dll的地方。注意:我从WebApiConfig调用它只是为了尝试一下,并确保它能正常工作:

public static class WebApiConfig
{
    [DllImport("Dll1.dll")]
    static extern IntPtr Tester_Create();

    [DllImport("Dll1.dll")]
    static extern void Tester_hello(IntPtr pObj);

    [DllImport("Dll1.dll")]
    static extern void Tester_Delete(IntPtr pObj);


    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        IntPtr h = Tester_Create(); <- Exception thrown here
        Tester_hello(h);
        Tester_Delete(h);
    }
}
公共静态类WebApiConfig
{
[DllImport(“Dll1.dll”)]
静态外部IntPtr测试仪_Create();
[DllImport(“Dll1.dll”)]
静态外部孔隙测试仪(IntPtr pObj);
[DllImport(“Dll1.dll”)]
静态外部孔隙测试仪(IntPtr pObj);
公共静态无效寄存器(HttpConfiguration配置)
{
//Web API配置和服务
//将Web API配置为仅使用承载令牌身份验证。
config.SuppressDefaultHostAuthentication();
添加(新的HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
//Web API路由
config.maphttpAttribute路由();
config.Routes.MapHttpRoute(
名称:“DefaultApi”,
routeTemplate:“api/{controller}/{id}”,
默认值:新建{id=RouteParameter.Optional}
);

IntPtr h=Tester_Create();你解决了吗?因为我在这种情况下,我解决了它。有一段时间了,但我认为问题是我正在将我的Dll1.dll构建为winrt dll,ASP.NET无法加载,除非它是作为windows的一部分提供的winrt dll之一(基本上它不能侧向加载不是Microsoft制造的winrt dll)为了让我的DLL加载,我必须重新编译它作为一个本地C++ DLL。