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.
Related
I made a new .NET Class Library solution if TFS, and added a bunch of preexisting classes that were developed for a windows forms application. Basically just dumped the old folder in. The forms app worked fine and the folders in bin were expectedly barren, apart from the exe and the required nuget references. The dll build however copies over libraries all the way from Microsoft.Win32.Primitives.dll, to System.Xml.XPath.XDocument.dll for no apparent reason. I have removed unused references with ReSharper and commented out unnecessary using statements. No difference whatsoever. I don't think it's a problem from the deployment perspective, it's just annoying to have so many files copied over each build. Could it be that the initial presence of Forms just poisoned the new project forever? Any help whatsoever would be much appreciated.
Prevent Visual studio 2017 from copying almost 100 unnecessary system
dlls to output folder for dll project
Please check if your VS2017 is very old and also check if the framework version of your project targets to 4.6 or 4.7.1.
If so, there is an known issue about this issue.
This is a .net standard 2.0/net 4.6/4.7.1 issue which was improved in 4.7.2. You can check this similar issue.
Suggestion
1) you should first update your VS2017 in case some updates fix it.
2) change the framework version of your project to net framework 4.7.2.(if you do not have net frameowork 4.7.2, you should install it in the VS Installer)
I am attempting to move a solution from TFS 2012 to TFS 2018 SP2RC2 but I can't get the unit tests to run correctly. All projects have been re-targeted to 4.7.1 and are built as x86 platform. We have a testsettings file that supplies nothing but deployment items. I am using the new VSTest Platform Installer task (as directed by MS) and the VS Test Task. At the start of the test run I get the following message:
Test run will use DLL(s) built for framework .NETFramework,Version=v4.5 and platform X86. Following DLL(s) do not match framework/platform settings.
So all of the test are skipped as they target 4.7.1. Where is this 4.5 setting coming from? I cannot find it specified anywhere and can't figure out how to change it.
There is a /Framework: parameter that you can specify to VSTest.
In your case, you should specify /Framework:.NETFramework,Version=v4.7.1
See more at https://msdn.microsoft.com/en-us/library/jj155796.aspx?f=255&mspperror=-2147217396
To add this parameter in a Azure DepOps yaml pipeline, use the otherConsoleOptions argument
- task: VSTest#2
otherConsoleOptions: '/Framework:.NETFramework,Version=v4.7.1'
The fix I found for this in Visual Studio is way easier than I thought:
Exit all instances of VS
Open your project folder in Windows Explorer, find the .vs folder, delete it
Restart VS, the folder rebuilds itself, tests work again.
Apparently there are some settings that the NUnit plugin stashes in this folder and they are in binary so you can't edit them. This happened to me after I updated to NUnit3TestAdapter version 3.17.
I had trouble running a test project developed on another machine where no tests where able to be run using the MSTest test runner. In addition to message in your question I also got the messages:
Make sure that test discoverer & executors are registered and platform
& framework version settings are appropriate and try again.
Discover test finished: 0 found
In my case I resolved it by unloading and updating the .csproj file adding the following import directly under the root Project tag.
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
Hope this answer will help save you some time.
I got this error using Visual Studio 2019 with NUnit 3.12.0:
Test run will use DLL(s) built for framework
.NETFramework,Version=v4.5 and platform X86. Following DLL(s) do not
match framework/platform settings.
Project.UnitTests.dll is built for Framework 4.5.2
and Platform AnyCPU.
Installed NUnit3TestAdapter 3.13.0 and then everything started working. Did not need to modify Framework version or CPU settings.
Had the exact same issue as Bill, working on legacy code in VS2019, nothing else had worked. I simply changed the Run Settings to use the Auto Detect.
In the menu go to Test -> Configure Run Settings -> Auto Detect runsettings File
For me skipping tests in local VS2022 run was related to testsettings file. I deleted .vs folder of my project then selected
Test ->Configure Run Settings -> Select Autodetect run settings file
After that I can debug unit tests
TLDR: If you use *.runsettings file for your test projects, try removing TargetFrameworkVersion node
I had similar problem but with .Net Core
Test run will use DLL(s) built for framework
.NETFramework,Version=v4.0 and platform X64. Following DLL(s) do not
match framework/platform settings. MyProject.Tests.dll is
built for Framework .NETCoreApp,Version=v3.1 and Platform AnyCPU.
Turns out there was another problem. For my other .NET Framework test projects I had defined *.runsettings file
And in this file I had
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Parameters used by tests at runtime -->
<TestRunParameters>
<Parameter name="ConnectionString" value="Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True" />
</TestRunParameters>
<RunConfiguration>
<!-- Framework35 | [Framework40] | Framework45 | FrameworkCore10-->
<TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
Supported values for TargerFrameworkVersions based on https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019
are:
FrameworkCore10 for .NET Core sources, FrameworkUap10 for UWP-based
sources, Framework45 for .NET Framework 4.5 and higher, Framework40
for .NET Framework 4.0, and Framework35 for .NET Framework 3.5.
But for Core 3.1, FrameworkCore10 doesnt work!
So I removed node TargetFrameworkVersion completely
I had the same problem in VS 2019 on a legacy project.
Restarting Visual Studio did not help, nor did build as Release then rebuild as Debug, nor did deleting the .vs folder. I did those things and still was unable to run tests, getting a message like the OP's during test detection each time. I mention these here for completeness.
I deleted the LocalTestRun.testrunconfig file and the *.vsmdi file from Solution Explorer, cleaned and rebuilt the solution, and the unit tests worked again.
I was running into the same issue with the Visual Studio Test Task version 2 in an Azure Devops 2019 pipeline after a .csproj test project was upgraded from .NetFramework 4.6.1 to .NetCore 3.1.
The fix for us was to be more specific when specifying the test files. The default of **\*test*.dll was finding several other assemblies with "test" in their names that didn't exist before the upgrade. Using an explicit **\<MyTestAssemblyName>.dll fixed the issue.
I've been extremely frustrated trying to deploy a C#/WPF application I've created that has some references to 3rd party DLLs. I created a folder in the project, called lib, where I placed all of these DLLs. In VS2012, I added the references by browsing to that folder, and selecting all the DLLs. Copy Local is set to true for all. Everything is fine when I build and run, but when I choose publish, and create a OneClick Installer, things aren't so smooth. During the publish wizard, I set it to install from disk, and set it to never check for updates. I take that folder, place it on a flash drive, plug it into another PC, run the setup, and it throws an Exception. I believe I know what is happening, but I cannot figure out how to package this in order to deploy it correctly.
One of my DLLs is a C# wrapper to a DLL that is designed for a C++ project. We'll say, Application requires DLL1 and DLL1 requires DLL2. DLL2 cannot be added as a reference in the project because is not a .NET DLL. DLL1 requires DLL2 to be in the same folder in order to pick it up. I'm using CefSharp which wraps the Chromium Embedded Framework.
I've tried placing the required DLLs for CefSharp.dll in the publish/Application Files directory, but it did not work. I noticed that all of the DLLs that are there from VS2012 have a .deploy extension on them, I even went and added that extension on to see if it was scanning for that to pick up, but it did not work either. This is my first time doing development and deployment for a Windows application and all of the tutorials on MSDN or blog posts I've read do not seem to cover this case, and I do not see any other options in the deployment manager to handle these types of cases.
If it helps, the Exception Code that is thrown is: CLR20r3
When I catch and display Exception, all of the info I am provided basically says CefSharp.dll or one of it's dependencies cannot be loaded. Which I've gotten before when DLL2 was not in the same folder as DLL1.
Can anyone provide help on how to deploy from VS2012 with a situation like this?
Thanks in advance!
Edit: Info Update
I was attempting to push a debug build version to a test machine without Visual Studio installed. When building for CefSharp or any other C++ Runtime DLL, it will look for all of the Debug versions of the DLL which are usually the same name, but with the letter 'd' added to the end. As mentioned below, the Debug version of the C++ Runtime is not redistributable. Not that you can't manually add those DLLs to your project and set them as Copy Always, but that's kind of a hack job. I started a new project from scratch, added all Release versions of the DLLs, built, and everything was fine.
I've been tearing my hair out trying to fix this very problem this morning and eventually found the solution. It seems you already know which DLLs etc. you need for CefSharp to work but I thought I would run through this in case anyone else is having the same problem. I have a C# WPF application and I'm using CefSharp as the web view. I'm using CefSharp v1 because I need the JavaScript -> C# bridge they provide which isn't yet implemented in v3. Here are the rough steps I went through in setting up the project (I'm using VS2013 but this will probably work in VS2012).
Installing CefSharp
Install CefSharp.Wpf through NuGet (I'm using v1.25.7)
That should put the relevant files in $(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef
Configuring Build
To get the CefSharp DLLs to copy to our build folders, right-click on your project, select Properties -> Build Events and enter the following in the "Post-build event command line":
xcopy "$(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef*" "$(TargetDir)" /s /y /i
That should now copy all of the required DLLs from the cef folder as well as the devtools_resources.pak file and the locales folder plus its contents. I require them in my project as I need the chromium dev tools.
Double-check your project references contain CefSharp and CefSharp.Wpf. That should have been taken care of by NuGet.
Taking care of Visual C++ 2012 Runtime Files
I didn't want the user to have to download the whole Visual C++ 2012 Runtime Files as part of the deployment so through Visual Studio, add the folder Lib\Microsoft.VC110.CRT and add the 3 DLLs (msvcp110.dll, msvcr110.dll, vccorlib110.dll) from the following folder on your machine to the folder you just created in your project:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\redist\x86\Microsoft.VC110.CRT
Select the 3 DLL files in Visual Studio, right-click -> properties. Make sure Build Action is set to "None" and Copy to Output Directory is set to "Do not copy". Now you need to add another post-build event to make sure these are copied properly (i.e. copied to the root so they sit alongside the CEF dlls and your project exe) for debug.
Right-click on your project, select Properties -> Build Events and enter the following in the "Post-build event command line" just after your other xcopy command for CEF:
xcopy "$(ProjectDir)Lib\Microsoft.VC110.CRT*.*" "$(TargetDir)" /s /y /i
At this point, everything should be building. To publish the app with ClickOnce, I need it to push all of the CEF DLLs out as well as ensuring the files/folders required for chromium dev tools are present. If you don't need the dev tools or all of the DLLs then you can tweak this accordingly.
Ensuring CEF and C++ runtime files are deployed with ClickOnce
Right click your project in Visual Studio and select "unload project".
Right click and select to edit the csproj file.
Before the closing </Project> tag add this
<ItemGroup>
<Content Include="$(SolutionDir)packages\CefSharp.Wpf.1.25.7\cef\**\*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(ProjectDir)Lib\Microsoft.VC110.CRT\**\*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
That will add everything from the cef folder into the project and make sure the C++ binaries are copied to the root of the project on deployment. In my case for CEF, I'm using the \**\* syntax at the end of the Include and %(RecursiveDir) to ensure all of the files are copied as well as the locales folder with its contents and structure preserved. Having set <Visible>false</Visible> you won't see the items in the solution explorer.
Relax
Now if you publish your app, it should copy over all of the required files and folders.
You could try this which solved a similar issue for me:
Add the DLL's that are not .NET libraries to the solution as files:
Right click project > Add > Existing Item
Then set their build action to Content and "Copy to output directory" to "Copy Always".
That way the libraries will be included in the output directory.
Since you already tried manually adding the suspect dll and it still does not work, the next thing I would do is run fusion and see what it really is complaining about, in other words what exactly is the dependency that can not be loaded. Here is a good tutorial on how to hunt down these types of errors:
Back to Basics: Using Fusion Log Viewer to Debug Obscure Loader Errors
Maybe you can work it out from the https://github.com/Code52/DownmarkerWPF sources?
They have at least a working ClickOnce installer for their app embedding CefSharp. I know because that's the way it got installed on my machine!
update just saw in comments that it's the VC Redist that you say you are missing then Distributing the Visual C++ Runtime Libraries (MSVCRT) seems relevant.
Also I seem to remember something vaguely about that for "VCRedist reasons" you are not supposed to distribute debug versions of your application. Can't you just switch from a Debug to a Release version? With this I think you can either bundle the needed VCRedist files as suggested in the CefSharp FAQ or add VCRedist as a prerequisite in your installer. DownmarkerWPF does it with their WIX installer setup which you can find on a branch in their GitHub repo. Something similar is AFAIK possible with the VStudio bundled installer if that's what you use.
Thanks to Barrie's answer to this, it helped me greatly. I'm using his answer below, but updating it to work for the latest CEF using Visual Studio 2015.
NOTE: I am only building/targeting the x86 platform. You may need to change or include x64 in the copy commands below to suit your needs.
Installing CefSharp
Install CefSharp.Wpf through NuGet (I'm using v51.0.0)
NuGet Library After Install
That should put the relevant files in
$(SolutionDir)packages\CefSharp.Wpf.51.0.0\CefSharp (CefSharp.Wpf)
$(SolutionDir)packages\CefSharp.Common.51.0.0\CefSharp (CefSharp.Common)
$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF (Cef x86 redist)
$(SolutionDir)packages\cef.redist.x64.3.2704.1432\CEF (Cef x64 redist)
Configuring Build
To get the CefSharp DLLs to copy to our build folders... I don't believe this is necessary anymore with the later versions of CefSharp. I found that I didn't need any of the "Post-build event command-line" xcopy stuff to get Click-Once to ship it out. (And yes, DevTools works too!)
Taking care of Visual C++ 2012 Runtime Files
(Switched to VCR 2013) I didn't want the user to have to download the whole Visual C++ 2013 Runtime Files as part of the deployment, so through Visual Studio, add the folder lib\Microsoft.VC120.CRT and add the 3 DLLs (msvcp110.dll, msvcr110.dll, vccorlib110.dll) from the following folder on your machine to the folder you just created in your project:
C:\Windows\SysWOW64
(Didn't see them in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist)
At this point, everything should be building. To publish the app with ClickOnce, we need it to push all of the CEF DLLs. You can tweak this accordingly...
Ensuring CEF and C++ runtime files are deployed with ClickOnce
Right click your project in Visual Studio and select "unload project".
Right click and select to edit the csproj file.
Before the closing tag add the following:
<!-- BEGIN: CUSTOM ITEM GROUP INCLUDES INTO THE PROJECT (SO CLICK-ONCE PUBLISHES THEM) -->
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF\x86\**\*;$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF\locales\**\*.pak">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF\**\en-US.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\cef.redist.x86.3.2704.1432\CEF\x86\**\*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)packages\CefSharp.Common.51.0.0\CefSharp\x86\**\CefSharp.BrowserSubprocess.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="$(ProjectDir)lib\Microsoft.VC120.CRT\**\*">
<Link>%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
<!-- END: CUSTOM ITEM GROUP INCLUDES INTO THE PROJECT (SO CLICK-ONCE PUBLISHES THEM) -->
That will add everything from the cef folder into the project and make sure the C++ binaries are copied to the root of the project on deployment. Having set false you won't see the items in the solution explorer.
REMEMBER: I am only building/targeting the x86 platform. You may need to change or include x64 in the copy commands below to suit your needs.
Publish
Now if you publish your app, it should copy over all of the required files and folders.
(EXTRA INFO) Supporting Older Operating Systems Info Below
If you need to use CefSharp for older machines (XP & Vista), simply
install CefSharp.Wpf through NuGet using the older v47.0.0 version and change your .NET targeting to .NET 4.0 Client Profile.
Chromium ended support for XP and Vista in April 2016, CefSharp version 47 (or there abouts) still had support for it.
Another note on a problem and fix for XP:
There is a Chromium issue for XP deployments. Below is the article describing the fix followed by steps to deploy fix for JBCB.
Here's the link to the article:
https://bitbucket.org/chromiumembedded/cef/issues/1787
...in it you'll see a reference to download a "dbghelp.dll". Download and extract.
YOU CAN TAKE A POST-INSTALL APPROACH LIKE BELOW OR CHOOSE TO INCLUDE THE DLL ALONG WITH YOUR OTHER PUBLISHED FILES. I'M CHOOSING NOT TO DEPLOY THE EXTRA DLL AND ONLY DEPLOY ON XP MACHINES (WE ONLY HAVE FEW) MANUALLY.
Take these steps to fix deployment on an XP machine:
Install the CefSharp Browser on the XP machine (via Click-Once)
Copy the "dbghelp.dll"
Paste it in the local install directory on the XP machine (per the instructions in previous link: along side the "libcef.dll" file).
NOTE: For click-once installs, will be in a sub-folder under this location:
C:\Documents and Settings\<UserName>\Local Settings\Apps\2.0\<auto-gen ostificated ID>
Read very carefully the official list of CefSharp dependencies - there are a lot of them! You need to get them all into the ClickOnce bin folder somehow.
Here is how I solved it:
Before deploying, install the latest version of Visual C++ Redistributable. on each PC you are deploying to (using group policy or just manually).
Start with a blank test project.
Add project references to CefSharp, CefSharp.Core, etc.
Add each dependency into a single folder in the project directory to keep them organised (Files\CefSharp\).
Ensure all files are configured with Build Action: Content, and Copy to Output Dir: Copy always.
Make a function Initalise_CefSharpFiles() to copy the files/folders into the bin root folder (where CefSharp looks for them). For example, copy from: Bin\Files\CefSharp\* to: Bin\*.
And finally at run time, call Initalise_CefSharpFiles() once after the app loads, and before initialising CefSharp's settings.
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.
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).