IT박스

파일 또는 어셈블리 'System.Data.SQLite'를로드 할 수 없습니다

itboxs 2020. 7. 12. 10:21
반응형

파일 또는 어셈블리 'System.Data.SQLite'를로드 할 수 없습니다


ASP.NET 프로젝트에 ELMAH 1.1 .Net 3.5 x64를 설치했는데이 오류가 발생합니다 (페이지를 보려고 할 때마다).

파일 또는 어셈블리 'System.Data.SQLite, 버전 = 1.0.61.0, Culture = neutral, PublicKeyToken = db937bc2d44ff139'또는 해당 종속성 중 하나를로드 할 수 없습니다. 형식이 잘못된 프로그램을로드하려고했습니다.

설명 : 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 오류 및 코드에서 발생한 위치에 대한 자세한 정보는 스택 추적을 검토하십시오.

예외 정보 : System.BadImageFormatException : 파일 또는 어셈블리 'System.Data.SQLite, 버전 = 1.0.61.0, Culture = neutral, PublicKeyToken = db937bc2d44ff139'또는 해당 종속성 중 하나를로드 할 수 없습니다. 형식이 잘못된 프로그램을로드하려고했습니다.

하단에 더 많은 오류 정보가 있습니다.

내 Active Solution 플랫폼은 "Any CPU"이며 x64의 x64 Windows 7, 물론 프로세서에서 실행 중입니다. 이 버전의 ELMAH를 사용하는 이유는 1.0 .Net 3.5 (x86, 컴파일 된 유일한 플랫폼)가 x64 Windows 서버에서 이와 동일한 오류를 발생했기 때문입니다.

x86 및 x64에 대해 컴파일을 시도했지만 동일한 오류가 발생합니다. 모든 컴파일러 출력 (bin 및 obj)을 제거하려고했습니다. 마지막으로 서버에서 프로젝트를 수행하는 데 필요하지 않은 SQLite dll을 직접 참조 했으며이 컴파일러 오류가 발생했습니다.

오류 1 오류로 경고 : 어셈블리 생성-참조 된 어셈블리 'System.Data.SQLite.dll'이 다른 프로세서 MyProject를 대상으로 함

문제가 무엇인지 아이디어가 있습니까?

더 자세한 오류 정보 :

소스 오류 :

현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 생성되었습니다. 예외의 출처와 위치에 관한 정보는 아래 예외 스택 추적을 사용하여 식별 할 수 있습니다.

스택 추적 :

[BadImageFormatException : 파일 또는 어셈블리 'System.Data.SQLite, 버전 = 1.0.61.0, Culture = neutral, PublicKeyToken = db937bc2d44ff139'또는 해당 종속성 중 하나를로드 할 수 없습니다. 형식이 잘못된 프로그램을로드하려고했습니다.]
System.Reflection.Assembly._nLoad (AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark & ​​stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly .nLoad (AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark & ​​stackMark, Boolean throwOnFileNotFound, Boolean forInspectspection) +43
System.Reflection.Assembly.InternalLoad (AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark & ​​stackMark, Boolean forIntrospection) +127 System.Reflection.Assembly.InternalLoad (String assemblyString, 증거 어셈블리 보안, StackCrawlMark & ​​stackMark, Introspection에 대한 부울) +142 System.Reflection.Assembly. Load (String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper (문자열 assemblyName, 부울 starDirective) +46

[ConfigurationErrorsException : 파일 또는 어셈블리 'System.Data.SQLite, 버전 = 1.0.61.0, Culture = neutral, PublicKeyToken = db937bc2d44ff139'또는 해당 종속성 중 하나를로드 할 수 없습니다. 형식이 잘못된 프로그램을로드하려고했습니다.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper (String assemblyName, Boolean starDirective) +613 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory () +203 System.Web.Configuration .CompilationSection.LoadAssembly (AssemblyInfo ai) +105
System.Web.Compilation.BuildManager.GetReferencedAssemblies (CompilationSection compConfig) +178
System.Web.Compilation.BuildProvidersCompiler..ctor (VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult (Boolean isPrecompiledApp) +232
System.Web.Compilation.BuildManager.CompileGlobalAsax () +52 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled () +337

[HttpException (0x80004005) : 파일 또는 어셈블리 'System.Data.SQLite, Version = 1.0.61.0, Culture = neutral, PublicKeyToken = db937bc2d44ff139'또는 해당 종속성 중 하나를로드 할 수 없습니다. 형식이 잘못된 프로그램을로드하려고했습니다.]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException () +58 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled () +512 System.Web.Hosting.HostingEnvironment.Initialize ( ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters 호스팅 매개 변수) +729

[HttpException (0x80004005) : 파일 또는 어셈블리 'System.Data.SQLite, Version = 1.0.61.0, Culture = neutral, PublicKeyToken = db937bc2d44ff139'또는 해당 종속성 중 하나를로드 할 수 없습니다. 형식이 잘못된 프로그램을로드하려고했습니다.]
System.Web.HttpRuntime.FirstRequestInit (HttpContext context) +8896783
System.Web.HttpRuntime.EnsureFirstRequestInit (HttpContext context) +85
System.Web.HttpRuntime.ProcessRequestInternal (HttpWorkerRequest wr ) +259


System.Data.SQLite.dll혼합 어셈블리입니다. 즉 관리 코드와 기본 코드가 모두 포함됩니다. 따라서 특정 System.Data.SQLite.dll은 x86 또는 x64이지만 둘다는 아닙니다.

업데이트 ( 제공 : J. Pablo Fernandez ) : F5를 누르거나 녹색«재생»버튼을 클릭 할 때 Visual Studio에서 사용하는 개발 웹 서버 인 Cassini는 x86 전용이므로 워크 스테이션이 x64 인 경우에도 x86 버전의 System.Data.SQLite.dll을 사용할 수 있습니다.

대안은 Cassini를 사용하지 않고 IIS x7을 올바르게 x64로 사용하는 것입니다.


앱 풀에 대해 "32-비트 응용 프로그램 사용"이 false로 설정되어 있는지 확인하십시오.


로 이동하십시오 IIS7 Application Pool -> advanced settings and set the 32-bit application to true.


SQLite를 사용하지 않는 경우 매우 간단합니다.

솔루션의 bin 폴더에서 ELite를 참조하는 폴더에서 SQLite DLL을 삭제할 수 있습니다. 다시 빌드하면 앱에서 사용하지 않는이 DLL을로드하지 않습니다.


I have a 64 bit dev machine and 32 bit build server. I used this code prior to NHibernate initialisation. Works a charm on any architecture (well the 2 I have tested)

Hope this helps someone.

Guido

        private static void LoadSQLLiteAssembly()
        {
            Uri dir = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            FileInfo fi = new FileInfo(dir.AbsolutePath);           
            string binFile = fi.Directory.FullName + "\\System.Data.SQLite.DLL";
            if (!File.Exists(binFile)) File.Copy(GetAppropriateSQLLiteAssembly(), binFile, false);
        }

        private static string GetAppropriateSQLLiteAssembly()
        {
            string pa = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
            string arch = ((String.IsNullOrEmpty(pa) || String.Compare(pa, 0, "x86", 0, 3, true) == 0) ? "32" : "64");
            return GetLibsDir() + "\\NUnit\\System.Data.SQLite.x" + arch + ".DLL";
        }

As someone who's had to deal with quite a few bug reports on Roadkill Wiki with exactly the same issue, this is what you need to do:

  • Are you using x64 or x86? Sqlite comes with DLLs for separate architectures - copy the right one to your bin folder, there are two DLLS for the official provider: System.Data.SQLite.dll System.Data.SQLite.Linq.dll
  • If you can't be bothered hunting around for these assemblies, enable 32 bit mode for your App Pool (a solution for dev machines only usually)
  • If you're hosting on a server, you'll need the Microsoft C++ Runtime redistributable - it's not installed on Server 2008 R2 by default. x64 version, x86 version

It's a real pain in the ass how many hoops you have to jump through when re-distributing the SQLite .NET binaries, my solution for Roadkill in the end was to copy the correct binaries to the ~/bin folder based on the architecture your using. Unfortunately that doesn't solve the C++ runtime issue.


I resolved this by installing System.Data.SQLite with Nuget extension. This extension can use for Visual Studio 2010 or higher. First, you have to install Nuget extension. You can follow here:

  • Go to Visual Studio 2010, Menu --> Tools
  • Select Extension Manager
  • Enter NuGet in the search box and click Online Gallery. Waiting it Retrieve information…
  • Select the retrieved NuGet Package Manager, click Download. Waiting it Download…
  • Click Install on the Visual Studio Extension Installer NuGet Package Manager. Wait for the installation to complete.
  • Click Close and 'Restart Now.

Second, now, you can install SQLite:

And now, you can use System.Data.SQLite.

In the case, you see two folder x64 and, x86, these folders contain SQLite.Interop.dll. Now go to the properties windows of those dlls and set build action is content and Copy to output directory is Copy always.

So, that is my way.

Thanks. Kim Tho Pham, HoChiMinh City, Vietnam. Email: tho.phamkim@gmail.com


Manual load related System.Data.SQLite assembly can resolve this.

Changed gatapia's Code as below:

    public static void LoadSQLLiteAssembly()
    {
        Uri dir = new Uri(Assembly.GetExecutingAssembly().CodeBase);
        FileInfo fi = new FileInfo(dir.AbsolutePath);
        string appropriateFile = Path.Combine(fi.Directory.FullName, GetAppropriateSQLLiteAssembly());
        Assembly.LoadFrom(appropriateFile);
    }

    private static string GetAppropriateSQLLiteAssembly()
    {
        string pa = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
        string arch = ((String.IsNullOrEmpty(pa) || String.Compare(pa, 0, "x86", 0, 3, true) == 0) ? "32" : "64");
        return "System.Data.SQLite.x" + arch + ".DLL";
    }

I got this error when our windows server was converted from 32 bit OS to 64 bit. The assembly that was throwing the error was set to compile in x86 mode (ie 32 mode). I switched it to "Any CPU" and that did the trick. You can change this value by doing the following:

right click on the project go to Properties -> Build -> Platform Target -> change to "Any CPU"


In our case didn't work because our production server has missing

Microsoft Visual C++ 2010 SP1 Redistributable Package (x86)

We installed it and all work fine. The Application Pool must have Enable 32-bit Applications set to true and you must the x86 version of the library


I resolved this, oddly enough, by installing System.Data.SQLite via the Nuget GUI application, as opposed to the package manager console.

Installing via the console didn't include the dependencies this library needs to run.


I came up with 2 quick solutions. Either work for me. I think the problem is because of permissions.

1) Instead of using the Elmah.dll file from the net-2.0 directory, I used Elmah.dll from net-1.1 .

2) Instead of keeping Elmah.dll in the project bin directory. I make a dll directory to put it in.


Another way to get around this is just to upgrade your application to ELMAH 1.2 rather than 1.1.


System.Data.SQLite has a dependency on System.Data.SQLite.interop make sure both packages are the same version and are both x86.

This is an old question, but I tried all the above. I was working on a strictly x86 project, so there was not two folders /x86, /x64. But for some reason, the System.Data.SQLite was a different version to System.Data.SQLite.interop, once I pulled down matching dlls the problem was fixed.


Can you delete your bin debug folder and recompile again?

Or check your project reference to the System.Data.SQLite, track down where it is located, then open the dll in reflector. If you can't open it, that means that the dll is corrupted, you might want to find a correct one or reinstall the .net framework.


If you are using IIS Express as the web server on your development machine I would change to Local IIS. This worked for me.


This is an old post, but it may help some people searching on this error to try setting "Enable 32-Bit Applications" to True for the app pool. That is what resolved the error for me. I came upon this solution by reading some the comments to @beckelmw's answer.


You likely have the wrong package installed. You want the package produced by Microsoft which implements the System.Data.Common provider model.

참고URL : https://stackoverflow.com/questions/1278929/could-not-load-file-or-assembly-system-data-sqlite

반응형