You are working in a .net Core or .net Standard codebase and get the error „Missing compiler required member ‚Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create“. In my case it appears when I used the dynamic type. The solution is to load the nuget package Microsoft.CSharp. After you installed it and write a using to your code everything should work as expected.
I developed an Api in Asp.Net Core Web Api. While testing it on my local machine verything works fine. When I deployed it to my Ionos Managed Windows Hosting I got a 405 Http Error on some Endpoints. Analyzing this behaviour showed me that only controller methods with PUT and DELETE annotations throwed the error.
The problem seems to be the WebDav Module of IIS blocking PUT and DELETE requests by default.
Sometimes a webhost wants you to use a proxy to communicate via http with an API for example. If you use Refit in C# with Factory implementation you can use the following code:
services.AddRefitClient()
.ConfigureHttpClient(c => c.BaseAddress = new Uri(Configuration.GetValue("The name of the value in your appsettings.json")))
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
UseProxy = true,
Proxy = new WebProxy("http://yourProxyUrl:yourProxyPort", false),
PreAuthenticate = true,
UseDefaultCredentials = false
});
There are use-cases where you want to start multiple projects of your solution at once in Visual Studio. For example if you’re developing a website in Asp.Net Core MVC getting it’s data of an Asp.Net Core Web API application. You’ll have to do the following steps to set multiple startup projects:
1) Right click on the top node of your solution in the solution explorer.
2) In the context menu choose Properties (Alt + Enter).
3) Expand the „Common Properties“ node, and choose Startup Project.
4) Select the Multiple Startup Projects radio button option and set the appropriate actions.
The way with less clicks is to click on the little arrow on the left side of the start button and choose Define Start Projects or right click on the solution node and choose Define Start Projects.
Some days ago I had a problem while mapping domain objects to DTO by automapper. My environment was an Asp.Net Core 3 Web Api project. I created an own profiles class where I stored my mapping logic. In the startup class I registered the mapper service. When running project my source of type List<Product> should be mapped to List<ProductDTO>. But the API always returned an empty list even if the source was filled correctly.
Updating my dot net core mvc project from version 2.2 to 3.0 I got an error saying „project.assets.json doesn’t have a target for .NETCoreApp,Version=v2.2“. I deleted the mentioned JSON file which was new generated but nothing changed. After searching for my problem in google I found this link https://github.com/dotnet/sdk/issues/1321 where similiar problems were reported. One of the answers was a good one: Delete your publish profile and try again. This worked for me and I hope for many other people out there getting this error.
If want to check which .net core version, sdk’s and runtimes are installed on your machine you can easily check in console by typing:
dotnet --info
You will get a result looking like:
Getting .net core infos in console
Like mentioned in the result you can install another version or sdk by visiting https://aka.ms/dotnet-download and following the instructions or do it directly in visual studio.
There you have to open the project properties and select the targetframework dropdown. You can find an option named install another framework there. By clicking on it the browser opens and you’ll be transfered to https://dotnet.microsoft.com/download/visual-studio-sdks where you can download runtimes and sdk’s.
Wenn in Razor Pages beim Ausführen des Projekts Umlaute nicht richtig angezeigt werden kann das daran liegen, dass die Datei mit dem falschen Encoding gespeichert wurde. Um dieses zu checken kann man einfach in Visual Studio auf Datei -> Speichernunter klicken. Im Speichern Dialog ist neben dem Speichern Button ein kleiner Pfeil nach unten. Wenn man diesen anklickt gibt es die Option Mit Codierung speichern. Dieses wählt man aus.
Im Anschluss wird man gefragt, ob man die vorhandene Datei ersetzen möchte. Dieses bejaht man. Nun öffnet sich ein Dialogfenster (siehe Screenshot) in dem man die Codierung auswählen kann. Unicode (UTF-8 mit Signatur) – Codepage 65001 sollte hier die Wahl sein und diese Auswahl bestätigt man mit OK. Wenn man nun das Projekt erneut startet sollten die Umlaute korrekt dargestellt werden.
Auswahl der Codierung für eine Razor Page Datei im Dialogfenster.
If you want to use a scoped service in a singleton service in a Asp.Net Core MVC project you can’t inject it via constructor injection. You’ll have to create a scope when needed. In my case I needed to use a DbContext service regisered with .AddDbContext as a scoped service in startup.cs into a hosted service.
First you have to create a service inheriting of IHostedService (Microsoft.Extensions.Hosting) with the following code:
public abstract class HostedService : IHostedService
{
// Example untested base class code kindly provided by David Fowler: https://gist.github.com/davidfowl/a7dd5064d9dcf35b6eae1a7953d615e3
private Task _executingTask;
private CancellationTokenSource _cts;
public Task StartAsync(CancellationToken cancellationToken)
{
// Create a linked token so we can trigger cancellation outside of this token's cancellation
_cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
// Store the task we're executing
_executingTask = ExecuteAsync(_cts.Token);
// If the task is completed then return it, otherwise it's running
return _executingTask.IsCompleted ? _executingTask : Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
// Stop called without start
if (_executingTask == null)
{
return;
}
// Signal cancellation to the executing method
_cts.Cancel();
// Wait until the task completes or the stop token triggers
await Task.WhenAny(_executingTask, Task.Delay(-1, cancellationToken));
// Throw if cancellation triggered
cancellationToken.ThrowIfCancellationRequested();
}
// Derived classes should override this and execute a long running method until
// cancellation is requested
protected abstract Task ExecuteAsync(CancellationToken cancellationToken);
}
The following code in the singleton service works for me:
Wir verwenden Cookies, um unsere Website und unseren Service zu optimieren.
Funktional
Immer aktiv
Die technische Speicherung oder der Zugang ist unbedingt erforderlich für den rechtmäßigen Zweck, die Nutzung eines bestimmten Dienstes zu ermöglichen, der vom Teilnehmer oder Nutzer ausdrücklich gewünscht wird, oder für den alleinigen Zweck, die Übertragung einer Nachricht über ein elektronisches Kommunikationsnetz durchzuführen.
Vorlieben
Die technische Speicherung oder der Zugriff ist für den rechtmäßigen Zweck der Speicherung von Präferenzen erforderlich, die nicht vom Abonnenten oder Benutzer angefordert wurden.
Statistiken
Die technische Speicherung oder der Zugriff, der ausschließlich zu statistischen Zwecken erfolgt.Die technische Speicherung oder der Zugriff, der ausschließlich zu anonymen statistischen Zwecken verwendet wird. Ohne eine Vorladung, die freiwillige Zustimmung deines Internetdienstanbieters oder zusätzliche Aufzeichnungen von Dritten können die zu diesem Zweck gespeicherten oder abgerufenen Informationen allein in der Regel nicht dazu verwendet werden, dich zu identifizieren.
Marketing
Die technische Speicherung oder der Zugriff ist erforderlich, um Nutzerprofile zu erstellen, um Werbung zu versenden oder um den Nutzer auf einer Website oder über mehrere Websites hinweg zu ähnlichen Marketingzwecken zu verfolgen.