12 Online C# Tutorials For 2018

Are you a beginner developer or someone who’s keen to learn programming languages? To mention, C# is great for learning. Unlike C++, for example, C# provides automatic memory management, and it also offers solid Type Safety in comparison to JavaScript and node.js. C# has huge libraries of base class; the .NET framework has several hundreds of libraries to work with the file system, manage security, and much more.

12 Online C# Tutorials For 2018

With the release of .NET Core, it appears that C# and .NET Core would be in a huge demand in 2018.

Whether you are learning C# for the first time or enhancing your C# expertise, here we share with you 12 best tutorials for both the beginners and experienced programmers to enrich their knowledge.

12 of the Best C# Tutorials

1. Lynda.com

Their topics include core language elements like data types, variables, and constants. There are 5 challenge videos which let you test yourself, along with another 5 videos with explained answers.

Key Topics:

To work with loops

To builds functions

To catch errors

To manage resources with t garbage collector

2. C# Station

They have a set of lessons for a beginner to intermediate-level developers.

Key Topics:

Expressions, Types, and Variables

Namespaces

Overview of Classes

Indexers and Attributes

To work with Nullable types

3. Tutorials Teacher

This site features free online tutorials on web technology for the beginners and professionals alike. In addition to C#, they teach ASP.NET MVC, LINQ, jQuery, AngularJS, JavaScript, or Node.js.

Key Topics:

Data types, classes, and variables

Switches and loops

Strings and arrays

Stream I/O

4. Deccansoft

Every concept is explained in details using different walkthroughs and practical methods. It is recommended to have a practical knowledge of any one programming language before you go for this course.

Key Topics:

.NET Framework

Common Language Runtime concepts

To build a standard GUI for Windows-based applications with the use of WinForms.

5. edX

This tutorial originates from edX, an online educational services provider which offers some courses to top universities and colleges. This is not a starter’s course and needs you to have a prior understanding of the programming language.

Key Topics:

C# syntax

Fundamentals of C# language

Object-oriented programming

Overview of .NET Framework

6. Udemy

This happens to be one of the largest online educational platforms with thousands of courses. There are many video tutorials on C# programming, but the best ones aren’t free and charge a reasonable fee.

Key Topics:

Loops, arrays, and structures

Coding beginner projects

To make the right approach

7. LearnCS.org

A free online tutorial for C#; the website is dedicated exclusively to teaching C#.

Key Topics:

Variables and types

Strings, and loops

Methods

Classes and class properties

8. Microsoft Virtual Academy

This C# tutorial offers 24 practical and easy episodes. Besides the fundamentals of C#, this course also covers the tools, tips to write code, debug features, explore customizations, and much more.

Key Topics:

To create and understand C# program

Understand Data types and Variables

Understand Arrays

Work with Strings

Learn to work with Date and Time data

9. Abbot – C# Tutorial

They have tutorials which cover the basics like loops, strings, and arrays and then offers more complicated stuff like delegates, namespaces, and collections.

Key Topics:

Data types

Lexical structure

Strings

Flow control

Delegates

Namespaces

Collections

10. Channel 9

With their “Jump Start” program they provide every topic with examples.

Key Topics:

Introduction to oriented programming

Basics of a managed language

Why C# is best for OOP

C# Syntax

11. SoloLearn

Their tutorials are fun and teach C# concepts through short interactive texts, games, and quizzes. The instructors offer a hands-on approach and that is the best way to learn codes and practicing them.

Key topics:

Basic concepts like variables, printing, and arithmetic operators

Loops and methods

Arrays and strings

Inheritance, polymorphism, and generics

12. Microsoft – Getting started with C#

This is a nice little tutorial from Microsoft and is unique and tailored. You can select your degree of difficulty before you begin with selecting if you are a beginner or experienced.

Key Topics:

Write your first hello world program

Strings, loops, dates, and times

Arrays, collections, and calling methods

Namespaces

Test your code and troubleshooting

Besides the above mentions, there are some other websites offering C# courses online like Coursera – Beginning Game Programming with C#, 26. Certification Guru – C# .NET Programming, Complete C# Tutorial just to name a few.

Once you’ve become an expert at C#, you can need to check out other resources with an advanced tutorial.

With this, we conclude.

Keep coding!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support. We give a well-structured program for the best Dot Net Course. Among many reputed institutes of dot net training and placement in Pune.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

How Can .NET Core 2.0 Act As Saviour When there is Dot NET Core DLL Hell

If you know that .NET came with a promise, about 15 years ago to eliminate DLL hell. It was then a big issue to register COM DLL files. And today with mixing, NET Standard, .NET Core and .NET Framework projects have created a new DLL hell.

Can .NET Core 2.0 Act As Saviour When there is Dot NET Core DLL Hell

Here let’s discuss a DLL hell problem.

Suppose there is a simple NetStandard library with some simple classes in it that are used by an ASP.NET Core MVC app and a .NET Framework console application.

There is also System.IO 4.3.0, the latest version.

Other Class Library

In a console app, there is a bunch of classes and business logic. And it is kept in a separate class library. This .NET Framework library also references the CoreLibrary project which is.NETStandard 1.5. And the problem starts, where there are several wonderful messages like this for basic system DLLs.

2> Consider app.config to remap of assembly “System.IO, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” from Version “4.1.1.0” [] to Version “4.1.2.0” [C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\\net461\ref\System.IO.dll] to solve conflict and get rid of warning.

2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2099,5): warning MSB3836: The explicit binding redirect on “System.IO, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” conflicts with an auto-generated binding re-direct. You need to remove it from the application configuration file or disable autogenerated binding redirects. The build will replace it with: “<bindingRedirect oldVersion=”0.0.0.0-4.1.2.0″ newVersion=”4.1.2.0″ xmlns=”urn: schemas-Microsoft-com:asm.v1″ />”.

DLL Version Hell

The .NETStandard class library uses System.IO 4.3.0, and so also the Framework class library.

<Reference Include=”System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL”>

<HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>

</Reference>

Then… why the DLL hell there are errors about 4.1.1 and 4.1.2?

It could be that the System.IO 4.3.0 package has different version DLLs in it? You need to recheck. And on looking into the System.IO.dll that gets copied to the bin folder after a build… it says 4.6.24705.1, just like the one in “..\packages\System.IO.4.3.0\lib\net462\System.IO.dll”.

And this is a real cruel deal. Who’s on first? What’s on second?

Why there are 4 Versions of the Same DLL/Package?

Let’s recap; there were versions 4.1.1, 4.1.2, 4.3.0, and 4.6.24705.1. Except, the only one which is actually seen is v4.6 stuck in a v4.3 folder. But why it shows 4.1.1 and 4.1.2 build errors.

Does it make any sense?

Why the .NET team has a v4.6 dll in a v4.3 NuGet package which is really v4.1.1.

It could be the effect of mixing.NETStandard and .NET Framework projects together are the problem.

How .NET Core 2.0 helps?

With the emergence of .NET Core 2.0, you need to switch all the projects. Initially, you were made to use full .NET Framework due to a few NuGet packages that were unavailable for NetStandard.

The false support for .NET Framework packages from a .NET Core application seems an easy solution.

Summary

With different projects that reference each other with conflicts in dependencies, it becomes complicated. The complexity of working with.NET Framework, netcoreapp, and.NETStandard all together is really complicated.

We can hope that .NET Core 2.0 solves the current set of issues.

With this, we conclude. This blog is an adaptation of a blog in Stackify. Keep coding!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support. We give a well-structured program for the best Dot Net Course. Among many reputed institutes in Pune, CRB Tech has created a niche for itself.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Why .NET Core and C# Are The Next Programming Languages

It seems that .NET Core is picking up steam fast, and there is expected huge demand for .NET Core and C# developers in the coming year.

DOT_NET_Core_and_C_Are_The_Next_Programming_Languages

According to TIOBE programming index, C# is one of the top 5 programming languages.

6 Things You Should Know About C# and .NET Core

1. Features Of Modern Languages

.NET has changed and improved in a span of 15 years. With .NET Core, even more, things are changed, including the entire ASP.NET stack being completely overhauled. The C# programming language was around for about 15 years and continues to improve over time.

Some top attributes:

Well typed

Huge base class libraries

Asynchronous programming

Garbage collection, auto memory management

LINQ

Generics

Share binaries over several platforms and frameworks

Easy to use frameworks to design MVC web apps and RESTful APIs

2. Easy to Learn

If you have done C, Java, or even javascript, the syntax of C# will look familiar to you. The syntax is simple and readable.

There are also many online resources to help you learn C#. Most of them are free and there are a few with low cost.

3. Versatility

The best thing about C# and .NET is that it is versatile. You can program desktop apps, background services, web applications, and also mobile apps owing to Xamarin. Besides C#, you have to know little JavaScript to hack the UI code together.

4. .NET Core is Open Source

One of the biggest changes to occur in .NET history is the open sourcing of the code. All the codes could be found on GitHub for anyone to review and contribute. A big change that most people in the IT industry never thought could happen.

You might not have contributes to the source code, but you can benefit from the huge community there. Problems and solutions are fast discussed, coded, and released on a regular basis.

5. Awesome Developer Tools

Visual Studio is regarded as one of the best IDEs for developers. Being a good code editor and supports features like debugging, code completion, profiling, unit testing, and lots more. VS currently offers a full-featured free Community edition.

There is also the possibility of writing code for .NET Core as basic text files with your favorite text editor. You can use VS Code on any OS as a great basic code editor.

The whole .NET ecosystem is filled with amazing developer tools.

6. Standardise The Skills

.NET has a good set of base class libraries. The wide array of base classes widely lessens the need for external packages.

Microsoft gives a very good set of patterns and practices for.NET. Most developers make use of standard frameworks, which makes it easy as a developer to move between teams and also understand how things work.

Conclusion

It is great to see what Microsoft, and the community, has done with .NET Core and how it has become the cool new thing.

The problem with several programming languages is that they are good at one use case. Ruby and PHP are good for web applications. Swift or Objective C works for creating iOS or MacOS applications. To write a background service there is python, java, or other languages. Besides C#, JavaScript and Java are the only languages which can be applied to a wide set of use cases.

An amazing thing about C# is the wide versatility which can be used for a wide variety of types of applications. And with .NET Core that works on MacOS and Linux, there is no limit to what you can do.

With this, we conclude. Keep coding!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support. We give a well-structured program for the best Dot Net Course. Among many reputed institutes of dot net training and placement in Pune, CRB Tech has created a niche for itself.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Top ASP.Net Web Application Framework Which You Must Know

ASP.NET happens to be an open-source server-side web application designed for web developers to create dynamic web pages. Created by Microsoft, it was done to permit programmers to develop dynamic websites, applications, and services on the web.

ASP Dot Net Web Application Framework Which You Must Know

Programmers make software by mixing their source code with .NET Framework and other available libraries. The framework is used by several new applications designed for Windows platform.

A Dot Net framework is a programming infrastructure developed by Microsoft for building, deploying, and to run applications and services which use .NET technologies, like desktop applications and Web services. The .NET Framework has three main parts: Common Language Runtime; Framework Class Library; ASP.NET.

Here we share a list of 5 best ASP.net web application frameworks:

* MonoRail

This is an ASP.net MVC web framework by Action Pack and provides different approaches for creating an application from a standard WebForms way of development as it imposes separation of concerns, where controllers handle application flow, models represent data, and the view to present logic. This says you can write less code and have a more manageable application.

* OpenRasta

This is an Asp.net based web application framework designed to create web-based applications and services. The framework mainly focuses on development of the resources and HTTP methods. The user can create REST-friendly User interfaces by using OpenRasta web application framework.

* DotNetNuke

This is an easily usable, flexible and open source web application framework based on Microsoft .NET platform. This is being written in VB.NET and released as Professional and Enterprise Editions.

* ASP.NET MVC

A web application framework which uses powerful, Model view controller patterns to create dynamic websites and web application that helps clean separation of issues and provides you full control over markup for enjoyable and agile development. The Framework has several useful attributes that allow rapid and TDD-friendly web development for developing sophisticated web applications that use the latest web standards.

* CSLA.net

An Asp.net based application creating framework which allows to build a web application for the Windows, Web, service-oriented and workflow applications and lower the cost of building and maintaining applications. It focuses on common issues of getting data in and out of the database or developing a very flexible User interface. The framework allows a developer to use the potential of object-oriented designs as the basis for creating powerful web applications.

With this, we conclude. Keep coding!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support. We give a well-structured program for the best Dot Net Course.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

New SPA Templates With ASP.NET Core 2

With the introduction of ASP.NET Core 2 Preview 2, now there are new web application templates present for Single Page Applications or SPA. Presently Angular, React.js, and React.js + Redux are supported. The intention of this blog post is to provide a short overview of the new templates and related applications as a sample.

New SPA Templates With ASP DOT NET Core 2

New SPA templates

While creating new ASP.NET Core application using Visual Studio 2017 Preview 3 there are three new templates for SPA.

The three templates actually create the same sample application but where they differ is in the JavaScript libraries. To mention, these new templates are found only when ASP.NET Core 2 is selected from framework dropdown list on top of the dialog.

TypeScript and webpack

SPA-s have ClientApp folder where JavaScript framework components are kept.

Another new aspect is a support for webpack module bundler. Webpack is added to the project as Node.js module. It is irrelevant as Task Runner. Webpack is run as a part of the build. It takes care of bundling and minimisation as well.

Webpack publishes bundled and minimised files to wwwroot\dist folder when the application is built. JavaScript libraries are piled to file wwwroot\dist\vendor.js and styles that come with these libraries are packet to wwwroot\dist\vendor.css file. Both files are minimised automatically as well.

webpack.config.js is a configuration file for webpack where all piling and minimising rules are defined. You can also add your own rules there.

Sample application

Let’s consider a SPA sample application which demonstrates simple counter and weather forecast page. The counter page uses JavaScript and forecast page uses server call to get weather forecasts. There is SampleDataController where sample data is produced.

Conclusion

The new SPA templates are very simple but potential as most of the work including scripts and adding components is done and to start building your own application become quite easy. Developers coding SPA-s on ASP.NET Core must know well the webpack as it is also one of most popular packing tools in JavaScript world.

With this, we conclude. Keep coding!

If you want to enhance yourself in Dot Net and improve yourself through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support. We offer a well-structured program for the best Dot Net Training Course.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

How To Test Logging In ASP.NET Core

In some cases, like analysis of problems in production, logging is really essential. Even you would like to test that your logging really works.

Testing_Logging_In_ASP_DOT_NET_Core

Let’s take the following function:

Public void DoSomething(int input)

{

_logger.LogInformation(“Doing something…”);

try

{

// do something that might result in an exception

var result = 10 / input;

}

catch (Exception ex)

{

// swallow but log the exception

_logger.LogError(ex, “An error occurred doing something.”, input);

}

public void DoSomething(int input)

{

_logger.LogInformation(“Doing something…”);

try

{

// do something that might result in an exception

var result = 10 / input;

}

catch (Exception ex)

{

// swallow but log the exception

_logger.LogError(ex, “An error occurred doing something.”, input);

}

}

We can assume that with an occurrence of this exception, it’s costing the company good amount of money. Hence it is good to know about it to solve a problem. From a developer’s point of view, the LogError method has the business Importance. And to be sure about it’s working right, there must be automated tests.

Now, consider how to test this code when the _logger case in question is an ASP.NET Core ILogger<T> type, input like as it is:

public class SomeService

{

private readonly ILogger<SomeService> _logger;

public SomeService(ILogger<SomeService> logger)

{

_logger = logger;

}

// methods

}

public class SomeService

{

private readonly ILogger<SomeService> _logger;

public SomeService(ILogger<SomeService> logger)

{

_logger = logger;

}

// methods

}

Now the question is how to test this scenario! You can’t call the method and then observe SomeService’s state to see if it is working. The only way to confirm in a unit test is to pass in your own implementation of ILogger<SomeService> into SomeService, and then find out if this instance was called by the DoSomething method. One way to do this is to use a mocking library like Moq, as shown below:

public void LogsErrorWhenInputIsZero()

{

var mockLogger = new Mock<ILogger<SomeService>>();

var someService = new SomeService(mockLogger.Object);

someService.DoSomething(0);

// Option 1: Try to verify the actual code that was called.

// Doesn’t work.

mockLogger.Verify(l => l.LogError(It.IsAny<Exception>(), It.IsAny<string>(), 0));

}

public void LogsErrorWhenInputIsZero()

{

var mockLogger = new Mock<ILogger<SomeService>>();

var someService = new SomeService(mockLogger.Object);

someService.DoSomething(0);

// Option 1: Try to verify the actual code that was called.

// Doesn’t work.

mockLogger.Verify(l => l.LogError(It.IsAny<Exception>(), It.IsAny<string>(), 0));

}

To mention, this approach fails as there is no LogError method on ILogger<T>, which is the LoggerExtension. This is the main reason why unit testing logging is difficult in ASP.NET Core.

A solution to this is to open a code for the logger extensions and find out what non-extension method is finally executed on ILogger. This would lead to a test like this one:

public void LogsErrorWhenInputIsZeroTake2()

{

var mockLogger = new Mock<ILogger<SomeService>>();

var someService = new SomeService(mockLogger.Object);

someService.DoSomething(0);

// Option 2: Look up what instance method the extension method actually calls:

//https://github.com/aspnet/Logging/blob/dev/src/Microsoft.Extensions.Logging.Abstractions/LoggerExtensions.cs#L342

// Mock the underlying call instead.

// Works but is ugly and brittle

mockLogger.Verify(l => l.Log(LogLevel.Error, 0, It.IsAny<FormattedLogValues>(), It.IsAny<Exception>(),

It.IsAny<Func<object, Exception, string>>()));

}

public void LogsErrorWhenInputIsZeroTake2()

{

var mockLogger = new Mock<ILogger<SomeService>>();

var someService = new SomeService(mockLogger.Object);

someService.DoSomething(0);

// Option 2: Look up what instance method the extension method actually calls:

// https://github.com/aspnet/Logging/blob/dev/src/Microsoft.Extensions.Logging.Abstractions/LoggerExtensions.cs#L342

// Mock the underlying call instead.

// Works but is ugly and brittle

mockLogger.Verify(l => l.Log(LogLevel.Error, 0, It.IsAny<FormattedLogValues>(), It.IsAny<Exception>(),

It.IsAny<Func<object, Exception, string>>()));

}

But you might have to mock calls that don’t even exist in the method we’re testing.

But every problem has a solution finder. So finally a trouble-shooter solved it by mentioning the need to create own version of ILogger<T> and give it with its own implementation of the method that has to be checked.

As instance methods are used before extensions methods, this would rather override the extension method in the test code. Thus, will appear the implementation:

public void LogsErrorWhenInputIsZeroTake3()

{

var fakeLogger = new FakeLogger();

var someService = new SomeService(fakeLogger);

someService.DoSomething(0);

// Option 3: Create your own instance of ILogger<T> that has a non-extension version of the method

// Doesn’t work, unless you change system under test to take in a FakeLogger (which is useless)

Assert.NotNull(FakeLogger.ProvidedException);

Assert.NotNull(FakeLogger.ProvidedMessage);

}

private class FakeLogger : ILogger<SomeService>

{

public static Exception ProvidedException { get; set; }

public static string ProvidedMessage { get; set; }

public static object[] ProvidedArgs { get; set; }

public IDisposable BeginScope<TState>(TState state)

{

return null;

}

public bool IsEnabled(LogLevel logLevel)

{

return true;

}

public void Log<TState>(LogLevel, EventId, TState state, Exception, Func<TState, Exception, string> formatter)

{

}

public void LogError(Exception ex, string message, params object[] args)

{

ProvidedException = ex;

ProvidedMessage = message;

ProvidedArgs = args;

}

}

public void LogsErrorWhenInputIsZeroTake3()

{

var fakeLogger = new FakeLogger();

var someService = new SomeService(fakeLogger);

someService.DoSomething(0);

// Option 3: Create your own instance of ILogger<T> that has a non-extension version of the method

// Doesn’t work, unless you change system under test to take in a FakeLogger (which is useless)

Assert.NotNull(FakeLogger.ProvidedException);

Assert.NotNull(FakeLogger.ProvidedMessage);

}

private class FakeLogger : ILogger<SomeService>

{

public static Exception ProvidedException { get; set; }

public static string ProvidedMessage { get; set; }

public static object[] ProvidedArgs { get; set; }

public IDisposable BeginScope<TState>(TState state)

{

return null;

}

public bool IsEnabled(LogLevel logLevel)

{

return true;

}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception, Func<TState, Exception, string> formatter)

{

}

public void LogError(Exception ex, string message, params object[] args)

{

ProvidedException = ex;

ProvidedMessage = message;

ProvidedArgs = args;

}

}

Even now you could assume that DoSomething is still calling the method LogError on ILogger<T>, Yet the extension method will be used because ILogger<T> doesn’t have an instance method that it could match. The only solution is to change the SomeService method to accept a FakeLogger, instead of an ILogger<T>, but even that doesn’t come as a real solution.

So what could be done?

The actual problem is we are dependent on types which are outside our control, and the types are using static methods which can’t be decoupled in tests. To attain loose coupling in our applications, we have to bring together dependencies on specific implementations by working with interfaces that can be controlled. This is a segment of the Interface Segregation Principle (ISP).

Now, some developers will counter because it’s not an implementation and even its part of the framework that we depend upon. But to accept the fact that, ILogger<T> isn’t an implementation, it’s only a use of extension methods and makes testing difficult. The best way to address the problem is with the use of an adapter.

You can start with the minimal interface which your client code needs. You don’t need to create one adapter for all but with every variation of method found on LoggerExtensions. Most applications won’t need all of them, so include the ones you require.

public interface ILoggerAdapter<T>

{

// add just the logger methods your app uses

void LogInformation(string message);

void LogError(Exception ex, string message, params object[] args);

}

public interface ILoggerAdapter<T>

{

// add just the logger methods your app uses

void LogInformation(string message);

void LogError(Exception ex, string message, params object[] args);

}

You can implement the adapter easily by passing in the implementation type it’s using. In this case, the ILogger<T> type and its extension methods:

public class LoggerAdapter<T> : ILoggerAdapter<T>

{

private readonly ILogger<T> _logger;

public LoggerAdapter(ILogger<T> logger)

{

_logger = logger;

}

public void LogError(Exception ex, string message, params object[] args)

{

_logger.LogError(ex, message, args);

}

public void LogInformation(string message)

{

_logger.LogInformation(message);

}

}

public class LoggerAdapter<T> : ILoggerAdapter<T>

{

private readonly ILogger<T> _logger;

public LoggerAdapter(ILogger<T> logger)

{

_logger = logger;

}

public void LogError(Exception ex, string message, params object[] args)

{

_logger.LogError(ex, message, args);

}

public void LogInformation(string message)

{

_logger.LogInformation(message);

}

}

At this point, you refract your service to remove the ILogger<T> dependency and instead use an ILoggerAdapter<T>. And next writing a text to verify that the error is logged properly becomes easy:

public void LogsErrorWhenInputIsZero()

{

var mockLogger = new Mock<ILoggerAdapter<SomeOtherService>>();

var someOtherService = new SomeOtherService(mockLogger.Object);

someOtherService.DoSomething(0);

mockLogger.Verify(l => l.LogError(It.IsAny<Exception>(), It.IsAny<string>(), 0));

}

public void LogsErrorWhenInputIsZero()

{

var mockLogger = new Mock<ILoggerAdapter<SomeOtherService>>();

var someOtherService = new SomeOtherService(mockLogger.Object);

someOtherService.DoSomething(0);

mockLogger.Verify(l => l.LogError(It.IsAny<Exception>(), It.IsAny<string>(), 0));

}

With this we conclude.

Keep coding!

If you want to enhance yourself in Dot Net and improve yourself through Dot NET training program; our institute, CRB Tech Solutions would be of great help and support. We offer a well-structured program for the best Dot Net Course.

Stay connected to CRB Tech for your technical up-gradation and to remain updated with all the happenings in the world of Dot Net.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

9 Things To Know Before Converting ASP.NET To .NET Core

During the conversion of ASP.Net to.Net Core, there are certain things you should know and understand. Here we listed the nine things you must know before you convert from ASP.NET to .NET Core.

9 Things To Know Before Converting ASP.NET to .NET Core

1. Build to deploy

If you want to create an app that targets non-Windows, you need to build it on the target platform. Rather you can’t create your app on Windows and next deploy it to a Mac. You can perform that with a net standard library, but not a netcoreapp. Hope this limitation is overcome in future.

2. IIS is somewhat dead

Microsoft created a new web server called Kestrel. IIS is amazing but comes with a very dated limited model and carries lots of weight with it.

Kestrel makes deploying the web app easily like deploying any console app. When ASP.NET Core app starts, it activates Kestrel server, sets up HTTP bindings, and handles everything.

IIS isn’t dead in actual. IIS can be used as a reverse proxy sitting in front of Kestrel to take advantage of some of its features that Kestrel doesn’t have, like virtual hosts, security, logging, etc. Microsoft yet suggests using IIS to remain in front of ASP.NET Core apps.

3. HttpModules and HttpHandlers are substituted by a middleware

Middleware is created to replace modules and handlers. The mixed news is that you can’t configure them in a config file. They are all mentioned in the code.

4. To use xproj & csproj files together

In no way, the two project types refer each other. You move everything of xproj, but no longer could use MSBuild. But it is possible to use xproj and csproj files both at the same time while doing your Windows targeted the creation of Prefix.

5. StreamReader constructor doesn’t work with a file path

Previously StreamReader was often used by sending a file path to the constructor. Now you have to send a stream. This cause little refactorings to use a FileStream in addition to the StreamReader everywhere.

6. Platform-specific code… like Microsoft specific RSA

.NET Core is created to run on Windows, Linux, and Macs. But some codes can compile on Windows but then fail during runtime while you want to run on a Mac or Linux. For example, RSACryptoServiceProvider which seems efficient. At Mac runtime, a message will pop up “platform not supported”. To know, RSA provider API is Windows specific. Instead, you need to use RSA.Create() which has slightly different methods.

7. No existence of System.Drawing

If you want to resize images, then you can’t-do currently with .NET framework. There are a few projects which could be used.

8. Web API is Gone

With .NET Core, Microsoft decided to merge together Web API and MVC. They were very similar to work with and either was used for API type applications. Hence in a several ways, merging them makes sense.

9. To design Windows Service in .NET Core

Windows Services can be created with VS 2017 so long the code targets the .NET Framework. You have to move your .NET Core code to a class library which targets NetStandard that could then be shared through different .NET Core apps and your Windows Service.

Keep coding!!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot NET training program then our institute CRB Tech Solutions would be of great help and support. We offer a well-structured program for the best Dot Net Course. Among much reputed of dot net training and placement institute in Pune.

Stay connected to CRB Tech for your technical up-gradation and to remain updated with all the happenings in the world of Dot Net.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

How Dot NET Core and C# Are The Best Thing Happening

.NET Core is developing in several aspects faster, and prediction is such there would be a huge demand for .NET Core and C# developers in the year 2018.

Dot NET Core and C# Are The Best Thing Happening

Top 6 Things to Know About C# and .NET Core

To know why .NET Core is bringing C# up the list of most popular programming languages.

Easy to Learn

Needless to mention, the syntax of C# would be familiar to you compared to C language or Javascript. The syntax is quite simple to understand and read. Based on the TIOBE index there are several millions of developers who could easily switch from Java or C.

Versatility

Both C# and .NET has versatility. You can write desktop apps, web applications, and even mobile apps with the help of Xamarin. Besides C#, what you need to know is a little JavaScript to hack some UI codes.

The versatility is significant as your investment in learning the language could be used for a wide array of things.

Amazing Tools

Visual Studio is the best IDEs available for developers. It is the best code editor which supports features like debugging, code completion, profiling, unit testing, and more.

You can also write code for .NET Core as basic text files with your favorite text editor. Visual Studio Code can be used on any OS as a great basic code editor. Rather, the whole .NET system has several amazing developer tools.

Modern Language Features

.NET has been around since a long time has changed and improved a lot. There are amazing improvements like MVC, LINQ, async/await and much more. With .NET Core, a lot has changed, which includes the whole of ASP.NET stack got completely overhauled.

C# has been around for about 15 years and has been improving over time.

Below mentioned are the top features:

*Strongly typed

*Asynchronous programming

*Garbage collection, automatic memory management

*LINQ

*Generics

*Package management

*Easy to use frameworks to design MVC web apps and APIs

NET Core is an Open Source

One of the biggest advantages is the availability of open sourcing coding.

As a developer, you will need to look what your code is really doing. Even if you don’t contribute to the source code, you can benefit from the huge community. Problems and enhancements are rapidly discussed, coded, and released regularly.

Conclusion

The problem with several existing programming languages is that they are good at one specific point. Ruby and PHP are good for web applications. Swift or Objective C is amazing for creating iOS or MacOS applications. If you wish to write a background service you could take help of python, java, or other languages. Besides C#, JavaScript and Java might be the only languages which could be applied to a vast set of use cases.

The best thing about C# is it’s wide versatility as it can be used for a wide variety of types of applications. And with .NET Core working on MacOS and Linux, there is no limit to what you can try it.

Now with this, we conclude. We hope this was of help to you.

Keep coding!!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot Net training program; CRB Tech Solutions would be of great help and support. Among many reputed institutes of dot net training and placement in Pune, CRB Tech has created a niche for itself.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

How To Deploy ASP.NET Core to IIS

To deploy an ASP.NET Core app to IIS isn’t that difficult, but hosting in ASP.NET Core is a little different than ASP.NET.

Deploy_ASP_DOT_NET_Core_to_IIS

Lets Configure an ASP.NET Core App For IIS

To mention about ASP.NET Core project is that they are console applications. Your project has a Program.cs file like a console app would have and it has the following code:

public class Program

{

public static void Main(string[] args)

{

var host = new WebHostBuilder()

.UseKestrel()

.UseContentRoot(Directory.GetCurrentDirectory())

.UseIISIntegration()

.UseStartup()

.Build();

host.Run();

}

}

What do you mean by WebHostBuilder?

All ASP.NET Core applications need a WebHost object that serves as an application and web server. WebHostBuilder is used to configure and develop WebHost. You can see UseKestrel() and UseIISIntegration() in the WebHostBuilder setup code.

What do they do?

UseKestrel() – This registers IServer interface for Kestrel that will be used to host your application. In the future, there would be other options, which include WebListener and that would be Windows only.

UseIISIntegration() – This says to ASP.NET that IIS will work as a reverse proxy in front of Kestrel. This then specifies some settings around which port Kestrel must listen on, forward headers, and other details.

If you are planning to deploy your application to IIS, UseIISIntegration() is needed.

What is AspNetCoreModule?

An ASP.NET Core projects create a web.config file. This is used to deploy your application to IIS. It registers AspNetCoreModule as an HTTP handler.

Default web.config for ASP.NET Core:

<?xml version=”1.0″ encoding=”utf-8″?>

<configuration>

<system.webServer>

<handlers>

<add name=”aspNetCore” path=”*” verb=”*” modules=”AspNetCoreModule” resourceType=”Unspecified”/>

</handlers>

<aspNetCore processPath=”%LAUNCHER_PATH%” arguments=”%LAUNCHER_ARGS%” stdoutLogEnabled=”false” stdoutLogFile=”.\logs\stdout” forwardWindowsAuthToken=”false”/>

</system.webServer>

</configuration>

AspNetCoreModule manages all incoming traffic to IIS and acts as reverse proxy that knows how to forward the traffic to your ASP.NET Core application.

Install .NET Core Windows Server Hosting Bundle

Before you start deploying your application, you must install the .NET Core hosting bundle for IIS. This will install .NET Core runtime, libraries, and ASP.NET Core module for IIS.

After doing that, you might need to do a “net stop was /y” and “net start w3svc” to make sure all the changes are taken for IIS.

Steps to Deploy ASP.NET Core to IIS

You have to configure WebHostBuilder to use Kestrel and IIS. Your web.config must exist and look similar to the example above.

Step 1: Publish to File Folder

Publish to a Folder with VS 2017

Step 2: Copy Files to Preferred IIS Location

Copy the published files where you want them live. If you deploy to a remote server, you might need to zip the files and move to the server. If you intend to deploy to a local dev box, you can copy them locally.

Step 3: Create Application in IIS

Firstly, make a new IIS Application Pool. You might like to develop one under the .NET CLR version of “No Managed Code“. Remember IIS works as a reverse proxy, it doesn’t execute any .NET code.

Next, develop your new application under your existing IIS Site, or design a new IIS site.

Step 4: Load Your App

Your application must load well. If it doesn’t, check the output logging from it. Within your web.config file, you explain how IIS starts up your ASP.NET Core process. Get output logging done by setting stdoutLogEnabled=true and you might also want to change the log output location as configured in stdout log file.

Advantages

Microsoft suggests using IIS with any public facing site for ASP.NET core hosting. IIS gives additional levels of configuration, security, management, logging, and several other things.

One of the biggest advantages of using IIS is process management. IIS will start your app automatically and restart it if a crash has to occur.

Now with this, we conclude. We hope this was of help to you.

Keep coding!!

If you want to enhance yourself in Dot Net Course and improve yourself through Dot NET training program then our institute CRB Tech Solutions would be of great help and support. We offer a well-structured program for the best Dot Net Course. Among many reputed institutes of dot net training and placement in Pune.

Stay connected to with us for your technical up-gradation and to remain updated with all the happenings in the world of Dot Net.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Ways To Configure log4net For .NET Core

We start with the mention that the log4net team published new NuGet packages which support.NETStandard 1.3, which says it must work with .NET Core. This article is to discuss updates for log4net support.

Ways To Configure log4net For Dot NET Core

To start with: Configure() log4net

To add a reference to the log4net NuGet package is no problem. If you worked previously with log4net for any amount of time, you know that you must add codes for configuring it.

XmlConfigurator.Configure() needs some parameters that we didn’t usually provide in the past.

Configuration Workaround: Load It Manually

This log4net is good enough to load its configuration from a web.config or log4net.config file. In .NET Core, it doesn’t appear to know how.

It makes sense that this can’t read from a web.config/app.config because they don’t exist in .NET Core.

But, it doesn’t automatically try to read a log4net.config file. To mention, NLog does the same thing. You need to configure manually as in .NET Core.

With little little reverse dtudying, you will know how to load the log4net.config file and configure log4net.

var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

XmlConfigurator.Configure(logRepository, new FileInfo(“log4net.config”));

You can get this to work with a .NET Core app targeting both netcoreapp1.0 and net452. Sum up that to your Program.cs as the first thing your code does.

There is a mention about some limitations with the current 2.0.7 version of log4net. Hopefully, there will be some more developments.

Now with this, we conclude. We hope this was of help to you.

If you want to enhance yourself in Dot Net Course and improve yourself then our institute, CRB Tech Solutions would be of great help and support.

They offer a well-structured program for the best Dot Net Training course. Among many reputed institutes of dot net training and placement in Pune. Keep coding!!

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr