Azure Function V1 Build issue - c#

Two day ago i started to experience an issue during build of my Azure Function App V1. Build process halts on GenerateFunctionsExtensionsMetadata task, particularly on AWSSDK.Core.dll assembly.
I have successfully used Microsoft.NET.Sdk.Functions 1.0.38 for several months. But something changed.
I can solve this by downgrading Microsoft.NET.Sdk.Functions to 1.0.37. In this case there is no such build step.
Do somebody know what could cause such an issue? Or any suggests to investigate it further?

This looks similar to GitHub issue#287.
Try adding below piece of code in your .csproj file:
<Target Name="HackMoveNativeDlls" BeforeTargets="_GenerateFunctionsExtensionsMetadataPostPublish">
<Move SourceFiles="$(PublishDir)bin/Cosmos.CRTCompat.dll" DestinationFolder="$(PublishDir)bin/temp"/>
<Move SourceFiles="$(PublishDir)bin/Microsoft.Azure.Documents.ServiceInterop.dll" DestinationFolder="$(PublishDir)bin/temp"/>
</Target>
<Target Name="HackRestoreNativeDlls" AfterTargets="_GenerateFunctionsExtensionsMetadataPostPublish">
<Move SourceFiles="$(PublishDir)bin/temp/Cosmos.CRTCompat.dll" DestinationFolder="$(PublishDir)bin"/>
<Move SourceFiles="$(PublishDir)bin/temp/Microsoft.Azure.Documents.ServiceInterop.dll" DestinationFolder="$(PublishDir)bin"/>
</Target>
This is a hack to resolve this problem. It happens to functions that use CosmosDB SDKs.

Related

Could not load file or assembly 'System.Private.ServiceModel' in Azure Function v2

I used a v2 azure function (durable function) with custom dll (.net core 2.2) that calls a service and I get the following exception:
Could not load file or assembly 'System.Private.ServiceModel,
Version=4.1.2.4, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
In the debugging process, I can't step into the method and the exception is thrown without letting me inside it and I don't know exactly what tried to access that library.
Putting manually the package from .nuget in the bin folder didn't work and the strange thing is that if a run the same code with a sample C# function it works.
fixed
Nuget Install or Update System.Private.ServiceModel
Install-Package System.Private.ServiceModel -Version 4.7.0
https://www.nuget.org/packages/System.Private.ServiceModel/
This issue is detailed here: https://github.com/dotnet/wcf/issues/2824
How I solved it was to download the nuget System.Private.ServiceModel
and add the following to my .csproj
<Target Name="CopySPSM" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.5.3\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>
I got this with a Blazor 3.1 app. Works fine locally, but, when deployed to Azure I get:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.ServiceModel
To fix it, in the Publish Profile, in Visual Studio, I changed the Target runtime from win-x86 to portable
There is a big thread about this on github. I added the PostBuild event as in that thread, but I was still struggling in the CI/CD build pipeline. In the end, I also added a cmd line script step in the build pipeline after the "Build Solution" step with the following code:
copy $(Agent.TempDirectory)\WebAppContent\bin\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll $(Agent.TempDirectory)\WebAppContent\bin\System.Private.ServiceModel.dll
This solution does not seem that clean but it worked for me.
Try to check in your cs.proj if System.Private.ServiceModel.dll is implemanted, if it's not the case you can refer to this work around : https://github.com/dotnet/wcf/issues/2824

HTTP Error 500.30 - ANCM In-Process Start Failure

I was experimenting with a new feature that comes with .NET core sdk 2.2 that is supposedly meant to improve performance by around 400%.
Impressive so I tried it out on my ABP (ASP.NET Boilerplate) project
Template asp.net core mvc 4.0.2.0
I added the following to my web.mv.cproj file
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
Unfortunately I do not think this version of the ABP framework is compatible as the project simply fails to run and throws: (eventually)
HTTP Error 500.30 - ANCM In-Process Start Failure
I checked the logs after setting stdoutLogEnabled="true" in the web.config and re-trying - but no entries.
Has anybody had any success running the current ABP against a asp.net core in process setup?
I'm thinking this may be something only available in ABP vNext.
In ASP.NET Core 2.2, a new Server/ hosting pattern was released with IIS called IIS InProcess hosting. To enable inprocess hosting, the csproj element AspNetCoreHostingModel is added to set the hostingModel to inprocess in the web.config file. Also, the web.config points to a new module called AspNetCoreModuleV2 which is required for inprocess hosting.
If the target machine you are deploying to doesn't have ANCMV2, you can't use IIS InProcess hosting. If so, the right behavior is to either install the dotnet hosting bundle to the target machine or downgrade to the AspNetCoreModule.
Source: jkotalik (Github)
Try changing the section in csproj (edit with a text editor)
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
to the following ...
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
</PropertyGroup>
Source (Github)
From ASP.NET Core 3.0+ and visual studio 19 version 16.3+ You will find section in project .csproj file are like below-
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
There is no AspNetCoreHostingModel property there. You will find Hosting model selection in the properties of the project. Right-click the project name in the solution explorer. Click properties.
Click the Debug menu.
Scroll down to find the Hosting Model option.
Select Out of Process.
Save the project and run IIS Express.
UPDATE
For Server Deployment:
When you publish your application in the server there is a web config file like below:
change value of 'hostingModel' from 'inprocess' to 'outofprocess' like below:
From Several Comments, I have learnt that 'OutOfProcess' is worked for them instead of 'outofprocess'.
In my case I had recently changed a database connection string in my appstettings.json file. Without logging or error catching in place I suspect this error wound up causing the "HTTP Error 500.30 - ANCM In-Process Start Failure" error.
I happened to notice the exchange between x-freestyler and Tahir Khalid where Tahir suggested an IOC problem in startup. Since my startup had not changed recently but my appstettings.json had - I determined that the connection string in my appstettings.json was the cause of the problem. I corrected an incorrect connection string and the problem was solved. Thanks to the whole community.
HTTP Error 500.30 – ANCM In-Process Start Failure” is moreover a generic error. To know more information about the error
Go to Azure Portal > your App Service > under development tools open console.
We can run the application through this console and thus visualize the real error that is causing our application not to load.
For that put, the name of our project followed by “.exe” and press the enter key.
I got the same error on my development machine running Windows 10. The error did not go away after I installed dotnet core hosting bundle. I had to go to Event Viewer to get the detailed error. Your underlying issue (if any) may be different than mine. Point is, if you're on a Windows machine, Event Viewer is there to provide details. Hope this helps someone.
If you are using Visual Studio, and have any instances of it running, close them all.
You should find a .vs sub folder where your
Visual Studio solution (.sln file) resides.
Delete the .vs folder and try again with the in-process hosting model.
ASP.NET Core 2.2 or later: For a 64-bit (x64) self-contained deployment that uses the in-process hosting model, disable the app pool for 32-bit (x86) processes.
In the Actions sidebar of IIS Manager > Application Pools, select Set Application Pool Defaults or Advanced Settings. Locate Enable 32-Bit Applications and set the value to False.
Source: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0#create-the-iis-site
I looked at the Windows Logs under Application. It displayed the error message and stack trace. I found out I was missing a folder called node_modules. I created that folder and that fixed it.
I did not make any changes to web.config or the project file. My .NETCoreApp version was 3.1
Removing the AspNetCoreHostingModel line in .cproj file worked for me. There wasn't such line in another project of mine which was working fine.
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
In may case it was just a typo which corrupts and prevents parsing of JSON settings file
Mine is because of UseKestrel() in program.cs
It should be .ConfigureKestrel() in 2.2
more info at https://learn.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=visual-studio&WT.mc_id=-blog-scottha#update-kestrel-configuration
I found another issue that starts out giving the same error message as in the question. I am sharing this here so that before changing the project file you can make sure your services are properly registered.
I am also running .netcore 2.2 and was receiving the same error message so I changed project file from InProcess to OutOfProcess as in the selected answer. After that I found the real cause for my issue when I received “Cannot instantiate implementation type” :
The cause of this was for me was having:
services.AddScoped<IMyService, IMyService>();
instead of
services.AddScoped<IMyService, MyService>();
Related post:
Why am I getting the error "Cannot instantiate implementation type" for my generic service?
I had a similar issue when attempting to switch to from OutOfProcess hosting to InProcess hosting on a .Net Core project which I had recently upgraded from 2.0 to 3.0.
With no real helpful error to go on and after spending days trying to resolve this, I eventually found a fix for my case which I thought I'd share in case it is helpful to anyone else struggling with this.
For me, it was caused by a few Microsoft.AspNetCore packages.
After removing all of the referenced Microsoft.AspNetCore packages that had version less than 3.0.0 (there was no upgrade available >= 3.0.0 for these) this error no longer occurred.
These were the packages I removed;
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
All other Microsoft.AspNetCore packages with version greater than or equal to 3.0.0 worked fine.
Download the .NET Core Hosting Bundle installer using the following link:
Current .NET Core Hosting Bundle installer (direct download)
Run the installer on the IIS server.
Restart the server or execute net stop was /y followed by net start
w3svc in a command shell.
moreover a generic error. To know more information about the error Go to Azure Portal > your App Service > under development tools open console. We can run the application through this console and thus visualize the real error that is causing our application not to load. For that put, the name of our project followed by “.exe” and press the enter key.
https://learn.microsoft.com/en-us/answers/questions/38950/http-error-50030-ancm-in-process-start-failure.html
This publish profile setting fixed for me:
Configure Publish Profile -> Settings -> Site Extensions Options ->
[x] Install ASP.NET Core Site Extension.
After spending an entire day fighting with myself on deciding to host my asp.net core application on IIS with InProcess hosting, i am finally proud and relieved to have this solved. Hours of repeatedly going through the same forums, blogs and SO questions which tried their best to solve the problem, i was still stuck after following all the above mentioned approaches. Now here i will describe my experience of solving it.
Step 1: Create a website in IIS
Step 2: Make sure the AppPool for the website has .Net CLR version set to "No Managed Code" and "Enable 32-bit Applications" property in AppPool -> Advanced Settings is set to false
Step 3: Make sure your project is referencing .Net core 2.2
Step 4: Add the following line in your startup.cs file inside ConfigureServices method
services.Configure<IISServerOptions>(options =>
{
options.AutomaticAuthentication = false;
});
Step 6: Add the following Nuget packages
Microsoft.AspNetCore.App v2.2.5 or greater
Microsoft.AspNetCore.Server.IIS v2.2.2 or greater
Step 7: Add following line to your .csproj file
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
Step 8: Build and publish your code (preferably x64 bitness)
Step 9: Make sure you added your website hostname in etc/hosts file
Step 10: Restart World Wide Web Publishing Service
Now test your asp.net core application and it should be hosted using InProcess hosting
In order to verify whether your app is hosted using InProcess mode, check the response headers and it should contain the following line
Server: Microsoft-IIS/10.0 (IIS version could be any depeding on your system)
Update: Download and Install ASP.Net Core Hosting Bundle which is required for it to work
In my case it was a wrong value in appsettings.json file. The value was .\SQLEXPRESS and it worked after i changed it to .\\SQLEXPRESS
Resolved my issue by running dedicated App Pool for AspNetCoreModuleV2
Description:
HTTP Error 500.34 - ANCM Mixed Hosting Models Not Supported
I was running multiple applications under the same App Pool.
Some of the applications were running
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
The application causing the error was running
AspNetCoreModuleV2
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
I created a new App Pool dedicated for AspNetCoreModuleV2 and it resolved my issue.
I encountered this issue on an Azure App Service when upgrading from 2.2 to 3.1. The reason ended up being the "ASP.NET Core 2.2 (x86) Runtime" Extension was installed on the App Service. Removing that extension from Kudu fixed the issue!
Wow, there are a lot of answers on this question, but I had this same issue and my solution was different from anything I read here, and also quite simple.
I had been having issues with deploying my app to azure with the right environment settings, so I was messing with the launchsettings.json file, and I had changed the value of the ASPNETCORE_ENVIRONMENT variable in the IIS profile from "Development" to "Production". Changing it back to "Development" fixed the issue for me.
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
Make sure that your *.deps.js json file copied correctly to the deployed location
In my case it was database connection problem. This error needs to be more clear. I hope they will do it in the future. Basically it is a problem at ConfigureServices function in Startup. My advise is try to add all lines try catch in ConfigureServices function and you can findout where is problem.
In my case after spending a lots of time the problem was the platform target was x86 and after change it to any CPU the issue fixed.
This error was blowing my mind. I tried all the things.
The magic happened when I deleted the published site from IIS, deleted the Application pool and created all over again. After that, It worked on the first request.
I don't know If I had broken some configuration before, but setting up the ISS site again worked.
For me it was wrongly injected DBContext in HostedService. I rewrote it according to this:
How should I inject a DbContext instance into an IHostedService?
and all worked fine!
Because the application crashes. For whom saving time on this exception!
And the error code says it throws an exception because it can't find a file in the initial phase.
See the Environment Settings section. In my scenario, it worked when I changed the following code
var environment = whb.GetSetting("environment");
to
var environment = "Development";// whb.GetSetting("environment");
Because I have appsettings.development.json but I didn't have appsettings.production.json. Why it can't find any file because it's looking for different thing on right place.
With .Net Core 2.2 you should be able to use the InProcess hosting model, since it is naturally faster: everything is processed in IIS, without an extra HTTP-hop between IIS and your app's Kestrel server. One thing you might want to do is add this tag:
AspNetCoreModuleV2
Notice the new AspNetCoreModuleV2 vs older AspNetCoreModule option.
Another important thing to do is, examine Windows Application Event Log, to identify the culprit. Although error messages there may be cryptic, occasionally, they point to the exact line numbers in the code that caused the failure.
Also, in case you use CI/CD with TFS, there maybe environment variables in appsettings.json file that were not properly replaced with their designated values, and this was one of the exception sources for me.
I had an issue in my Program.cs file. I was trying to connect with AddAzureKeyVault that had been deleted long time ago.
Conclusion:
This error could come to due to any silly error in the application. Debug step by step your application startup process.
In my case, I had a migration which was failing when run on a specific environment in Azure, but running fine in dev. As we have the service configured to run the migrations as part of startup, the actual startup of the web app fails.
I ran the migration manually on the environment to discover the problem, then adjusted it to deal with the data differences on that environment.
If anyone knows how I could have seen the migration error without manually running in directly on the DB, that would be useful.

Sautinsoft PdfFocus exception after migration to .NET Core 2.1

I have a purchased license of the DLLs (6.9.4.10) and my *.csproj contains this:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0"/>
...
<PackageReference Include="System.IO.Packaging" Version="4.5.0"/>
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0"/>
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.0"/>
</ItemGroup>
...
<ItemGroup>
<Reference Include="SautinSoft.PdfFocus">
<HintPath>..\PDF Focus .Net Full (6.9.4.10)\DLLs\Net Core 2.0\SautinSoft.PdfFocus.dll</HintPath>
</Reference>
</ItemGroup>
I am trying to convert a PDF into a DOCX-file (which worked in .NET 4.5).
This is the relevant part of the code:
....
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.Serial = Settings.GetAppSetting("PdfFocusSerial", "**MySerial**");
f.OpenPdf(buffer);
if (f.PageCount > 0)
{
f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
var result = f.ToWord(); //f.Exception set after this
...
}
...
I've checked that the same buffer is sent in as in the old code, but the output differs by some bytes. And I get an Exception set in f.Exception, which is:
{System.Collections.Generic.KeyNotFoundException:
The given key '0' was not present in the dictionary. ...
When I try to open the newly created *.docx-file, Word says it's damaged. After clicking through some dialogs it can still open the file.
Anyone have any ideas?
Is this a known bug for this library in .Net Core 2.1? (Only 2.0 is mentioned on their website)
I've also tried the free version published on NuGet with the same results.
EDIT
This was indeed a bug in the .NET Core specific version. They have fixed this in version 6.9.6.29.
My Name is Dmitry and I work in SautinSoft.
Thank you for your issue. You are right. We have some problems with PDF Focus.Net and Net Core 2.1
Our developers try to fix this issue. We have found where is a bug (resources/fonts) and I hope, that we will prepare a new version very quickly.
I'll inform you.
If you want to use "RTF to HTML" for Net Core 2.X-6.X please add these references in your project:
System.Drawing.Common, 4.7.0 or up.
System.IO.Packaging, 4.4.0 or up.
System.Text.Encoding.CodePages, 4.5.0 or up.
System.Xml.XPath.XmlDocument, 4.3.0 or up.
But If it will be Net Core 7.X for LinuxOS - it doesn't work, because the System.Drawing.Common NuGet package is now attributed as a Windows-specific library. The platform analyzer emits warning at compile time when compiling for non-Windows operating systems.

No job functions found. Try making your job classes and methods public

First off, I have looked at the other SO posts with the same error message and none seem to resolve my issue. I have tried many permutations and options. My function builds fine but will not run in the CLI, I get the following cryptic error. The MSFT documentation does not seem to have the answers either.
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
I am trying to run a timer job and then write a collection of messages to an event hub. What am I missing? I have been fighting this for hours.
Function:
[FunctionName("CreateData")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[EventHub("murraytest", Connection = "evingest")] IAsyncCollector<string> myeventhub,
TraceWriter log)
{
await myeventhub.AddAsync("data1");
await myeventhub.AddAsync("data2");
await myeventhub.AddAsync("data3");
log.Info($"COMPLETED: {DateTime.Now}");
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"Eventhub": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "",
"evingest": "Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=LtcqBLT5VWjg0dGMdIvxCcEGs8902010Y6y14iGg="
}
}
Packages
function.json - is missing any eventhub bindings!
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */5 * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
}
],
"disabled": false,
"scriptFile": "..\\bin\\AzFuncs.dll",
"entryPoint": "AzFuncs.Function1.Run"
}
If you are using Azure Functions in .NET 5 or higher with the out-of-proces execution model you need to replace your FunctionName with Function, otherwise the function will not be detected.
Before:
[FunctionName("CreateData")]
After:
[Function("CreateData")]
Another gotcha I found especially if you are converting from another project or version.
In the VS csproj file, make sure AzureFunctionsVersion is present
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
...etc
the tooling adds this automatically but not added if you are modifying a project where this was missing. Hope this helps you save the 3 hours it cost me :-).
You should upgrade to the latest Microsoft.NET.Sdk.Functions (1.0.6 as of today) and Microsoft.Azure.WebJobs.Service.Bus (2.1.0-beta4 if running on full framework). You might need to remove the ServiceBus reference first in order to upgrade SDK.
The Microsoft.Azure.Eventhubs package also needs to be removed. All relevant types etc are in Microsoft.Azure.WebJobs.Service.Bus
Also remember to check "Include prerelease" in the package manager in order to find 2.1.0-beta4.
In my case I was simply running the command from an actual function directory. You should run it from the root of the functions project instead!
My issue was different from the other answers: the local.settings.json was explicitly included in the .gitignore definition. As such the file was not included in a clone and the local build couldn't understand which was the correct runtime to use.
I pulled the default local.settings.json from a sample project to restore the file.
I randomly had this issue but it only affected the functions in one class. Turned out I just needed to run a dotnet clean first.
In my case (v3 on net core 3.1) it was a weird case that somehow this was removed from csproj file.
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
In my case, the clue was this message at the start of the console output:
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell]
Adding the --csharp argument did the trick.
It happened to me when I changed the name of the project and some other refactoring. It was working on that machine after the change, but interesting enough when I switch to a different machine, I got this error - even if it's the same code.
The solution was for me basically creating a random new azure function and running again. All my functions appeared on the cli on the next run.
I was running "func start" from the wrong folder. Make sure you're running it from the root folder of the azure function. This should be true for any language (I'm using python)
I appreciate the other answers here. But in my case none of them worked on VS Code.
I am still trying to use .NET core SDK version of 2.1 and had to use all old version of dependencies for my Azure function.
Even after everything seeming right, I was still unable to run the function locally. Turns out, there is a small step to be taken:
First, publish your project dotnet publish
The published stuff should be in bin/Debug/netstandard2.0 . Just get inside this folder and run your function:
cd bin/Debug/netstandard2.0 # I was using netstandard2.0 framework
func start --build # You can add --verbose flag for more detailed outputs
Voila! That's it. Just to be clear, here are my versions:
.NET core SDK version: 2.1.810
Azure CLI version: 2.12.0
Azure Function version: v2
Microsoft.NET.Sdk.Functions: 1.0.37
I found this error when I use FunctionName like this:
[FunctionName("Example/signup")]
I removed "/" in FunctionName and resolved it.
After having upgraded a lot of packages - amongst others the one that triggered the change from [FunctionName("CreateData")] to [Function("CreateData")], I needed to delete the bin and obj folder before the functions were discovered again.
If it's working from bin/Debug/netcoreapp3.1/ etc this is because you are missing some needed files in the root or missing sections in some files. (eg: host.json)
I managed to fix this by running func init --force to restore the initial setup and use git to find the missing sections.
I got the error
no job functions found
when my firewall was blocking the azure functions program from connecting to the internet.
in my scenario, for Existing Project, I missed to give reference in .csproj file after installing azure function setup in windows
here is it
you can run command on VS Code Func init --force and Select Dotnet template and then delete .csproj file which is created automatically.
local.settings.json
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=false",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
.csproj file
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>
I hope someone helps out there if you are using like me visual studio code.
For some reason, my working project got this below info duplicated in the csproj file, and so ran into this same error while running the AzFunction locally. I removed the extraneous lines and it worked just fine.
<ItemGroup>
<None Include="Function1.cs" />
</ItemGroup>

ItemGroup Item scope, alternatively "Why does MSBuild hate me?"

I have a solution I'm trying to get to build on TFS. I want to update the versions of all appropriate files, and I've been stuck trying to get this done. There are plenty of links on how to do it, but none of them work for me, due to one little issue... Scope.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<Target Name="DesktopBuild">
<CallTarget Targets="GetFiles" />
<Message Text="CSFiles: '#(CSFiles)'" />
</Target>
<Target Name="GetFiles">
<ItemGroup>
<CSFiles Include="**\AssemblyInfo.cs" />
</ItemGroup>
<Message Text="CSFiles: '#(CSFiles)'" />
</Target>
</Project>
My tree looks like this:
test.proj
application.sln
application (Folder)
main.cs
Properties (Folder)
AssemblyInfo.cs
When I run "c:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe test.proj" from the solution folder... I get the following output:
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3074]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 7/6/2009 3:54:10 PM.
Project "D:\src\test.proj" on node 0 (default targets).
CSFiles: 'application\Properties\AssemblyInfo.cs'
DesktopBuild:
CSFiles: ''
Done Building Project "D:\src\test.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.04
So, how can I make my ItemGroup have global scope? All the Targets files used by the compiler and TeamBuild do this same thing, and theirs all seem to be global... I don't understand why this isn't working for me.
Any help?
Have you tried using DependsOnTarget rather than CallTarget? It could be that CallTarget is causing the scope issue.
The previous commenter was correct, you should change this to use DependsOnTargets instead of using the CallTarget task. What you are seeing is a bug not a scoping inssue. The way to avoid this bug is to use DependsOnTargets (which is a much better approach anywayz).
Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build
As said, you should use DependsOnTargets. I've done some research on MSBuild scope, you can find my results on my blog : http://blog.qetza.net/2009/10/23/scope-of-properties-and-item-in-an-msbuild-script/
The thing is there seems to be a global scope for the project and a local scope for the target . When entering the target, the global scope is copied and when exiting the target, the local scope is merged back. So a CallTarget will not get the modified local scope values but the DependsOnTargets will since the first target is exited before the entering the second target.
We do something similar in our build. We pass the version as a command line parameter.
In our TFSBuild.proj we set the version to 0.0.0.0 if no version was supplied:
<!--Our assembly version. Pass it in from the command prompt like this: /property:Version=1.0.0.0-->
<PropertyGroup>
<Version>0.0.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<!--Used to ensure there is a newline before our text to not break the .cs files if there is no newline at the end of the file.-->
<newLine>%0D%0A</newLine>
Then we do this:
<Target Name="BeforeCompile">
<!--Update our assembly version. Pass it in from the command prompt like this: /property:Version=1.0.0.0-->
<!--attrib needs to be run first to remove the read only attribute since files from tfs are read only by default.-->
<Exec Command='attrib -R $(SolutionRoot)\Source\Project\GlobalAssemblyInfo.cs' />
<WriteLinesToFile File="$(SolutionRoot)\Source\Project\GlobalAssemblyInfo.cs"
Lines='$(newLine)[assembly: AssemblyVersion("$(Version)")]'/>
</Target>

Categories