0

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>
Gregor Biswanger
  • 529
  • 3
  • 16
  • Can you share your csproj? – Luke Sep 30 '22 at 14:59
  • I added it to the description – Gregor Biswanger Sep 30 '22 at 15:21
  • Possible duplicate? Have you tried the solutions here? https://stackoverflow.com/questions/55463790/sap-data-sqlanywhere-saexception-cannot-find-the-language-resource-file-dblgen – Luke Sep 30 '22 at 20:10
  • The generated EXE file in the release now works without any problems. I only get the exception with "dotnet server.dll". The only problem is that Azure Web Apps run the server.dll and not the EXE file. What could be the reason? – Gregor Biswanger Oct 04 '22 at 15:34
  • I don't use Azure Web Apps so unfortunately I can't help you there. I recommend asking in a new question – Luke Oct 04 '22 at 15:37

1 Answers1

0

I found the solution. It needs an environment variable with:

SQLANY17=<Path-to-DLLs>
Gregor Biswanger
  • 529
  • 3
  • 16
  • Hi @Gregor - did you use the relative path? So `SQLANY17=Artifacts\Libraries`? Or did you need the root path? – RemarkLima Nov 15 '22 at 21:29