C# AccessViolationException-调用Botan::LibraryInitializer时

C# AccessViolationException-调用Botan::LibraryInitializer时,c#,c++-cli,botan,C#,C++ Cli,Botan,我正在.NET中为Botan crypto构建一个托管包装器,并按照这里的入门说明进行操作 和 我试图首先执行LibraryInitializer,但当我调用它时,它会在我的INIT()方法中抛出AccessViolationException 我的代码是这样的 C#测试程序 using System; using System.Collections.Generic; using System.Linq; using System.Text; using BotanCrypto_Manage

我正在.NET中为Botan crypto构建一个托管包装器,并按照这里的入门说明进行操作

我试图首先执行LibraryInitializer,但当我调用它时,它会在我的INIT()方法中抛出AccessViolationException

我的代码是这样的

C#测试程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotanCrypto_ManagedWrapper;
using System.Numerics;

namespace TestBotanWrapper
{
    class Program
    {
        static void Main(string[] args)
        {
            BotanCrypto BC = new BotanCrypto();
            BC.INIT();


            UInt64 num = 100;

            BigInteger b = BC.Test(num);


            Console.WriteLine(b);
            Console.ReadKey();
        }
    }
}
包装器CPP

// This is the main DLL file.

#include "stdafx.h"

#include "BotanCrypto_ManagedWrapper.h"
using namespace BotanCrypto_ManagedWrapper;

void BotanCrypto::INIT(){
    LibraryInitializer init;

}

BigInteger BotanCrypto::Test(UInt64 x){
    //try{
        BigInt n = 1000000;
        x = 2;
    //}catch(SystemException^ ex){

    //  x = 0;
    //}
    return x;
}
包装头

// BotanCrypto_ManagedWrapper.h

#pragma once

using namespace System;
using namespace Numerics;
using namespace Botan;

namespace BotanCrypto_ManagedWrapper {

    public ref class BotanCrypto
    {
        // TODO: Add your methods for this class here.
    public:
        BigInteger Test(UInt64 k);
        void INIT();
    };


}
我甚至不知道我是否正确地给图书馆初始化者打了电话。我对C++不太熟悉。感谢您的帮助。谢谢

我在Win32控制台应用程序中尝试了相同的方法,但得到了相同的结果

#include "stdafx.h"
#include <botan/botan.h>

int _tmain(int argc, _TCHAR* argv[])
{
   try
      {
      Botan::LibraryInitializer init;

      // ...
      }
   catch(std::exception& e)
      {
      //std::cerr << e.what() << "\n";
      }
    return 0;
}
#包括“stdafx.h”
#包括
int _tmain(int argc,_TCHAR*argv[]
{
尝试
{
植物学:图书馆初始化器初始化;
// ...
}
捕获(标准::异常&e)
{
//标准::cerr我会改变:

LibraryInitializer init;
致:

试试看
{
图书馆初始化器初始化;
}
捕获(标准::异常&e)
{

我会把这个放在下面,看看加载了什么(或者应该加载什么)在
0x003B0000
。如果它在您的DLL中,那么您应该能够获得一个符号。我认为您的另一个选择是在Visual Studio下启用本机代码调试。为此,请参阅和。一个是-该页面提到
LibraryInitializer
生存期必须超过所有其他Botan对象的生存期。这意味着您应该创建一个为您的BotancCrypto类初始化构造函数,并将
LibraryInitializer init
放在其中。您的代码只是通过将其塞入init函数来创建和销毁。
try
{
   LibraryInitializer init;
}
catch(std::exception& e)
{
    std::cerr << e.what() << "\n";
}