Tech Point Fundamentals

Sunday, September 4, 2022

.Net Core Interview Questions and Answers - Part 01

ASP.Net Core Interview Questions and Answers - Part 01

AspDotNetCoreInterviewQuestionsAndAnswers

Are you preparing for the .Net Core Interview? If yes, then you are at the right place. This is the ASP.Net Core Interview Questions and Answers article series. Here we will see the Top 150+ .Net Core Interview Questions with Answers. 

Please visit our YouTube Channel for Interviews and other videos by below link:




Please read the complete Design Pattern, C#, MVC, WebAPI, and .Net Framework Interview Questions and Answers article series here.




Introduction


This is the 1st part of the .Net Core Interview Questions and Answers article series. Each part contains ten .Net Core Interview Questions. Please read all the .Net Interview Questions list here.






ASP.Net Core Interview Questions and Answers - Part 01


Q001. What is the .Net Framework?

The .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows. The.NET Framework is the original implementation of .NET. It supports running websites, services, desktop apps, and more on Windows.

A .NET Framework is a managed execution environment for Windows that provides a variety of services to its running apps. A computer code written using .NET Framework is called "Managed Code".

Microsoft began developing .NET Framework in the late 1990s and by early 2000, the first beta versions of .NET 1.0 were released. In April 2019, Microsoft released .NET Framework 4.8, as the last version of the .Net framework.



Components of .Net Framework:

Common Language Runtime(CLR): 

CLR serves as the execution engine of the .NET Framework and offers many services such as memory management, type safety, exception handling, garbage collection, security, and thread management. 

A CLR is also a virtual machine that not only executes apps but also generates and compiles code on the fly using a JIT compiler. All programs written for .NET Framework are executed by the CLR.

The CLR implementation for .NET Framework is Windows only. But the CLR implementation for .NET 5 and later versions is known as the Core CLR which is built from the same code base as the .NET Framework CLR.



Common Language Infrastructure(CLI): It provides a language-neutral platform for application development and execution.

Framework Class Library (FCL): FCL provides the user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and network communications. 

FCL refers to the entire class library that ships with .NET Framework. It includes all the required libraries, including BCL, Windows Forms, ASP.NET, Windows Presentation Foundation(WPF), Windows Communication Foundation (WCF), and Windows Workflow Foundation (WWF). 



Base Class Library (BCL): 

BCL is a set of libraries that comprise the System.* (and to a limited extent Microsoft.* as well) namespaces. The BCL is a general-purpose, lower-level framework that higher-level application frameworks, such as ASP.NET Core, build on.

BCL includes a small subset of the entire class library and is the core set of classes that serve as the basic API of CLR. For .NET Framework, most classes considered to be part of BCL reside in mscorlib.dll, System.dll, and System.Core.dll.

The source code of the BCL for .NET 5 (and .NET Core) and later versions are contained in the .NET runtime repository. Most of these BCL APIs are also available in .NET Framework, so you can think of this source code as a fork of the .NET Framework BCL source code.

Common Type System (CTS): It defines all possible data types and programming constructs supported by CLR and how they may or may not interact conforming to CLI specification

Code Access Security (CAS): .NET Framework has its own security mechanism called CAS and validation and verification.



Common Intermediate Language Code (IL Code) or MSIL Code:  

Higher-level .NET languages, such as C#, compile down to a hardware-agnostic instruction set, which is called Intermediate Language (IL). IL is sometimes referred to as MSIL (Microsoft IL) or CIL (Common IL) as well.

Programs written for .NET Framework are compiled into Common Intermediate Language code (CIL), as opposed to being directly compiled into machine code. 

JIT Compiler:  It is a Just-in-time compiler. JIT compiler converts the CIL code into machine code for execution by CLR. 

Similar to the AOT compiler (Ahead-of-time compiler) this compiler translates IL to machine code that the processor understands. Unlike AOT, JIT compilation happens on demand and is performed on the same machine that the code needs to run on. 



Since JIT compilation occurs during the execution of the application, compile time is part of the run time, A JIT knows the actual hardware on which it has to run.

On the other hand in contrast to JIT compilation, AOT compilation happens before the application is executed and is usually performed on a different machine.

dot-net-framework
Source: Microsoft.Com




Features of .Net Framework:

Language Interoperability: Each language can use code written in other languages supported by the .Net Framework.

Language Independence:  Because of CTS the .NET Framework supports the exchange of types and object instances between libraries and applications written using any conforming .NET language.

Type Safety: CTS and the CLR used in .NET Framework enforce type safety by preventing wring casting, wrong method invocations, and memory size issues when accessing an object.



Memory Management and Garbage Collection: The .NET Framework includes a garbage collector (GC) which runs periodically, on a separate thread from the application's thread, that enumerates all the unusable objects and reclaims the memory allocated to them. 

It is a non-deterministic, compacting, mark-and-sweep garbage collector. GC runs only when a set amount of memory has been used or there is enough pressure for memory on the System Performance.

Security: .NET Framework has its own security mechanism with two general features: Code Access Security (CAS), and validation and verification.

Version Compatibility: With rare exceptions, apps that are developed by using a particular version of the .NET Framework run without modification on a later version.

Side-by-side execution: .NET Framework helps resolve version conflicts by allowing multiple versions of the common language runtime to exist on the same computer. This means that multiple versions of apps can coexist and that an app can run on the version of the .NET Framework with which it was built. 




Q002. What is .NET Standard?  What are the different versions of the .Net Standards?

The .NET Standard is the set of APIs that is available on all .NET implementations. The motivation behind .NET Standard was to establish greater uniformity in the .NET ecosystem. .NET Standard is a set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation.

But the .NET 5 and later versions adopt a different approach to establishing uniformity that eliminates the need for .NET Standard in most scenarios.

The .NET Standard solves the code sharing problem for .NET applications across all platforms by bringing all the APIs that you expect and love across the environments that you need: desktop applications, mobile apps & games, and cloud services.


There are multiple versions of the .Net Standard and each new version adds more APIs. When a library is built against a certain version of the .NET Standard, it can run on any .NET implementation that implements that version of the .NET Standard (or higher).
Targeting a higher version of the .NET Standard allows a library to use more APIs but means it can only be used on more recent versions of the . NET. Targeting a lower version reduces the available APIs but means the library can run in more places.

dotnet-standard-history




Q003. What are the different versions of the .Net Framework?

In April 2019, Microsft has release the last version of the .Net Framework 4.8. After that, no new .Net version will be released as specified by Microsoft.

Major Features released along with the most common Framework Versions:


dotnet-framework-major-release
Source: Wikipedia



Here is the complete .Net Framework version release history:

dotnet-framework-versions









Q004. What is .NET Core?

The .Net Core is a cross-platform version of .NET, that supports almost all things that .NET supported (except things like WPF, Windows Forms, Web Forms, and Active Directory). It is a leaner, faster, and improved version of .NET.

On November 12, 2014, Microsoft announced .NET Core, in an effort to include cross-platform support for .NET, including Linux and macOS. The .NET Core 1.0 was released on June 27, 2016, along with Microsoft Visual Studio 2015 Update 3, which enables .NET Core development.

It includes a small runtime that is built from the same codebase as the .NET Framework CLR. The .NET Core runtime includes the same GC and JIT (RyuJIT) but doesn’t include features like Application Domains or Code Access Security. The runtime is delivered via NuGet, as part of the ASP.NET Core package.

The .NET Core also includes the base class libraries. These libraries are largely the same code as the .NET Framework class libraries but they have been refactored into smaller parts(removal of dependencies) to enable shipping a smaller set of libraries. These libraries are shipped as System.* NuGet packages on NuGet.org.




Q005. What are the different versions of .Net Core?

Every Microsoft product has a lifecycle. The lifecycle begins when a product is released and ends when it's no longer supported. So the same is true for the .Net Core as well:  

dotnet-core-versions




Q006. What are the advantages of .NET Core?  Why .Net Core should be preferred?

ASP.NET Core is an open-source, cross-platform framework for building modern, cloud-based web apps on Windows, macOS, or Linux.

1. Open Source: 

It is an open-source framework to build web applications. The .NET Core platform is open source, using MIT and Apache 2 licenses. 

All .NET source codes and documentation are freely available for download and contribution. This results in faster software releases, enormous support, and usage of the latest tools in development. 

2. Cross-Platform:

The .Net Core application can run on different platforms like Windows, macOS,  Linux, etc. It can support application development on different platforms such as Windows, Linux, Mac, etc as well. 

Also, the deployment is supported on multiple platforms through containerization(Docker, Kubernetes, Service Fabric). This makes .NET completely portable and runnable on different platforms.



3. High Performance:

The .Net Core is lightweight and provides high performance compared to the .Net Framework. With every new release of the .NET core, the performance is improved for the benefit of users. The new Kestrel web server was redesigned from the ground up to take advantage of asynchronous programming models, and be much more lightweight, and fast.

4. Testing:

.Net Core is architected for testability.

5. Flexibility:

The .Net Core provides the flexibility to use any database and infrastructure as per choice. It also provides flexible deployment. You can deploy the .Net core application to on-premises or to the cloud.

6. Cloud-ready and Self-Hosting: 

It provides a cloud-ready environment configuration system and the ability to host in IIS or self-host.



7. Built-In Dependency Injection:

The .Net Core has a built-in dependency Injection feature.

8. Microservices and Containers Support:

Microservices architecture is supported in .NET Core, which allows cross-platform services to work with .NET Core including services developed with .NET Framework, Java, Ruby, or others.

.NET Core’s modularity, lightweight, and flexibility make it easier to deploy .NET Core apps into containers. Containers contain an app as well as all configuration files and dependencies into a single, small, and independently deployable unit of software. Containers can be deployed on any platform, cloud, Linux, and Windows. .NET Core works well with both Docker and Azure Kubernetes Service.

9. CLI Tools:

.NET Core includes Command-line interface tools for development and continuous integration.




Q007. What are the new features of .Net Core?


Unified MVC & Web API frameworks: 

With ASP.NET Core, MVC and Web API have been merged together. There was always a lot of overlap between the two frameworks. MVC could always return JSON data instead of HTML. Combining them was a good move and simplified development.

Razor Page Support:

With ASP.NET Core we also have the new Razor Pages. They extend the MVC framework to allow encapsulating the controller and model aspects of a page together with two-way binding. They are sort of a replacement for WebForms while using the familiar Razor syntax.

New Kestrel Web Server:

Kestrel is the new web server introduced in .Net Core. Kestrel is an event-driven, Asynchronous I/O-based web server for hosting web applications.



Asynchronous Programming via async and await:

ASP.NET core has excellent support for utilizing asynchronous programming patterns. One of the reasons ASP.NET Core is faster is its extensive use of asynchronous patterns within the new MVC and Kestrel frameworks.

Multiple environments and development mode:

It allows you to easily differentiate parts of your code for their behavior in development, staging, production, etc. There was no standard way to do this before ASP.NET Core.

Environments are perfect for using different CSS or Javascript files. Use your CDN in production, but local files during development.



WebSockets & SignalR: 

ASP.NET Core has support for WebSockets and SignalR. This can be used to persist long-running connections and communicate back and forth with the browser. SignalR is a full framework that is also available which makes it easy to handle common scenarios.

Self Hosting:

Sometimes we need to make a web application that will be deployed onto a desktop and not a server running IIS. You can create a self-hosted ASP.NET web application in several different ways. In .NET 4.5 you could accomplish it by using Owin, Nancy, or WCF. For Prefix, we use ASP.NET Web API with Owin.

With ASP.NET Core, you can also use the standard Kestrel web server. Actually, your web application is essentially a console application in the .Net Core. IIS just sits in front of it as a reverse proxy. This means that you can also deploy your app only with kestrel for non-server-based use cases, like Prefix.



Extensible Output Caching:

This feature allows ASP.NET to cache the output generated by a page and serve this cached content for future requests. It stores the data that is not updated frequently and outputs that specific data from a cached location.

ASP.NET makes it easy to specify how long any request should be cached via common HTTP headers. It also has support for caching output within the memory on your web server itself. You can even use Redis or other providers to handle your output caching.

Swagger OpenAPI Support:

ASP.NET has historically provided built-in functionality that is pretty similar for SOAP web services created with WCF. If you are using Web API or MVC for RESTful APIs, you definitely want to use Swagger.



Increased Security:

The .Net Core offers a wide range of security features. From authentication and authorization mechanism to data protection and threats prevention, .Net Core has all you need. For example, Data Protection API and Azure Key Vault providers may use security features to guard statistics and generate keys.

Middleware Service for HTTP Pipeline:

The .Net Core introduced the middleware concept to inject anything in the pipeline. Before this .Net Core, there was no option to alter the request pipeline.

New Health Checks API:

The ASP.NET Core 2 new features consist of a set of libraries defining an abstraction and an IHealthCheck service, as well as a middleware. 



Q08. What are the key changes in .NET Core compared to the .NET Framework?

No web.config files: In .Net Core the web. config files are removed. Instead, the .Net core is using appsettings.json files for all the configuration-related settings.

No Global.asax file: There is no Global.asax file at all in the .Net core. We have Startup.cs file which is used to set up Middleware and services for DI Container.

No ASP.Net Web Forms: WebForms are removed from .Net Core completely. Instead of Web Forms, we can use Razor Pages to develop apps in .NET Core.

No Windows Workflow Foundation(WWF)WWF is also removed from .Net Core completely.

No ADO.Net Data Services: ADO.Net is removed from .Net Core completely.

New wwwroot folder: There is a new folder in .NET Core projects called wwwroot. This folder contains the static files that are to be transferred to the user such as the HTML/CSS and image files.




Q009. What are discontinued Technologies in .NET Core? What are the things which are removed from .Net Core?

Reflection:

The Reflection API has changed a lot in .NET Core. As with WinRT, it has been bifurcated into a lightweight version and a more expensive version. An extension method called GetTypeInfo exposes the rest of the information that you would normally get from the Type object. The TypeInfo class isn’t as rich as the original.

The reflection has been converted into a lightweight version. An extension method called GetTypeInfo exposes information that you normally retrieve from the Type object. However, it is not as detailed as the original.

App Domains:

AppDomains isolate apps from each other. They require runtime support and are costly. Microsoft recommends using separate processes or containers as an alternative.

App Domains are implemented by CoreCLR, but not .NET Native. For dynamic loading of assemblies, Microsoft recommends the new AssemblyLoadContext class.”



Remoting:

.NET Remoting created several issues in its architectural design. Thus Microsoft has no plans to include Remoting in .NET Core.

These days, communication between .NET applications on the same machine it has largely been replaced with WCF, or for higher performance, pipes or memory-mapped files. Across machines, Microsoft recommends “a low-overhead plain text protocol such as HTTP”. 

Binary Serialization:

Most of the serializers such as data contract serialization, XML serialization, JSON.NET, and protobuf-net will be supported in .NET Core. The major exception is binary serialization as it is not supported in the .Net core.

Sandboxing:

In theory sandboxing is a great idea; it allows for the execution of partially trusted code in a secure manner. In practice, it is very difficult to get right and the slightest mistake leads to a security vulnerability.

The recommended alternative is to spawn separate processes that run under a user account with restricted permissions. That way the runtime doesn’t need to duplicate the often expensive permission checks the OS is already running.




Q010. Does real-time application support by .Net Core?

Yes. Asp.net's core SignalR is an open-source library that gives real-time web functionality to the application.



Q011. What are .Net 5 or .Net 6? How they are different from .Net Core?

.Net 5 is one of the major releases of the Microsoft .Net Core family after .Net Core 3.1.  It is also .Net core supported but the word "core" is removed in the .Net 5. 

It has all the features of .Net core 3.1 and much more which are introduced in .Net 5. The .Net 5 is a unified platform to build any type of .Net application with a single Base class library.



So why did Microsoft skip ".Net 4" and give the name ".Net 5"? 

Well, there is already we have “.Net 4 X” (.Net Framework 4.8) and Microsoft don’t want to confuse the user by giving a similar name. Though the .Net 4.x does not support the .Net core feature at all. 

Since Microsoft has already said that the .Net Framework 4.8 is the last version and there will not be any release further, so keep the .Net naming convention, as usual, they provide the name .Net 5. Similarly .Net 6 is released as well and .Net 7 (Nov 2022) and .Net 8 (Nov 2023) are projected for future release.

By doing so there will be just one .NET going forward, and you will be able to use it to target Windows, Linux, macOS, iOS, Android, tvOS, watchOS and WebAssembly, and more.



.NET 5 vs .Net Framework:

.NET 5 doesn't replace .NET Framework. .NET 5 and later versions are the main implementation of .NET going forward but .NET Framework 4.x is still supported. 

There are no plans to port Web Forms and Windows Workflow Foundation(WWF) technologies from .NET Framework to .NET 5, but there are alternatives in .NET 5 which you can use. For Web Forms, you can use ASP.NET Core Blazor or Razor Pages and for Windows Workflow you can use Elsa-Workflows as an alternative.

Visual Studio Version for .Net 5:

For .Net 5 we have to use Visual Studio 2019 ( V 16.9 or higher). Please note that it will not work with Visual Studio 2017.



C# Version for .Net 5:

.Net 5 is introduced with C# 9.0. C# 9.0 has many new features in the C# language like Records, Top Level statement, Relational Pattern matching, functional Pointer, etc.

dotnet5
Source: devblogs.microsoft.com



.Net 5 Features: .Net 5 is a single product that has the following capabilities:

  1.        Window Desktop application
  2. Cross-Platform Console application
  3. Cloud Services
  4. Websites
  5. Universal Window Platform (UWF)
  6. WPF (Windows Presentation Foundation)
  7. DataScience
  8. Machine learning
  9. Mobile and IOS devices




Q012. What is Mono Framework? What is the difference between Mono and .Net Framework?

Mono is an open-source, cross-platform .NET implementation that is mainly used when a small runtime is required. It is the runtime that powers Xamarin applications on Android, Mac, iOS, tvOS, and watchOS and is focused primarily on apps that require a small footprint. 

It supports all of the currently published .NET Standard versions. Mono provides an open-source distribution of the Silverlight API named Moonlight. The browser that runs under Linux can host and run Silverlight web applications. 



Mono is an open-source implementation of Microsofts .NET Framework that allows developers to execute .NET-centric applications on other platforms such Mac and Linux. Using such open-source implementations of .NET you can create, compile and execute .NET assemblies on operating systems other than the Microsoft platform.

Historically, Mono implemented the larger API of the .NET Framework and emulated some of the most popular capabilities on Unix. It is sometimes used to run .NET applications that rely on those capabilities on Unix.

Mono is typically used with a just-in-time compiler, but it also features a full static compiler (ahead-of-time compilation) that is used on platforms like iOS.



Use of Mono:

  1. Mobile App Development
  2. Game development
  3. Multi-platform desktop applications
  4. Compiled code inside the browser



Mono vs .Net Core and .Net Framework:

Mono is way older than .NET Core. .NET Core can run on Windows, Linux and Mac, while .NET Framework could only run on Windows. However, the ability to run .NET code on multiple operating systems isn’t new. We had it for years since the release of mono.

Unlike .NET Core, which natively only allows you to build console apps and web applications, mono allows you to build many application types available in .NET Framework, including GUI-enabled desktop apps. 

The mono can do everything that .NET Core can while .NET Core can only do some of the things that mono can. But in reality, each of these programming platforms has its place. There are scenarios where .NET Core is a way better choice than mono, despite its limitations.

Please read more here.











To Be Continued Part-02...


Recommended Articles






Thanks for visiting this page. Please follow and join us on LinkedInFacebookTelegramQuoraYouTubeTwitterPinterestTumbler, and VK for regular updates.

    

No comments:

Post a Comment

Please do not enter any HTML. JavaScript or spam link in the comment box.