As part of a WebApi app upgrade, I upgraded an Azure function from .Netcore 2 to .Net5. This function has previously worked. When I run the function, I get the following error:
System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
I made the following changes to the function project as part of the upgrade:
Changed Project file TargetFramework to .net5.0
Changed AzureFunctionsVersion to v3
Upgraded the referenced packages
Microsoft.Azure.WebJobs
Microsoft.Azure.WebJobs.Extensions.EventGrid
Microsoft.Azure.WebJobs.Extensions.Storage
Newtonsoft.Json
I changed the Azure function configuration setting for the Runtime Version to ~3.
After getting the above error, I also added the packages
Microsoft.Extensions.Logging
Microsoft.Extensions.Logging.Abstractions
Building the project with the above references doesn't create the Microsoft.Extensions.Logging.Abstractions.dll in the .Net5 bin directory. Note that I do see that dll in the bin directory of the .Netcore 2 build. Why am I not seeing the dll when building for .Net5?
Functions.csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.27" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.12" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VI.VirtualIncision.Managers\VI.VirtualIncision.Managers.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Based on your packages (i.e. Microsoft.Azure.WebJobs) and your csproj file it looks like you are currently running an "in-process Azure Function", and .NET 5 is not supported for these types of Azure Functions, so that is why you are getting that error. So you have 3 options:
Based on this Microsoft blog post, it looks like Microsoft is planning on skipping.NET 5 and just adds support for .NET 6 to in-process Azure functions. So you can just wait for .NET 6.
You can try to switch your Azure Function to be a .NET Isolated Process Function which is more involved than just simply updating some packages and changing the target framework. It requires some major changes to how your project is setup and what nuget packages you are using. Microsoft has a guide around this here: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide
You can also just downgrade your Microsoft packages to 3.x.x version and keep everything .NET Core 3.1. You will need to make sure you don't have any other dependencies that use .NET 5 packages or else you will see a similar issue.
A quick preamble, I have seen a number of questions with this error already, but in all cases, these were users that were actually attempting to host asp.net core apps using the wrong container. That is not the case in my situation.
I have a working .net core console app hosted in a docker container that was targeting netcoreapp2.1 I started to update it to netcoreapp3.1 by changing the TargetFramework tag and updating the nuget packages. I also updated the base docker image (.net core runtime) from 2.1 to 3.1.
When I attempt to start this image I get the following error:
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=ubuntu.18.04-x64
The error message is correct that framework is not installed, but it should be looking for Microsoft.NetCore.App, which is installed in the container. It seems that is governed by The value of the Sdk attribute in the Project element in the csproj file which is <Project Sdk="Microsoft.NET.Sdk"> in this project.
What is causing the runtime to look for the wrong framework dependency?
The issue was a package reference to Serilog.AspNetCore The netstandard 2.0 version of the package is fine but the netcoreapp 3.1 version takes a framework refernce on Microsoft.AspNetCore.App:
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
</ItemGroup>
This dependency doesn't seem to be visible anywhere, which was why it was so difficult to track down. Removing the package, which didn't seem to actually be needed solved the problem.
I have installed VS 2019 on my windows 10.
Created ASP.net Core Web Project -> Selected API.
When I try to generate controller referring the model and created the context class,
It is not generating the controller class but it gives me the following error:
Error,
there was an error running the selected code generator
'Unhandled exception. System.IO.FileNotFoundException: Could not load
file or assembly 'Microsoft.VisualStudio.Web.CodeGeneration.Utils,
Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The system cannot find the file specified. File name:
'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=3.1.2.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60' at
Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Main(String[]
args)
I also had this problem but the follwing answer worked for me.
Select "Manage Nuget Packages" and install these packages
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" ExcludeAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="3.1.2" />
To solve the problem, you can right click on your project, then select Manage Nuget Packages.
Next, Search Microsoft.VisualStudio.Web.CodeGeneratio.Utils, then install it.
After installing the above, It is generating without error.
Please check if you have all the package on compatible version. This could happen when you have packages of different versions, one of which is not supporting the current functionality/project type.
First, check your csproj file. There is no package reference for 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=3.1.2.0'. This is why the error message showing "Could not load file or assembly". Easy to solve. https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Utils/
Go to Package Manager Console install it.
For what it's worth, the below solution is what worked for me.
My Setup:
First of all my project setup was different. I had a MyProject.Data and MyProject, and I was trying to scaffold "API Controller with actions, using Entity Framework" on to my API folder in MyProject, and I was getting the error in question. I was using .net 3.1.
Solution:
I had to downgrade all the below nuget packages installed on MyProject.Data project
Before downgrade:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
After downgrade:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.11">
Then tried again to use scaffolding and it just worked!!
After scaffolding MyProject had the below nuget package versions installed:
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.11"/>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
The main problem was that no errors were displayed other than the one that shows up on the dialog box or does not even point us to any logs or nor any helpful documentation are available. If anyone finds one please attach it to this answer. It was very frustrating and this almost ate away half-day of my weekend :(
Hope it helps someone. Happy coding!!
I had a .Data project and another another .API project in my solution. The auto scaffolded action controller was trying to add Microsoft.VisualStudio.Web.CodeGeneration.Design which goes up to v5.0.2. I had to downgrade all my nuget packages down to 5.0.2 as follows:
Data Project
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
API project
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
The API action controller with EF core dbcontext was then able to successfully add:
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
I hope this helps! All the best.
I was having a similar behavior, but with a different version of the package: 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=3.1.4.0'.
The package was already installed (both in Manage NUGet Packages and also in .csproj file). I uninstalled it from Manage NUGet Packages and reinstalled.
That solved my issue.
I have also face the same problem. It's a problem with different versions of the NuGet Packages. just try to use similar versions of packages.
Microsoft.VisualStudio.Web.CodeGeneration.Utils(5.0.2)
Microsoft.VisualStudio.Web.CodeGeneration.Design(5.0.2)
I had similar error during ovveride Identity login and register layout.
I did uninstall all package from Application.Web and install again.
My reinstall libraries from NuGet Packages:
Microsoft.AspNetCore.Authentication.Google
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.AspNetCore.Identity.UI
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.VisualStudio.Web.CodeGeneration.Design
My solution had 5 projects (2 dlls, webservice, db and MVC). I removed all but the MVC project and the problem ceased. Added all the projects back in and the problem did not return. Comparing the old solution file to the new one showed a bunch of changes, difficult to say which change was the fix, but the solution file is much cleaner.
In my case, I only update the dependencies for the same version and It Works :)
I Just update al NuGet Packages installed in my project and it run perfectly.
Check and see if you have any warnings about nullable types. If you do, you can update your "ProjectName".csproj and remove the line:
enable
Build the project, and retry.
enter image description here
We have a continuous WebJob that is written in .NET Core 2.x and has been running fine for the past few weeks. Recently someone made some changes to this WebJob and brought in a 3rd party NuGet package. Now, I am unable to start the WebJob because it is unable to locate one of the 3rd Party libraries dependencies.
This is the error message:
D:\local\Temp\jobs\continuous\Temp1\oitdncff.sfg>dotnet Temp1.dll
Error:
An assembly specified in the application dependencies manifest (Temp1.deps.json) was not found:
package: 'System.Drawing.Common', version: '4.5.0-preview1-25914-04'
path: 'runtimes/win/lib/netcoreapp2.0/System.Drawing.Common.dll'
I have tried several things I found whilst Googling this problem. Here is the PropertyGroup and ItemGroup (NuGet packages) from the csproj file:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ApplicationIcon />
<StartupObject>Temp1.Program</StartupObject>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>latest</LangVersion>
<Version>1.0.0.0</Version>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="AsyncEnumerator" Version="2.1.0" />
<PackageReference Include="EPPlus.Core" Version="1.5.4" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.5.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.5.1" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
Per suggestions online, I added the line
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
and
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
The package in question that has the dependency is EPPlus.Core
I have confirmed that the library System.Drawing.Common does exist in the app folder on our Azure Web App but the when the WebJob starts up, it is ignoring that the file is there and looking in the runtimes (GAC) and failing.
UPDATE:
I realized that the EPPlus.core package was not official so switched over to the official package hoping this would resolve the error. Same error but a new version of the System.Drawing.Common version: 4.5.0-preview1-26216-02
I have manually added the NuGet package for System.Drawing.Common version: 4.5.0-preview2-26406-04 to the project, this removed the original error but then I started getting an error that Microsoft.Win32.SystemEvents version: 4.5.0-preview2-26406-04 could not be found. This library is a dependent of System.Drawing.Common.
I attempted to do the same thing I did above and added the NuGet package for Microsoft.Win32.SystemEvents version: 4.5.0-preview2-26406-04 directly to the project but this time the error is not going away.
FURTHER UPDATE:
After searching more, I came across a posting here that talked about publishing and then zipping up the published directory and uploading the zip. This did actually work, the error in question was gone but this is not really a solution. We are using VSTS as our repo system and our CI/CD. I have the build configration set to do a publish and then copy the files up. The WebJob throws the error when its deployed via this process.
First, I would like to state that as of today, to my knowledge, .NET Core is not 100% supported with Azure WebJobs (feel free to correct me if I am wrong) but there are lots of articles and posts on how to make them work.
Below is the solution I did to get around the above issue I was having and whilst I do not feel this is elegant, I do feel that Microsoft has done something odd that most developers would not think is the correct path.
The reason I was having issues was that when I built (in debug or release) the manifest file was always pointing to the runtimes (GAC). Running locally on my box was never an issue because the files could be found. The oddity is when building in release mode, all files were copied to the bin folder yet the manifest still told the program to look in the runtimes and not to use the local copies. When this was pushed out to the WebJob itself, these files did not exist in the runtime so the WebJob would throw exceptions.
The workaround I had to do is as follows:
dotnet build (Solution - Release Configuration)
dotnet publish (WebJobs Only - Do Not Zip)
dotnet publish (Web Project Only - Do Not Zip)
Copy WebJob Data from Publish to the Web Project directory \App_Data\jobs\continuous\ directory
Zip Up Web Project Published Directory (this is what gets deployed)
My honest opinion is, when I build a webjob project in release mode, the process should transform the manifest to look for any referenced libraries locally before attempting to look for them in the runtimes.
I am trying to port a Windows.Forms application to .Net Standard 2.0 using Visual Studio Code. Based on responses to an earlier question (thank you guys), my plan is to try to use Xamarin.Forms to replace System.Windows.Forms. So, I add the Xamarin.Forms package to my project. When I try to run dotnet build, then I see the following error:
C:\Users\<user>\.nuget\packages\xamarin.forms\2.4.0.38779\build\netstandard1.0\Xamarin.Forms.targets(51,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:\Users\<user>\.nuget\packages\xamarin.forms\2.4.0.38779\build\netstandard1.0\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
I have tried to add various other Microsoft.Build packages but nothing seems to work. Is there a way forward here? Here's my current csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.Build" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.3.409" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="System.Configuration" Version="2.0.5" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
<PackageReference Include="System.ServiceModel" Version="1.0.0" />
<PackageReference Include="Xamarin.Forms" Version="2.4.0.38779" />
</ItemGroup>
</Project>
I think that I may be asking the same question as here: Where is the difference of dotnet build on cmd vs VS2017? but am not sure.
I'm working on a Xamarin.Forms application and I'm migrating my libraries from PCL to NetStandard.
It seems that you can build the project with MsBuild.exe (I used C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe).
I found it mentioned in this blog post: https://oren.codes/2017/04/23/using-xamarin-forms-with-net-standard-vs-2017-edition/
You will need to use MSBuild.exe to build this, either on Windows with a VS 2017 command prompt or a Mac with Visual Studio for Mac. You cannot use dotnet build for these projects types. dotnet build only supports .NET Standard, .NET Core and .NET Framework project types. It is not able to build the Xamarin projects and the custom tasks in Xamarin Forms have not yet been updated to support .NET Core.
An additional note: I had to delete AssemblyInfo.cs, otherwise MsBuild complained about duplicate properties.