Fix SQLite BadImageFormat by disabling Prefer32Bit and syncing interop arch.
Ensure SQLite.Interop.dll next to the exe always matches process bitness from x86/x64. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
fd5bd18c66
commit
3d253a2f54
@ -129,7 +129,7 @@ namespace Электронная_Фармация.Classes
|
|||||||
private static void EnsureSQLiteInteropInBaseDir()
|
private static void EnsureSQLiteInteropInBaseDir()
|
||||||
{
|
{
|
||||||
// System.Data.SQLite ожидает SQLite.Interop.dll рядом с exe.
|
// System.Data.SQLite ожидает SQLite.Interop.dll рядом с exe.
|
||||||
// В релизной поставке DLL часто лежит в подпапках x86/x64.
|
// Важно: разрядность DLL должна совпадать с процессом (Prefer32Bit => x86).
|
||||||
if (_sqliteInteropPrepared)
|
if (_sqliteInteropPrepared)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -144,13 +144,6 @@ namespace Электронная_Фармация.Classes
|
|||||||
|
|
||||||
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
var targetDll = Path.Combine(baseDir, "SQLite.Interop.dll");
|
var targetDll = Path.Combine(baseDir, "SQLite.Interop.dll");
|
||||||
if (File.Exists(targetDll))
|
|
||||||
{
|
|
||||||
_sqliteInteropPrepared = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// AnyCPU в .NET Framework обычно выбирает разрядность процесса автоматически.
|
|
||||||
var archFolder = Environment.Is64BitProcess ? "x64" : "x86";
|
var archFolder = Environment.Is64BitProcess ? "x64" : "x86";
|
||||||
var sourceDll = Path.Combine(baseDir, archFolder, "SQLite.Interop.dll");
|
var sourceDll = Path.Combine(baseDir, archFolder, "SQLite.Interop.dll");
|
||||||
var sourcePdb = Path.Combine(baseDir, archFolder, "SQLite.Interop.pdb");
|
var sourcePdb = Path.Combine(baseDir, archFolder, "SQLite.Interop.pdb");
|
||||||
@ -159,7 +152,7 @@ namespace Электронная_Фармация.Classes
|
|||||||
{
|
{
|
||||||
if (File.Exists(sourceDll))
|
if (File.Exists(sourceDll))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(baseDir);
|
// Всегда подкладываем DLL нужной разрядности (даже если в корне уже лежит "чужая").
|
||||||
File.Copy(sourceDll, targetDll, overwrite: true);
|
File.Copy(sourceDll, targetDll, overwrite: true);
|
||||||
|
|
||||||
var targetPdb = Path.Combine(baseDir, "SQLite.Interop.pdb");
|
var targetPdb = Path.Combine(baseDir, "SQLite.Interop.pdb");
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
@ -30,6 +31,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user