Elusive processor architecture mismatch during publish of a web application - .net-assembly

Our team is developing a web application targeted to x64. All its project references and their dependencies are targeting x64 (I verified the .csproj files and the assemblies). There are no latebound references in configuration files.
Everything compiles and runs fine under IIS 8.x Express. Only when publishing do we see
invalid assembly platform or ContentType in file
in the Fusion log. This occurs during a run of aspnet_compiler.exe as part of the publish. It seems that indeed, there is some kind of processor architecture mismatch, but where?
I also checked the target framework and target profile. The web project's framework is .NET 4.5. All its dependencies are 4.5 or lower, and the profile is the non-client one.

Related

How are dotnet core assemblies resolved in an asp.net core app hosted in IIS

We have an asp.net core application running on kestrel hosted in IIS on windows server 2008.
This application uses several base components and we are used to just install these components in the GAC and use assembly redirects to point all applications on the same server to the latest version of these components.
Everything runs fine when we deploy the application including all the necessary assemblies.
However, when we apply a redirect on a dotnet core assembly (we apply the redirect in the [app].exe.config, not the web.config) to a version that is installed in the GAC, we get a type exception ...
Application startup exception: System.TypeLoadException: Could not
load type 'my.company.namespace.coolest.component.helpers'
Curiously enough, the redirects for the plain old dotnet4 assemblies work when specified in the [app].exe.config, only the redirect for the dotnet core assembly fails.
So, I'm now wondering. How are dotnet core assemblies resolved? Which locations are searched for ?
(And ultimately, is it possible at all to redirect to a dotnet core assembly in the GAC)
[EDIT 23/OCT/2017:
Doh... turns out the latest dotnet core assembly from our team was bad..
so to answer my own question.. yes, assembly redirects (when specified in [app].exe.config) for dotnet core assemblies targeting full .net framework do work and ARE also searched from the GAC]
ASP.NET Core emphasizes a lot of Self-Contained Deployments, so if any assemblies (including ASP.NET Core runtime itself) of your web apps need to be updated, you should rebuild a deployment package and redeploy.
Framework-Dependent Deployments is just introduced to eliminate some disadvantages of SCD, but it still requires your own assemblies to be repackaged and redeployed if you make certain updates.
So forget about the GAC tricks and assembly redirection your team previously used (many other teams also use similar tricks), and follow Microsoft's new approaches. Maybe one day Microsoft would bring GAC to .NET Core, but that should look completely different from what it is today.
Reference: https://learn.microsoft.com/en-us/dotnet/core/deploying/
As Martin Ulrich indicated, it depends on the targetFramework..
For a .net core application targeting the full dotnet framework, assemblies are loaded just as we are used to.
(all assemblies, including the dotnet core ones)
In my case the assembly manager was loaded from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
For binding redirects, it checks application configuration file / host configuration files / machine configuration file
For retrieving assemblies, it looks in the GAC, then the current directory
Noteworthy, for a .net core application targeting the dotnet core 2.0, a "Runtime Package Store" was recently introduced.
Here the assemblies in the application directory are searched first, then the Runtime Package Store
(See also SO 35538093, Microsoft documentation and Runtime Package Store discussion on github)

VS Code + Develop(Linux) + Target(.net Framework) + Host(Windows)

I am developing a Web Application with ASPNET Core 2.0 on Visual Studio Code on Linux. But the host I'm trying to deploy the application is a Windows Server and the only target available option is .Net Framework 4.6.
So, when I try to run dotnet publish -o /folder -f net461 it shows me
this error.
Is it possible to develop an aspnet core application on linux and deploy it on windows using .Net Framework?
The following is the text of the error:
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/home/maransatto/Projects/FATEC/EraDoConhecimento/web/BDAg.csproj]
There are 2 scenarios: ASP.Net Core with .Net framework and ASP.Net Core with .Net Core. You can't develop asp.net core with .net framework on linux, so probably your application's target is "netcoreapp2.0" (suposed you downloaded the latest version). It's ok you deploy your app on windows server just using .net core runtime 2.0.
your command should be
dotnet publish -c Release -f netcoreapp2.0
You can deploy Framework-dependent or self-contained version. See (https://learn.microsoft.com/en-us/dotnet/core/deploying/index).
You also need Asp.Net Core Module on windows with IIS Integration.
https://learn.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x
When publishing self-contained you don't need .net core to be installed on the server.

ASPNETCoreModule not installed with .NET Core SDK

I installed VS 2017 along with .NET Core SDK on Windows 10. But it did not install ASPNETCoreModule as shown in figure 2 below. I thought .NET Core SDK should have installed it implicitly - and one does not have to install it separately. NOTE: I'm trying to publish my asp.net core app to IIS and the publish process requires ASPNETCoreModule as explained in the above link and also in this official MSDN article.
ASPNETCoreModule is missing:
ASP.NET Core Module is installed separately from the SDK. You can download the current version 2.0.0 here. https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md#windows-server-hosting
See https://github.com/dotnet/core/blob/master/release-notes/download-archive.md for a list of other releases.
ASP.NET Core Module is installed separately from the SDK
It's not true since the release of 2.1. I'm experiencing the same issue on Windows Server 2016. The module was installed on developer PC after uninstalling old versions / installing 2.1 a few times, but still struggling with the same issue in 2016. %SystemRoot%\system32\inetsrv\aspnetcore.dll is still missing.
In order to run .net core apps on IIS you need to have installed the ASP.NET Core Module ( the way it works is explained here ) that comes:
1 - with the SDK 2.1,
2 - With the Hosting Bundle Installer that bundles the .Net Core and the ASP.NET Core Runtime into a single bundler.
you can have both from the download page
If you are a developer computer you already have the Module with the SDK, I think is better to have on Sever computer only the hosting bundle
First, you need to check your IIS configurations, in case Shared configuration is configured in your IIS then normal installation of dotnet hosting bundle package wont work,
to make it work you need to install bundle package by command line with the argument as below:
dotnet-hosting-{VERSION}.exe OPT_NO_SHARED_CONFIG_CHECK=1
you can refer ASP.NET Core Module with an IIS Shared Configuration
This solution work for me because we are using the shared configuration in IIS

ASP.NET Core BadImageFormatException for libuv.dll

We recently migrated an ASP.NET Core project from the old project.json format to the new .csproj one.
Everything runs fine on our development machines. But once the application is deployed on the server, IIS fails to launch the application with a 502.5 (Process Failure) exception. The Windows event log mentions a BadImageFormatException for libuv.dll.
Has anyone encountered this? What could be the source of the problem?
Apparently, when an ASP.NET Core project is migrated to the csproj format, there are certain conditions under which the resulting csproj will not receive an explicit <PlatformTarget>.
And Visual Studio doesn't seem to behave identically when doing a usual build vs. publishing.
In both bases, it will build an PE32 executable with the 32BITREQ flag (32-bits only). But when publishing, it will deploy 64-bit libraries alongside, leading to the aforementioned BadImageFormatException, while it doesn't do that in a non-publish build.
Solution: In the project property page, reselect the platform in the dropdown list. Event if it doesn't have any visual effect, an explicit <PlatformTarget> will be added to the csproj on save and this solved my problem.

Loading web role in Azure emulator results in a BadImageFormatException

I have an ASP.NET MVC project that loads fine when I start it directly. When I try to run it vai the Azure SDK's emulator, I get the following exception:
Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\62253e0e\13ba4ff3\App_global.asax.a-wnopwm.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
This usually indicates something like a reference to a 64bit assembly on a 32bit system, but I've never seen this error on a ASP.NET project dll. The project configuration is set to AnyCPU. What gives?
The problem was due to the assemblyPostProcessorType attribute added to the system.web/compilation element of the web.config file when I used VS 2012's performance analysis (profiling) tool. It doesn't appear to clean up after itself very well and the config was left in place, causing an apparently assembly platform mismatch. It also caused problems when publishing to Windows Azure because the post-build assembly wasn't available.
The solution was to add a transform to the web config transform to remove the attribute (assemblyPostProcessorType).

Resources