0

I get an exception:

System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'SQLitePCLRaw.core, Version=2.0.4.976, Culture=neutral, PublicKeyToken=1488e028ca7ab535' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at SQLite.SQLiteConnection..cctor()

I get this from BOTH the Microsoft.Data.Sqlite nuget package and the sqlite-net-pcl package (sqlite-net-pcl has a different contructor but same error).

I am able to use these same packages in desktop applications (Winforms and Console .NET Framework).

I searched all the .dll files in the \bin folder of the IIS application and could not find 2.0.4 anywhere so I don't know what manifest it is finding.

There IS a version 2.0.4 of SQLitePCLRaw.core in the global nuget cache along with the version 2.0.7. enter image description here

Here is my project file:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
  <PropertyGroup>
    <ProjectType>Local</ProjectType>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{2CF2EE45-849A-47F9-BD72-3ADA2C1BAFCE}</ProjectGuid>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccProvider>SAK</SccProvider>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ApplicationIcon>
    </ApplicationIcon>
    <AssemblyKeyContainerName>
    </AssemblyKeyContainerName>
    <AssemblyName>XamarinBOs</AssemblyName>
    <AssemblyOriginatorKeyFile>
    </AssemblyOriginatorKeyFile>
    <DefaultClientScript>JScript</DefaultClientScript>
    <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
    <DefaultTargetSchema>IE50</DefaultTargetSchema>
    <DelaySign>false</DelaySign>
    <OutputType>Library</OutputType>
    <RootNamespace>XamarinBOs</RootNamespace>
    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
    <StartupObject>
    </StartupObject>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <UpgradeBackupLocation>
    </UpgradeBackupLocation>
    <SccAuxPath>SAK</SccAuxPath>
    <SignAssembly>false</SignAssembly>
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
    <OldToolsVersion>2.0</OldToolsVersion>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <TargetFrameworkProfile />
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <OutputPath>bin\Debug\</OutputPath>
    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
    <BaseAddress>285212672</BaseAddress>
    <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
    <ConfigurationOverrideFile>
    </ConfigurationOverrideFile>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DocumentationFile>
    </DocumentationFile>
    <DebugSymbols>true</DebugSymbols>
    <FileAlignment>4096</FileAlignment>
    <NoStdLib>false</NoStdLib>
    <NoWarn>
    </NoWarn>
    <Optimize>false</Optimize>
    <RegisterForComInterop>false</RegisterForComInterop>
    <RemoveIntegerChecks>false</RemoveIntegerChecks>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningLevel>4</WarningLevel>
    <DebugType>full</DebugType>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <OutputPath>bin\Release\</OutputPath>
    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
    <BaseAddress>285212672</BaseAddress>
    <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
    <ConfigurationOverrideFile>
    </ConfigurationOverrideFile>
    <DefineConstants>TRACE</DefineConstants>
    <DocumentationFile>
    </DocumentationFile>
    <DebugSymbols>true</DebugSymbols>
    <FileAlignment>4096</FileAlignment>
    <NoStdLib>false</NoStdLib>
    <NoWarn>
    </NoWarn>
    <Optimize>true</Optimize>
    <RegisterForComInterop>false</RegisterForComInterop>
    <RemoveIntegerChecks>false</RemoveIntegerChecks>
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <WarningLevel>4</WarningLevel>
    <DebugType>full</DebugType>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <BaseAddress>285212672</BaseAddress>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <FileAlignment>4096</FileAlignment>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <BaseAddress>285212672</BaseAddress>
    <Optimize>true</Optimize>
    <FileAlignment>4096</FileAlignment>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.Data.Sqlite, Version=6.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.Data.Sqlite.Core.6.0.2\lib\netstandard2.0\Microsoft.Data.Sqlite.dll</HintPath>
    </Reference>
    <Reference Include="SQLitePCLRaw.batteries_v2, Version=2.0.7.1395, Culture=neutral, PublicKeyToken=8226ea5df37bcae9, processorArchitecture=MSIL">
      <HintPath>..\packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.7\lib\net461\SQLitePCLRaw.batteries_v2.dll</HintPath>
    </Reference>
    <Reference Include="SQLitePCLRaw.core, Version=2.0.7.1395, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
      <HintPath>..\packages\SQLitePCLRaw.core.2.0.7\lib\netstandard2.0\SQLitePCLRaw.core.dll</HintPath>
    </Reference>
    <Reference Include="SQLitePCLRaw.nativelibrary, Version=2.0.7.1395, Culture=neutral, PublicKeyToken=502ed628492ab262, processorArchitecture=MSIL">
      <HintPath>..\packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.7\lib\net461\SQLitePCLRaw.nativelibrary.dll</HintPath>
    </Reference>
    <Reference Include="SQLitePCLRaw.provider.dynamic_cdecl, Version=2.0.7.1395, Culture=neutral, PublicKeyToken=b68184102cba0b3b, processorArchitecture=MSIL">
      <HintPath>..\packages\SQLitePCLRaw.provider.dynamic_cdecl.2.0.7\lib\netstandard2.0\SQLitePCLRaw.provider.dynamic_cdecl.dll</HintPath>
    </Reference>
    <Reference Include="SQLitePCLRaw.provider.e_sqlite3, Version=2.0.7.1395, Culture=neutral, PublicKeyToken=9c301db686d0bd12, processorArchitecture=MSIL">
      <HintPath>..\packages\SQLitePCLRaw.provider.e_sqlite3.2.0.7\lib\netstandard2.0\SQLitePCLRaw.provider.e_sqlite3.dll</HintPath>
    </Reference>
    <Reference Include="System">
      <Name>System</Name>
    </Reference>
    <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
    </Reference>
    <Reference Include="System.configuration" />
    <Reference Include="System.Data">
      <Name>System.Data</Name>
    </Reference>
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="System.DirectoryServices" />
    <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
    </Reference>
    <Reference Include="System.Numerics" />
    <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
    </Reference>
    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
    </Reference>
    <Reference Include="System.Xml">
      <Name>System.XML</Name>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="AssemblyInfo.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\FeedBack.cs" />
    <Compile Include="BOs\FileProcessor.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\XamarinHelper.cs" />
    <Compile Include="BOs\XamarinInvAdjHelper.cs" />
    <Compile Include="BOs\XamarinInventoryHelper.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\XamarinLoginHelper.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\XamarinTransferHelper.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\Logger.cs" />
    <Compile Include="BOs\PDBFileConverter.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\PDBfileUploader.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="BOs\PDBFileZipper.cs" />
    <Compile Include="BOs\Utility.cs" />
    <Compile Include="DOs\XamarinAccess.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="DOs\XamarinInvAdjAccess.cs" />
    <Compile Include="DOs\XamarinInvAdjQuery.cs" />
    <Compile Include="DOs\XamarinInventoryAccess.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="DOs\XamarinInventoryQuery.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="DOs\XamarinLoginAccess.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="DOs\XamarinLoginQuery.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="DOs\XamarinTransferAccess.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="DOs\XamarinTransferQuery.cs">
      <SubType>Code</SubType>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
      <Visible>False</Visible>
      <ProductName>Windows Installer 3.1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\DCSDTOs\DCSDTOs.csproj">
      <Project>{3992f70f-4c99-47af-a4e4-c17574bda7e7}</Project>
      <Name>DCSDTOs</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\Factor.StoreTrak.DealerTrak\WindowsEventLogWriter\Factor.WindowsEventLogWriter.csproj">
      <Project>{c3bf9001-6a7b-407f-a689-2b347706976c}</Project>
      <Name>Factor.WindowsEventLogWriter</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\GeneralDTOs\GeneralDTOs.csproj">
      <Project>{749f9e29-03ad-4ed8-894c-2237eaa594d0}</Project>
      <Name>GeneralDTOs</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\Utils\Utils.csproj">
      <Project>{10aa46ad-6c8a-4042-901d-ed87262b54b7}</Project>
      <Name>Utils</Name>
    </ProjectReference>
    <ProjectReference Include="..\XamarinDTO\XamarinDTO.csproj">
      <Project>{C069F763-4C38-407D-89F3-B3601D91E451}</Project>
      <Name>XamarinDTO</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config" />
    <None Include="packages.config" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <PropertyGroup>
    <PreBuildEvent>
    </PreBuildEvent>
    <PostBuildEvent>
    </PostBuildEvent>
  </PropertyGroup>
  <Import Project="..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.7\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.7\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.7\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.7\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets'))" />
  </Target>
</Project>

Here is my packages.config file:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Data.Sqlite" version="6.0.2" targetFramework="net462" />
  <package id="Microsoft.Data.Sqlite.Core" version="6.0.2" targetFramework="net462" />
  <package id="SQLitePCLRaw.bundle_e_sqlite3" version="2.0.7" targetFramework="net462" />
  <package id="SQLitePCLRaw.core" version="2.0.7" targetFramework="net462" />
  <package id="SQLitePCLRaw.lib.e_sqlite3" version="2.0.7" targetFramework="net462" />
  <package id="SQLitePCLRaw.provider.dynamic_cdecl" version="2.0.7" targetFramework="net462" />
  <package id="SQLitePCLRaw.provider.e_sqlite3" version="2.0.7" targetFramework="net462" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net462" />
  <package id="System.Memory" version="4.5.4" targetFramework="net462" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net462" />
</packages>

Here is my Application Pool for IIS:

enter image description here enter image description here

I tried this: Could not load file or assembly SQLitePCLRaw.core

And I could not follow most of this: https://github.com/ericsink/SQLitePCL.raw/issues/343[5]

I also deleted all the ASP.NET Temporary files. Thanks for any help.

Belmiris
  • 2,741
  • 3
  • 25
  • 29
  • It's funny how I still sometimes go into new projects all confident well established stuff will work reasonably. I created a new ASP.NET (.NET framework) web application (this was an older project type) and installed the sqlite-net-pcl nuget package and tried to create a database in the App_Data folder and got Exception: Library e_sqlite3 not found. This lead me to https://stackoverflow.com/questions/65750542/microsoft-data-sqlite-library-e-sqlite3-not-found and it's a known issue. I guess SQLite is kind of a poop show, – Belmiris Feb 17 '22 at 23:04
  • You need to include the missed file (SQLitePCLRaw.core) to the folder with the add-in files. – samwu Feb 18 '22 at 09:52
  • The SQLitePCLRaw.core was in the bin folder. It's version was 2.0.7. I uninstalled all the packages and re-installed the sqlite-net-pcl (which had the dll with the desired version 2.0.4 - just don't update anything) and it still threw the error. – Belmiris Feb 18 '22 at 17:34

1 Answers1

1

Well, this turned into a real nightmare. It's been a while since I've been stumped this hard.

I remembered that the reason I chose SQLite was that i had used it in a previous web application. I went and looked at that project and saw that I had chosen the package "System.Data.SQLite.Core" there.

I removed all the packages from my current project and installed the System.Data.SQLite.Core package.

I immediately ran into a problem with the file SQLite.Interop.dll not being found. I read through this massive ticket: Unable to load DLL Sqlite.interop.dll but none of the MANY answers there worked for me. I resolved the issue by including the x86 and x64 folder from my project's bin folder in the IIS bin folder for the application.

I had originally chosen the sqlite-net-pcl package because I am hoping to create a database on the server and have an android app written in Xamarin download and use it. Some courses I took recommended this package for Xamarin apps and it seems to work fine there. I can only hope the database created with this other package can be read on both devices, my faith in these tools working correctly is pretty low at this point.

So far everything seems to be working. I have not checked to see if my Xamarin program can read the database. Hopefully the fates will throw me a bone.

Belmiris
  • 2,741
  • 3
  • 25
  • 29