Search code examples
.net-corewindows-servicesautofacwindows-server-2008-r2topshelf

Unable to run dotnet core 2 console app in Windows Server 2008 R2


I'm developing a windows service application using TopShelf and under dotnet core 2 framework. To create it I used Console App (.NET core) template. Now, to deploy the App I created a publish profile to do it locally. This is the content:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <PropertyGroup>
  <PublishProtocol>FileSystem</PublishProtocol>
  <Configuration>Release</Configuration>
  <TargetFramework>netcoreapp2.0</TargetFramework>
  <PublishDir>C:\Repos\Deployments\MassTransit.Consumer</PublishDir>
  <Platform>Any CPU</Platform>
  <SelfContained>true</SelfContained>
  <_IsPortable>true</_IsPortable>
  <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

As you can see the RuntineIdentifier is win7-x64, which according with the documentation this should be the correct one to run the application in Windows server 2008 R2. When I deploy the application to the local folder I can run it without issues in my machine executing the generated .exe, but when I try to run it in Windows server 2008 R2, copying all the files of the local folder in the windows server, I'm getting badimageformatexception bad il format error:

Console Error

In windows server is installed Dotnetcore.2.0.5-WindowsHosting and Dotnet-sdk-2.1.105-win64

Just a FYI,I have a web api core 2 application running under IIS in this server and if I run dotnet --version in cmd.exe it returns 2.1.0.105, so it recognize that dotnet core is installed

Any clue why the console app is getting me that error at the time to run it in Windows Server 2008 R2. Do I need to install anything else? Or, do I need to change something in my publish profile?

Update

I'm pretty sure the exception is happening in the yellow line by the Load.From:

Code

I'm using that code to load custom libraries that have Autofac modules I need to register when the app start.


Solution

  • It wasn't a server's problem. It was because the pattern I'm trying to match was contained in the filename, which is a path, so it was loading wrong assemblies like hostfrx.dll and hostpolicy.dll:

    Assemblies

    It was running locally because this assemblies show up once I deploy the project.