.NET Nancy 2 bootstrapper not firing - c#

We have a Nancy Boostrapper class like so (Structure Map):
public class NancyBootstrapper : StructureMapNancyBootstrapper
{
protected override void ConfigureApplicationContainer(IContainer existingContainer)
{
existingContainer.Configure(ConfigureContainer);
}
}
When we run our application, this bootstrapper is found and the code hits ConfigureApplicationContainer(), all works well.
We then upgrade all Nancy packages from 1.4.1 to Nancy 2.
Upon running the application, this bootstrapper code is no longer hit.
We have isolated the issue specifically to the "Nancy.Hosting.Aspnet" package. When all Nancy packages are 2.0, this code is no longer hit. But as soon as we downgrade Nancy.Hosting.Aspnet to 1.4.1, it is successfully hit once again.
We're using the Nancy 2 "ClintEastwood" pre-release.
Has something in Nancy changed so that we can no longer use StructureMap bootstrappers?

Related

Azure Function startup's Configure not being called

I'm trying to create non-static functions in my Azure Function projet in .NET 5 (VS 2022) and the Startup Configure method is not being called.
Here's my start up class
[assembly: FunctionsStartup(typeof(AuthenticationGateway.Functions.Startup))]
namespace AuthenticationGateway.Functions
{
class Startup : FunctionsStartup //public or not, still does not get called.
{
public override void Configure(IFunctionsHostBuilder builder)
{
//break point here never gets hit...
}
}
}
And here's the function in question:
namespace AuthenticationGateway.Functions
{
public class CreationConnection
{
private AuthenticationGatewayContext Context { get; set; }
public CreationConnection(AuthenticationGatewayContext context)
{
Context = context;
}
[Function("CreationConnection")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req,
FunctionContext executionContext)
{
var response = req.CreateResponse(HttpStatusCode.OK);
return response;
}
}
}
I've tried commenting all of the code in Configure just in case it was a problem with it, not working either. Also tried marking the startup class as public too, no go.
Here are the dependencies for the projet in question
They are not the default dependencies the projet has when creating an Azure Function projet but as I tried other solutions to fix the issue, it lead me to plug those in.
Here's what the console is saying when starting the project:
Azure Functions Core Tools Core Tools Version: 3.0.3904 Commit
hash: c345f7140a8f968c5dbc621f8a8374d8e3234206 (64-bit) Function
Runtime Version: 3.3.1.0
Anything I missed ?
EDIT: I have reverted to the following dependencies as the previous ones made it so no functions would be found in the project.
On this page here it says those following dependencies have to be installed:
Microsoft.Azure.Functions.Extensions
Microsoft.NET.Sdk.Functions package version 1.0.28 or later
Microsoft.Extensions.DependencyInjection (currently, only version 3.x and earlier supported)
I have done so, except the last one because it is incompatible with .NET 5 it seems. Also, the project is now unbuildable:
error MSB4062: The "GenerateFunctionMetadata" task could not be loaded from the assembly
I have tried to reproduce the same issue which you got by following the below steps:
Created the Azure Functions (Stack: .Net5-v3) in VS2022.
Before adding Microsoft.Net.Sdk.functions to the project, it was built successfully.
After adding Microsoft.Net.Sdk.functions to the project, it has run to the same issue MSB4062 error as below:
By referencing these SO Thread1 and Thread2, removing Microsoft.Net.Sdk.functions will solve the compile issue.

Does NltkNet the NLTK wrapper class support .NET core web applications or only console applications?

When I try to Initialize the NltkNet object in my dotnet core web application I receive an error saying an assembly is not found or has a different manifest definition than its assembly reference.
The code is fairly simple, it does nothing at all except initialize an NltkNet object when a button is clicked.
public IActionResult Upload()
{
Nltk.Init(new List<string>()
{
#"C:\IronPython27\Lib",
#"C:\IronPython27\Lib\site-packages",
});
return View();
}
I was able to get the exact same code to work in my console application without issue.
Is this a configuration issue on my end or is ASP.NET core MVC web application support not available for NltkNet?
I have discovered that NltkNet does not support dotnet core.

Xamarin Forms +Entity Framework Core + SQLite - Calling migration on production breaks application

First I run the following setup
Xamarin Forms - Entity Framework Core 2.2 - SQLite - Android - DEBUG
And everything works fine. The .db file is generated properly and queries are executed on the database.
Then I prepared the application for production and I changed the DEBUG to RELEASE compiled, and packed into an apk. As installed on the device the application always crashes when calling either Database.Migrate() or Database.EnsureCreated()
The scenario is the same on every application I tried. App runs properly in emulator and on the device being in DEBUG mode. App crashes on every Android device when creating the database.
This is the instantiation of the DbContext
public ItemContext(DbContextOptions<ItemContext> options)
: base(options)
{
//Database.Migrate();
Database.EnsureCreated();
}
This is how the constructor is called
public void Load()
{
string databasePath = DependencyService.Get<ILocalFileStorageService>().GetDatabaseFilePath("ItemSQLite.db");
string connectionString = $"Filename={databasePath}";
DbContextOptions<ItemContext> options = new DbContextOptionsBuilder<ItemContext>()
.UseSqlite(connectionString)
.Options;
dataService = new DataService(new ItemContext(options));
}
This is how I retrieve the filepath on Android.
public string GetDatabaseFilePath(string fileName)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return Path.Combine(path, fileName);
}
When looking on the Android Device Monitor a very long error is displayed
The beginning is
somewhere later there is the EnsureCreated method listed
The Question: Why is this happening and how to make the application runnable on production?
Do you have linking enabled in your release build configuration? According to this https://github.com/aspnet/EntityFrameworkCore/issues/10963 the compiler requires hints to not link assemblies accessed through reflection internally in EF Core. You can try switching to "Link sdk assemblies only" to see if that fixes the issue. If it does then you will need to identify the assemblies and mark them to be preserved. There's some more info on that here: Xamarin iOS Linker Issue and here: https://learn.microsoft.com/en-us/xamarin/android/deploy-test/linker#linkskip.
I can't personally test at the moment but I think putting [assembly: Preserve (typeof (System.Linq.Queryable), AllMembers = true)] (or whatever assembly might be causing it) in your App.xaml.cs should do it.

Run migrations in self-contained applications

I have created a self-contained application with dotnet:
dotnet publish -c release
The deployment package contains .net core runtime itself - so if somebody wants to use app - doesn't need to install .net core runtimes separately.
But my question is... is it possible to attach dotnet.exe to deployment package?
F.e. - my web app expectes migrated database:
dotnet ef database update
This command cannot be run from self-contained application (no direct access to dotnet.exe).
What are scenarios in this case? How should I handle it?
The solution is to add it on your Startup.cs like that
public void Configure(
IApplicationBuilder app,
// ... various other parameters that you may have and below add the context that you want to run Migrations
YourDbContext db1)
{
{
// run the migrations before other code
db1.Database.Migrate();
// ...
}
PS. it is a bit weird, but you add it on the Configure method signature as an extra parameter and it works (I guess it instantiates the dbContext object automatically and calls the method). It worked for me.

SignalR/EPiServer "/signalr/hubs?" 404 on IIS when trying to use Live Monitor

I'm trying to get Live Monitor with EPiServer to work.
However, when the page loads,it returns a 302 on /signalr/hubs?, which is just a redirect to our 404 page.
See this screenshot:
This is my startup class:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(MyWebApp.Web.Plumbing.OwinStartup))]
namespace MyWebApp.Web.Plumbing
{
public class OwinStartup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I have installed these NuGet packages:
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.AspNet.SignalR.Core
Microsoft.AspNet.SignalR.SystemWeb
EPiServer.LiveMonitor
I don't have any experience working with this; can anyone help?
I did a reinstall of the EPiServer.LiveMonitor package, which pulled all dependecies, including signalr. After that I set up live monitor again, and then tried to load the page. I still got the same result, but this time totally emptying the asp.net cache worked, as oppsed to last time.

Categories

Resources