Reputation: 458
I created a solution in VS 2017 with 2 main projects (& common ones). The architecture illustrates a very large legacy project, therefore cannot be changed. The main project is a .Net executable which it's main class inherits from 'ServiceBase' class in order to be used as a Windows service. It defines WCF endpoint and uses an interface 'IWcfXmlServer' to process a request. The other project is a C++ project with a class that implements 'IWcfXmlServer' interface and used to process a request.
I have created a Windows service locally and pointed it to the .exe file of the solution and it worked fine.
The next step is to put that app on a Docker container. I added Docker support, which added "docker-compose" .yml file:
version: '3.4'
services:
wcfservice:
image: ${DOCKER_REGISTRY}wcfservice
build:
context: .\..\WcfService
dockerfile: Dockerfile
and a Dockerfile:
FROM microsoft/dotnet-framework:4.7.1-windowsservercore-1709
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["C:\\app\\WcfService.exe"]
When I build the solution and start debugging I get:
Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.
but still, the container is created.
I opened PowerShell in the created Docker container and used "New-Service" to create a new service and point it to my .exe file. When I try to run Start-Service I get an error.
I used the Windows event log to get the error description:
EntryType : Error Message : Service cannot be started. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'testole.dll' or one of its dependencies. The specified module could not be found. at WcfService.WcfXmlServerFacade..ctor() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.ServiceModel.Description.ServiceDescription.CreateImplementation(Type serviceType) at System.ServiceModel.Description.ServiceDescription.SetupSingleton(ServiceDescription serviceDescription, Object implementation, Boolean isWellKnown) at System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implem... Source : WcfService1
I can't figure out neither why it fails to run the C++ dll, nor how to get more information about the error (Console.Writeine() \ Debug.Writeine()) didn't work for some reason.
Thanks in advance.
Upvotes: 2
Views: 1341
Reputation: 4289
Most probably you're missing Visual C++ Redistributable package. I suspect it's not installed by default on windows docker images.
Try adding following lines (for downloading VC++ 2015 Update 3 x64) to your Dockerfile just below FROM
line:
ADD https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe /vc_redist.x64.exe
RUN C:\vc_redist.x64.exe /quiet /install
Source (https://github.com/Microsoft/dotnet-framework-docker/issues/15)
Upvotes: 2