I managed to fix my issue by switching to a new base image.
This is my first Dockerfile, which resulted in the " Unable to start container. Error message: Index was outside the bounds of the array." error:
# escape=`
FROM mcr.microsoft.com/dotnet/aspnet:5.0-windowsservercore-ltsc2019 AS base
# Set environment vars for the next step.
ENV `
# Unset ASPNETCORE_URLS from aspnet base image
ASPNETCORE_URLS= `
DOTNET_SDK_VERSION=5.0.301 `
# Enable correct mode for dotnet watch (only mode supported in a container)
DOTNET_USE_POLLING_FILE_WATCHER=true `
# Skip extraction of XML docs - generally not useful within an image/container - helps performance
NUGET_XMLDOC_MODE=skip
# Download and install the dotnet core SDK for x86. This also includes the runtime.
RUN powershell -Command "`
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
`
Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.azureedge.net/dotnet/Sdk/$Env:DOTNET_SDK_VERSION/dotnet-sdk-$Env:DOTNET_SDK_VERSION-win-x86.zip; `
$dotnet_sha512 = '8fd4b4e00d5506e12a3b214ce9f4142fef42f304d01c359f5551baba7e327768daaf236edf899be83f5cd87d36c9234b8329e97355fc5ea41cb5c903740ea5ed'; `
if ((Get-FileHash dotnet.zip -Algorithm sha512).Hash -ne $dotnet_sha512) { `
Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
`
$install_path = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath dotnet; `
New-Item -Force -Path $install_path -ItemType directory | Out-Null; `
Write-Host "Installing dotnet x86 to $install_path"; `
tar -C $install_path -oxzf dotnet.zip; `
Remove-Item -Force dotnet.zip;"
EXPOSE 80
# Copy 32-bit ODBC driver files over
COPY ["./OdbcDrivers/*", "c:/Program Files (x86)/OdbcDrivers/"]
# Copy the ODBC driver registry file and run it to register the drivers with ODBC.
COPY ["./OdbcDrivers/RegKeys.reg", "c:/Program Files (x86)/OdbcDrivers/"]
RUN ["reg", "import", "c:/Program Files (x86)/OdbcDrivers/OdbcDrivers.reg"]
ADD ./OurWebApi /App
WORKDIR /App
ENTRYPOINT ["c:/Program Files (x86)/dotnet/dotnet", "OurWebApi.dll"]
For what it's worth: I even changed the ENTRYPOINT above to just "cmd.exe" and I still got the "Index was outside the bounds of the array." error. So, our WebApi application didn't appear to be a factor.
My 2nd Dockerfile, which worked:
# escape=`
ARG REPO=mcr.microsoft.com/dotnet/runtime
FROM $REPO:5.0-windowsservercore-ltsc2019 AS base
# Set environment vars for the next step.
ENV ASPNET_VERSION=5.0.8
# Download and install the .NET Core Runtime for x86.
RUN powershell -Command `
$ErrorActionPreference = 'Stop'; `
$ProgressPreference = 'SilentlyContinue'; `
`
Invoke-WebRequest -OutFile aspnetcore.zip https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/aspnetcore-runtime-$Env:ASPNET_VERSION-win-x86.zip; `
$aspnetcore_sha512 = '990de1faf7f1c916a62fe15b87e2a7170238407882b2fb12d277a48a75120929296bf35c2deaf5690206f8295382767e220e92576ea73fab57f019023a132950'; `
`
if ((Get-FileHash aspnetcore.zip -Algorithm sha512).Hash -ne $aspnetcore_sha512) { `
Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
`
# Commented out because the Azure App Service doesn't like paths with spaces for some reason
#$install_path = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath dotnet; `
$install_path = 'C:\dotnet_x86'; `
$null = New-Item -Force -Path $install_path -ItemType directory; `
tar -C $install_path -oxzf aspnetcore.zip; `
Remove-Item -Force aspnetcore.zip;"
EXPOSE 80
# Copy 32-bit ODBC driver files over
COPY ["./OdbcDrivers/*", "c:/Program Files (x86)/OdbcDrivers/"]
# Copy the ODBC driver registry file and run it to register the drivers with ODBC.
COPY ["./OdbcDrivers/RegKeys.reg", "c:/Program Files (x86)/OdbcDrivers/"]
RUN ["reg", "import", "c:/Program Files (x86)/OdbcDrivers/OdbcDrivers.reg"]
ADD ./OurWebApi /App
WORKDIR /App
# Commented out because the Azure App Service doesn't like paths with spaces for some reason
# See $install_path above as well
#ENTRYPOINT ["c:/Program Files (x86)/dotnet/dotnet", "OurWebApi.dll"]
ENTRYPOINT ["c:/dotnet_x86/dotnet", "OurWebApi.dll"]
For context: We have a 32-bit WebAPI written using aspnetcore 5.0. It has to be 32-bit because the ODBC driver we're relying on is 32-bit as well. This is why we download the x86 SDK / runtime in the Dockerfile.