I use SQL Anywhere and only have to include the necessary 64-bit DLL files of the same type in my project directory. These are always copied to the bin folder during the build. When I debugging and use dotnet run
it works fine.
However, if I start the built DLL file from my asp.net core 6 project with dotnet server.dll
- I get the following error message:
System.Exception: The type initializer for 'Sap.Data.SQLAnywhere.SAConnection' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Sap.Data.SQLAnywhere.SAConnection' threw an exception.
---> Sap.Data.SQLAnywhere.SAException (0x80004005): Cannot find the language resource file (dblgen17.dll).
at Sap.Data.SQLAnywhere.SAUnmanagedDll..ctor()
at Sap.Data.SQLAnywhere.SAUnmanagedDll.get_Instance()
at Sap.Data.SQLAnywhere.SAConnection..cctor()
--- End of inner exception stack trace ---
at Sap.Data.SQLAnywhere.SAConnection..ctor()
---> System.TypeInitializationException: The type initializer for 'Sap.Data.SQLAnywhere.SAConnection' threw an exception.
---> Sap.Data.SQLAnywhere.SAException (0x80004005): Cannot find the language resource file (dblgen17.dll).
at Sap.Data.SQLAnywhere.SAUnmanagedDll..ctor()
at Sap.Data.SQLAnywhere.SAUnmanagedDll.get_Instance()
at Sap.Data.SQLAnywhere.SAConnection..cctor()
--- End of inner exception stack trace ---
at Sap.Data.SQLAnywhere.SAConnection..ctor()
The dll files are in the root directory of the bin folder. Debugging or with dotnet run
command works fine.
The csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>x64</Platforms>
</PropertyGroup>
<ItemGroup>
<ContentWithTargetPath Include="Artifacts\Libraries\dbcon17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dbcon17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\dbicu17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dbicu17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\dbicudt17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dbicudt17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\dblgde17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dblgde17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\dblgen17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dblgen17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\dbodbc17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dbodbc17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\dbrsa17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>dbrsa17.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Artifacts\Libraries\sapcrypto.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>sapcrypto.dll</TargetPath>
</ContentWithTargetPath>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="**.Interfaces" Version="1.0.0" />
<PackageReference Include="**.Libraries.Common" Version="1.0.0" />
<PackageReference Include="**.Libraries.Database" Version="1.0.0" />
<PackageReference Include="**.Libraries.Logging" Version="1.0.0" />
<PackageReference Include="**.Libraries.MQTTHandling" Version="1.0.0" />
<PackageReference Include="**.Libraries.Translation" Version="1.0.0" />
<PackageReference Include="**.Utilities" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.22.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Sap.Data.SQLAnywhere.Core.v2.1">
<HintPath>Artifacts\Sap.Data.SQLAnywhere.Core.v2.1.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Resource Include="Artifacts\Libraries\dbcon17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\dbicu17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\dbicudt17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\dblgde17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\dblgen17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\dbodbc17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\dbrsa17.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Artifacts\Libraries\sapcrypto.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<None Update="bms.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>