Code to Live
548 FOLLOWERS
Code to Live blog talks about .NET Core, SQL Server, Visual Studio IDE, Entity Framework, Angular, and more on their blog. Stay tuned to read informative articles on programming.
Code to Live
6M ago
Are you the one stuck with the below issue?
Unable to find the PowerShell in the GitHub codespaces terminal.
PowerShell is not available after installing the extension in the GitHub codespaces.
Not comfortable with Bash.
See the below image, the PowerShell option is missing in the CodeSpaces terminal and you're going to learn how to enable it now.
Fig 1. Github CodeSpaces - PowerShell missing
No worries. You can enable the PowerShell in the GitHub codespaces because many of us have done it already.
1. Go to your GitHub repository Fig 2. Github repository - dev container2. Ope ..read more
Code to Live
7M ago
There are various reasons cause the swagger to fail to load the API definition and you will get the error shared in the below screenshot. The below are the possible reasons,
Swagger misconfiguration
Controller methods without HTTP verbs (HttpGet, HttpPost etc.)
Same class name etc…
Fig 1. Failed to load definition error in Swagger
Solution:
The Swagger can be launched by adding the ‘/swagger’ after your API URL which doesn’t show the error details causing the Swagger to fail to load.
http://localhost:{PortNo}/swagger/index.html
If you navigate to ‘swagger/v1/swagger.json’ page you w ..read more
Code to Live
7M ago
1. What is swagger?
Swagger is an open-source set of rules and specifications. It is used for API documentation and testing the API endpoints. Swagger UI generates documentation based on the Swagger specification and provides an interactive UI for testing APIs and experimenting with different parameters and options.
2. How to enable the swagger in .NET Core or .NET 7/8?
Go to the startup.cs file or program.cs file
Add the Swagger services under the ‘ConfigureServices’ method.
Add the following middleware under the ‘Configure’ method i.e, Swagger and Swagger UI.
Build and run the API.
Go to ht ..read more
Code to Live
7M ago
Problem statement:
You may receive the following error when you try to open the New Query window in the Microsoft SQL Server Management Studio connected to the Microsoft SQL Server instance.
Fig 1. The visual Studio component cache is out of date, please restart Visual Studio.
Solution:
Option 1:
Open Run or Press the Windows key + R.
Type %temp%
Delete all the files from the temp folder.
You can open the New Query window in the SSMS, which will open without any issues.
Option 2:
Run the ‘Disk cleanup’.
Select the C:\ drive.
Make sure the ‘Temporary Files’ checkbox is selected.
Clic ..read more
Code to Live
7M ago
1. Problem statement
‘IHeaderDictionary’ does not contain a definition for ‘Referrer’ and no accessible extension method ‘Referrer’ accepting a first argument of type ‘IHeaderDictionary’ could be found (are you missing a using directive or an assembly reference?
Referrer is missing in the ‘IHeaderDictionary’ when using the .NET Core or .NET projects.
2. Context
A request header is an HTTP header that can be used in the HTTP request to pass additional information. The header can be sent from the client, and the same can be read from the server to retrieve the information.
The way of reading the ..read more
Code to Live
7M ago
INDEX
Context
Static files
WWWroot folder
Enable the static files in the ASP.NET Core project
Reading static files
1. Context
Using static files in an ASP.NET Core project from the wwwroot folder using the IwebHostEnvironment’ interface inside the controller or service
2. Static file
The static files are the assets of the project, like HTML, CSS, JS, images, Excel, etc.
3. WWWroot folder
The static files are stored in the wwwroot folder in the project directory. The web root folder, i.e., wwwroot is the base path of the public and static resource files like Javascript (.JS), stylesheet (.css ..read more
Code to Live
7M ago
INDEX
Context
Using the IHttpContextAccessor
Accessing HttpContext via Dependency Injection
Accessing HttpContext via Dependency Injection in a static class
Considerations
1. Context
In ASP.NET Core, the HTTP context cannot be accessed directly in the class library because it is a transient object that is available in the context of an HTTP request.
2. Using the IHttpContextAccessor
You can use the HTTPContext in a class library by injecting the IHttpContextAccessor to your class via the dependency injection from your startup class. Once you have injected the IHttpContextAccessor service int ..read more
Code to Live
7M ago
INDEX
What is a recursion?
Simple recursion
Example: Power
Example: Factorial
Download samples
1. What is a recursion?
Recursion is the process of calling the same function repeatedly until it meets the break condition. It is similar to the loop in that it will call the same function as the loop to iterate the counter and end the iteration after it meets the condition.
function x(){
....
x();
}
2. Simple recursion
Simple recursion to demonstrate recursion in C#. It will iterate the number by decrementing a number and break the condition once it reaches the number = 0.
2.1 Code
using S ..read more
Code to Live
7M ago
INDEX
What is an array?
What is a multidimensional array?
2d and 3d arrays
Examples
1. What is an Array?
Arrays are used to store multiple values in a single variable instead of in separate variables. It can be single dimensional, multidimensional, or jagged.
2. What is a multidimensional array?
It is an array of arrays and has more than one dimension. The most common is a two-dimensional array, i.e., 2D.
3. What is 2D?
A 2D array is a matrix that consists of rows and columns.
3.1 2D array with an int data type without specifying the index
int[,] arrayNumbers = new int[,] { {1, 2 ..read more
Code to Live
9M ago
Problem statement:
You may receive the following error when you try to open the New Query window in the Microsoft SQL Server Management Studio connected to the Microsoft SQL Server instance.
Fig 1. The visual Studio component cache is out of date, please restart Visual Studio.
Solution:
Option 1:
Open Run or Press the Windows key + R.
Type %temp%
Delete all the files from the temp folder.
You can open the New Query window in the SSMS, which will open without any issues.
Option 2:
Run the ‘Disk cleanup’.
Select the C:\ drive.
Make sure the ‘Temporary Files’ checkbox is selected.
Clic ..read more