Unable to debug Azure Function that targets .NET 5.0 - visual-studio

I wrote a simple Azure Function from the template using the .NET CORE 3.1 as target framework.
After that I migrated the target framework to .NET 5.0 using the guide
After the migration I'm not able to debug the Azure Function. I get the usual message "the breakpoint will not currently be hit".
The csproj is this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
local.settings.json is this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
program.cs is this:
class Program
{
static Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
})
.Build();
return host.RunAsync();
}
}
The simple function is:
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
namespace FunctionAppNet50
{
public static class Function1
{
[Function("Function1")]
public static async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req)
{
var response = req.CreateResponse(System.Net.HttpStatusCode.OK);
return response;
}
}
}
Is this related to the ".NET isolated process" model or did I do something wrong?

Thanks... found the solution in the suggested articles by marc_c and Douglas.
I installed the Azure Function Core Tools using choco with the command "choco install azure-functions-core-tools-3";
run the function in a shell with "func start –-dotnet-isolated-debug";
attached the debugger at the PID showed in the window
here is an article that similar steps: https://dev.to/kenakamu/debug-net-5-function-with-visual-studio-visual-studio-code-5235

Related

NativeScript AdMob plugin - crash the app on emulator or on playground: Cannot read property 'getRewardedVideoAdInstance' of undefined

I've created a nativescript with angular (drawer template) app and everything works fine.
Using the command tns run android --bundle the app was successfully installed and runned on the Pixel 2 emulator.
The problem was after I installed the admob plugin, using the command tns plugin add nativescript-admob. Immediately app crashed on the emulator.
Bellow the package.json to proff the installation of the admob plugin on my app.
...
"nativescript-admob": "^4.0.1",
...
Nevertheless, I've continued following instructions from here: https://market.nativescript.org/plugins/nativescript-admob
so my AndroidManifest.xml it looks like that:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="10000"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
**<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544/5224354917" />**
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:theme="#style/LaunchScreenTheme">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="#style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
and the browse.component.ts it looks like that:
On the emulator, the app continues to crash,
However, using the nativescript playground (tns preview) the app does not crash but it gives the error: LOG from device Galaxy S9: Error in admob.preloadRewardedVideoAd: TypeError: Cannot read property 'getRewardedVideoAdInstance' of undefin
LOG from device Galaxy S9: admob preloadRewardedVideoAd error: TypeError: Cannot read property 'getRewardedVideoAdInstance' of undefined
import { Component, OnInit } from "#angular/core";
import { RadSideDrawer } from "nativescript-ui-sidedrawer";
import * as app from "tns-core-modules/application";
import * as admob from "nativescript-admob";
#Component({
selector: "Browse",
templateUrl: "./browse.component.html"
})
export class BrowseComponent implements OnInit {
constructor() {
// Use the component constructor to inject providers.
}
ngOnInit(): void {
// Init your component properties here.
admob.preloadRewardedVideoAd({
testing: true,
iosAdPlacementId: "ca-app-pub-XXXXXX/YYYYY2", // add your own
androidAdPlacementId: "ca-app-pub-3940256099942544/5224354917", // add your own
keywords: ["keyword1", "keyword2"], // add keywords for ad targeting
}).then(
() => {
console.log("RewardedVideoAd preloaded");
},
(error) => {
console.log("native-admob preloadRewardedVideoAd error: " + error);
}
)
}
onDrawerButtonTap(): void {
const sideDrawer = <RadSideDrawer>app.getRootView();
sideDrawer.showDrawer();
}
}

ASP.NET Core: develop locally with custom base URL and https

I'm using ASP.NET Core. There are questions/answers on Stackoverflow related to developing with custom URLs already, but my situation seems to be a little different, as I need both https support and a custom base URL. I'm authorizing with a 3rd party with OAuth redirect flow. The 3rd party only supports redirect URLs that are https but not localhost. Right out of the box, Visual Studio 2017 (version 15.7.2) configured https support, which was a nice surprise. By default, my app launches on https://localhost:44348/.
launchSettings.json looks like this:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53837",
"sslPort": 44348
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyProject.Web": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
I've added a host entry to map a custom url to 127.0.0.1
127.0.0.1 app.mysite.local
...but I'm not able to access my site at https://app.mysite.local:44348/. I get a Bad Request - Invalid Hostname error.
I've tried changing this entry in .vs/config/applicationhost.config from:
<binding protocol="https" bindingInformation="*:44348:localhost" />
to
<binding protocol="https" bindingInformation="*:44348:*" />
but then my app won't run at all, even if I run Visual Studio as an Administrator. Visual Studio shows this dialog:
I've even tried using the UseUrls() extension method on IWebHostBuilder:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("https://*:44348/");
}
...but none of those techniques seem to work. Can anyone shed some light on how to get a custom base URL to work on https when developing ASP.NET Core apps?
Have have this running with the updated url but its missing the cert which is probably the next thing to look at. Granted I know this is not the complete answer but I thought it better to provide some help as I don't currently have time to try getting passed the cert issue.
Try changing .vs/config/applicationhost.config to the following (you will need to update the port to the one you are using) so looking at the bindings notice in my config I updated it in two places:
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
<binding protocol="https" bindingInformation="*:44335:app.mysite.local" />
</bindings>
</site>
<site name="WebApplication2" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\benl\source\repos\WebApplication2\WebApplication2" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:63297:localhost" />
<binding protocol="https" bindingInformation="*:44335:app.mysite.local" />
</bindings>
</site>
Additionally I was running VS as an admin. I did experience and IIS error so I did do a restart. App loads on the localhost url and complains about the bad request. So now enter in your url https://app.mysite.local:44335/ (again port change) and it now is running:
The next part you will need to sort a new cert for IIS express as its most likely only been setup for localhost. Link to possibly how to do this
Also this may be of use Link to cert creation / use for localdev

Entity Framework Core Migration for ASP.Net Core Class Library

I've been trying to follow the advice of Ben Cull (http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects), but the database is a little different in that I'm trying to inherit from ASP.NET Core IdentityUser class. I created a new solution containing the default ASP.NET Core Web Application from the VS2015 template (CodeFirstTest). I then added an ASP.NET Core class-library (CodeFirstTest.User) to the solution, which would be the data layer in the application and where I will also be setting up ASP.NET Core Identity.
Following the advice of Ben Cull, I rewrote the CodeFirstTest.User project.json as follows.
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.Extensions.Configuration": "1.0.1",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
}
I also created a Program.cs file containing the entry point, and a User class that inherits from ASP.NET Core IdentityUser as shown below.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace CodeFirstTest.User
{
public class Program
{
public static void Main(string[] args) { }
}
public class User : IdentityUser
{
}
public class UserIdentityDbContext : IdentityDbContext<User>
{
public UserIdentityDbContext(DbContextOptions options)
{
}
}
public class TemporaryDbContextFactory : IDbContextFactory<UserIdentityDbContext>
{
public UserIdentityDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<UserIdentityDbContext>();
builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=UserDb;Trusted_Connection=SqlTruncateException;MultipleActiveResultSets=true");
return new UserIdentityDbContext(builder.Options);
}
}
}
When I use the Project Manager Console to create the initial migration, I received the following errors.
PM> Add-Migration -Name "Initial" -Project "CodeFirstTest.User"
Could not invoke this command with the startup project 'CodeFirstTest'. Check that 'Microsoft.EntityFrameworkCore.Design' has been added to "dependencies" in the startup project and that the version of 'Microsoft.EntityFrameworkCore.Tools' in "tools" and 'Microsoft.EntityFrameworkCore.Design' are the same. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
PM> Add-Migration -Name "Initial" -Project "CodeFirstTest.User"
Unhandled Exception: System.MissingMethodException: Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I corrected the first error, but the second run will cause dotnet to fail with the 'Unhandled Exception' error.
The question...
Am I coding something incorrectly that prevents the migration from executing?
Thank you.
UPDATE: And now this answer appears to be out of date! Turns out 1.1 has removed this feature. After upgrade to 1.1 it no longer works. Odd that this would stop working. Setting up the class library to work like a console application as Ben Cull suggests appears to be the way to handle it when using EF Core 1.1
That blog article is pretty old. Most things that are from before the .Net Core release while still usually useful, need to be taken with a grain of salt.
You no longer have to fake out a console app in the class library. I whipped together a sample identity application where the User and DbContext were in a class library.
The class library project.json looked like this:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
To show the ClassLibrary namespace and the identity schema coming through in the migration.
A few subtle things to note:
Passed the options in the DbContext constructor to the base constructor
WebApplication was the startup project. The default project in the Package Manager Console was the Class Library. This is so that it knows where to find Startup.
The whole example solution I put together has been put up on Github if you want to use it as a baseline.
for core 1.1
after adding the packages with nuget it will not work directly, you will need also to edit the .csproj file like that
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
</ItemGroup>
</Project>
reference: https://www.benday.com/2017/02/14/walkthrough-entity-framework-core-1-1-with-migrations/

Can not delete directory by mask in Gradle

I try to delete directory in 'foo/dir' with name 'public-someHash'. 'SomeHash' was created dynamically (eg 'dsflsdfn') and always new. I tried to use 'fileTree' but directory still present. There is my code:
tasks.create(name: 'delete', type : Delete) {
delete fileTree(dir: 'foo/dir/', include: 'public-*/**')
}
What is wrong with my mask?
UDP: I have similar task in Ant and all works fine:
<target name="delete">
<delete includeemptydirs="true">
<fileset dir="foo/dir/">
<include name="public-*/**"/>
</fileset>
</delete>
</target>
EDIT: Apologies, as original answer was based on a misreading of the question.
Here's one way to do it, but not the most elegant:
task myDelete(type: Delete) {
def files = new HashSet()
new File('foo/dir').eachFile { file ->
if (file.isDirectory() && (file.name ==~ /public-.*/)) {
files << file
}
}
delete files
}

Symfony assetic sass filter via node-sass?

I'm having some difficulties getting an assetic sass filter to work with node-sass instead of the ruby alternative. I have the following configuration in my config.yml file:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
write-to: "%kernel.root_dir%/../web/assets"
read_from: "%kernel.root_dir%/../web/assets"
node: "%%PROGRAMFILES%%\nodejs\\node.exe"
node_paths: ["%%USERPROFILE%%\\AppData\\Roaming\\npm\\node_modules"]
sass: "%%USERPROFILE%%\\AppData\\Roaming\\npm\\node-sass"
ruby: null
filters:
cssrewrite: ~
scss:
output-style: compressed
apply_to: "\.(scss|sass|css)%"
Although this triggers the right node-sass command, I'm not sure the configuration is correct. If I remove ruby: null it tries to run C:\Program Files...\path\to\ruby.exe %%USERPROFILE%%\\AppData\\Roaming\\npm\\node-sass which is totally wrong. But having ruby: null doesn't solve the problem as well, because it sets the wrong arguments (i.e --load-path instead of --include-path) and that messes things as well.
Does anybody know how to set the sass filter with node instead of ruby?
I'd like to share my solution to this issue for anybody out there who might be experiencing it as well.
It appears that the BaseSassFilter is suited to work only with the ruby version. So I decided to create my own filter. Here is my class:
<?php
namespace App\YourBundle\Assetic\Filter;
use Assetic\Asset\AssetInterface;
use Assetic\Exception\FilterException;
use Assetic\Filter\Sass\BaseSassFilter;
use Assetic\Filter\Sass\SassFilter;
/**
* This class is based on Assetic\Filter\Sass\SassFilter and is slightly modified to work with node-sass instead of Ruby.
*/
class NodeSassFilter extends BaseSassFilter
{
const STYLE_NESTED = 'nested';
const STYLE_EXPANDED = 'expanded';
const STYLE_COMPACT = 'compact';
const STYLE_COMPRESSED = 'compressed';
private $sassPath;
private $scss;
private $style;
private $quiet;
private $cacheLocation;
public function __construct($sassPath = '/usr/bin/node-sass')
{
$this->sassPath = $sassPath;
$this->cacheLocation = realpath(sys_get_temp_dir());
}
public function setScss($scss)
{
$this->scss = $scss;
}
public function setStyle($style)
{
$this->style = $style;
}
public function setQuiet($quiet)
{
$this->quiet = $quiet;
}
public function filterLoad(AssetInterface $asset)
{
$sassProcessArgs = array($this->sassPath);
$pb = $this->createProcessBuilder($sassProcessArgs);
if ($dir = $asset->getSourceDirectory()) {
$pb->add('--include-path')->add($dir);
}
if ($this->style) {
$pb->add('--output-style')->add($this->style);
}
if ($this->quiet) {
$pb->add('--quiet');
}
// input
$pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_sass'));
file_put_contents($input, $asset->getContent());
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 !== $code) {
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent($proc->getOutput());
}
public function filterDump(AssetInterface $asset)
{
}
}
Then, in your config.yml you add the following:
assetic:
filters:
nodesass:
bin: "%sass.bin%"
resource: '%kernel.root_dir%/config/filters/nodesass.xml'
style: compressed
apply_to: "\.scss%"
In app/config/filters/nodesass.xml you add the following xml:
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="assetic.filter.nodesass.class">App\YourBundle\Assetic\Filter\NodeSassFilter</parameter>
<parameter key="assetic.filter.nodesass.bin">%assetic.sass.bin%</parameter>
<parameter key="assetic.filter.nodesass.timeout">240</parameter>
<parameter key="assetic.filter.nodesass.style">null</parameter>
<parameter key="assetic.filter.nodesass.load_paths" type="collection" />
</parameters>
<services>
<service id="assetic.filter.nodesass" class="%assetic.filter.nodesass.class%">
<tag name="assetic.filter" alias="nodesass" />
<argument>%assetic.filter.nodesass.bin%</argument>
<call method="setTimeout"><argument>%assetic.filter.nodesass.timeout%</argument></call>
<call method="setStyle"><argument>%assetic.filter.nodesass.style%</argument></call>
<call method="setLoadPaths"><argument>%assetic.filter.nodesass.load_paths%</argument></call>
</service>
</services>
</container>
This should get things working for now.

Resources