Replacement of AssemblyBuilder.DefineDynamicAssembly in .NET Core

Add this to your project.json: “dependencies”: { “System.Reflection.Emit”: “4.0.1” }, and use: AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run); AssemblyBuilderAccess.RunAndSave is not supported at the moment – link to source. For new .csproj projects, use: <ItemGroup> <PackageReference Include=”System.Reflection.Emit” Version=”4.3.0″ /> </ItemGroup>

How to get Table Name of mapped entity in Entity Framework Core

Using the Microsoft.EntityFrameworkCore.Relational package in 2.X: var mapping = dbContext.Model.FindEntityType(typeof(YourEntity)).Relational(); var schema = mapping.Schema; var tableName = mapping.TableName; This assumes that dbContext is a instance of class that inherits from DbContext and that you have YourEntity configured there. Note that in EF Core 3.X, [.Relational() provider extensions have been replaced] (https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#provider) with getters and so … Read more

asp-controller and asp-action attributes not working

After a little bit of digging I found that asp-controller and asp-action attributes are called anchor tag helpers, and are part of the Microsoft.AspNetCore.Mvc.TagHelpers namespace Apparently it is an alternative to using Razor. I was able to resolve the issue by creating ‘_ViewImports.cshtml’ and adding the below into the file: @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers Once done … Read more

Is Kestrel using a single thread for processing requests like Node.js?

Updated for ASP.Net Core 2.0. As pointed by poke, the server has been split between hosting and transport, where libuv belongs to the transport layer. The libuv ThreadCount has been moved to its own LibuvTransportOptions and they are set separately in your web host builder with the UseLibuv() ext method: If you check the LibuvTransportOptions … Read more

Return jpeg image from Asp.Net Core WebAPI

Clean solution use FilestreamResult !! [HttpGet] public IActionResult Get() { var image = System.IO.File.OpenRead(“C:\\test\\random_image.jpeg”); return File(image, “image/jpeg”); } Explanation: In ASP.NET Core you have to use the built-in File() method inside the Controller. This will allow you to manually set the content type. Don’t create and return HttpResponseMessage, like you were used to using in … Read more

AddDbContext or AddDbContextPool

The answer is here (under “DbContext pooling”): https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#dbcontext-pooling DbContext is not thread-safe. So you cannot reuse the same DbContext object for multiple queries at the same time (weird things happen). The usual solution for this has been to just create a new DbContext object each time you need one. That’s what AddDbContext does. However, there … Read more

Why does page not update after refresh when .cshtml changes

After Asp.net Core 3.0, Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must: Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package. Update the project’s Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation: services .AddControllersWithViews() .AddRazorRuntimeCompilation(); or services.AddMvc().AddRazorRuntimeCompilation();

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)