.status-msg-wrap { display: none; }
Friday, August 31, 2018
no image

Remapping posted values from listbox

Hey everyone,

What’s the best way to remap submitted options values from a listbox in the post action, back to a list it was chosen from.

The only way I can think of doing it is by reacquiring the list of options from the datasource, then using LINQ to get the selected items, but that requires a additional sql call.

Is there another way to do it without making a call to the db?

Thanks.

Remapping posted values from listbox Click here
no image

I published my ASP.NET Core app to a local IIS server but it's not up to date. What happened?

It's showing an old version of the app that I'd previously published, and it's failing to connect to the database. I didn't get any errors when publishing. The files such as site.css are up to date on the filesystem but they're not appearing in my browser properly, and the database connection is broken. I tried clearing my cache to no avail. What happened? How can I get the latest version of my app running under IIS?

I published my ASP.NET Core app to a local IIS server but it's not up to date. What happened? Click here
no image

SOLID Principle in C#

SOLID Design Principles in C# by dotnettutorials.net

The SOLID Design principles represent five design principles that basically used to make the software designs more understandable, flexible and maintainable.

The theory of SOLID principles first introduced by Robert C. Martin. In this article, I will discuss the basics of SOLID Design Principles.

What is SOLID Principle?

The SOLID Design principles are the design principles that enable us to manage most of the software design problems that generally as a developer we face in our day to day programming. These design principles are provided with some mechanism to make software designs more understandable, flexible and maintainable.

Let’s first discuss the reason behind most of the unsuccessful application.

Developers start designing and developing the applications with their tidy design knowledge and experience. But over the time, the applications might give bugs. Them the developer needs to alter the design for every change request or for any new feature request to include.

After some time we might need to put a lot of effort, even for simple tasks and it might require a full working knowledge of the entire system. But we can’t blame change or new feature requests as they are part of the software development.

We can’t stop them and refuse them either. So who is the culprit here? Obviously, it is the design of the application.

The following are the reasons that cause the damage to the software.

  1. Putting more stress on classes by assigning more responsibilities to them. (In the simple word a lot of functionalities we are putting into the class even though they are not related to the class.)
  2. Forcing the classes to depend on each other. If classes are dependent on each other (in simple words we can say that they are tightly coupled), then a change in one class will affect the other classes also.
  3. Spreading duplicate code in the system/application.

Solution

  1. We need to choose the correct architecture (i.e. MVC, 3-tier, Layered, MVP, MVVP and so on) based on the project requirements.
  2. As a developer, we need to follow the Design Principles (i.e. SOLID Principles).
  3. Again we need to choose correct Design Patterns to build the software based on the project requirements.

SOLID Introduction

  1. SOLID Design principles are the design principles that enable us to manage most of the software design problems that generally as a developer we face in our day to day programming.
  2. Robert C. Martin compiled SOLID Design principles in the 1990s.
  3. The SOLID Design principles represent five design principles that basically used to make the software designs more understandable, flexible and maintainable.
  4. The theory of SOLID Design principles was introduced by Robert C. Martin in his 2000 paper Design Principles and Design Patterns, although the SOLID acronym itself was introduced later by Michael Feathers.

SOLID Acronym

  1. SSingle Responsibility Principle (SRP)
  2. OOpen Closed Principle (OSP)
  3. L:  Liskov Substitution Principle (LSP)
  4. I:  Interface Segregation Principle (ISP)
  5. DDependency Inversion Principle (DIP)
Single Responsibility Principle (SRP)

The Solid single responsibility principle states that

“every module or class should have responsibility for a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class”.

Robert C. Martin expresses the principle as, “A class should have only one reason to change”.

Open/Closed Principle (OCP)

The Open Closed Principle states that

“software entities such as classes, modules, functions, etc. should be open for extension, but closed for modification”.

That is, an entity can enable its behavior to be extended without altering its source code.

Liskov Substitution Principle (LSP)

Liskov Substitution Principle is a Substitutability principle which state that, if S is a subtype of T, then objects of type T should be replaced with objects of type S (that means objects in a program should be replaceable with instances of their sub-types) without altering any of the desirable properties of the program (correctness, task performed, etc.).

In simple word, we can say that If a program module is using a Base class, then the reference to the Base class can be replaced with a Derived class without affecting the functionality of the program module

Interface Segregation Principle (ISP)

The interface segregation principle (ISP) states that no class should be forced to implements any methods it does not use. ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them.

That means the main responsibility of ISP is to keep a system more decoupled and thus easier to refactor, change, and redeploy.

Dependency Inversion Principle (DIP)

The dependency inversion principle (DIP) states that

  1. High-level modules should not depend on low-level modules. Both should depend on abstractions.
  2. Abstractions should not depend on details. Details should depend on abstractions.

In simple word, we can say that while designing the interaction between a high-level module and a low-level module, the interaction should be thought of as an abstract interaction between them.

Following SOLID Design Principles helps us to 
  1. Achieve reduction in complexity of code
  2. Increase readability, extensibility and maintenance
  3. Reduce error and implement Reusability
  4. Achieve Better testability
  5. Reduce tight coupling

Following are the Links where I explained each of these principles in a great details with taking some real-time examples.

Single Responsibility Principle

https://dotnettutorials.net/lesson/single-responsibility-principle/

Open Closed Principle

https://dotnettutorials.net/lesson/open-closed-principle/

Liskov Substitution Principle

https://dotnettutorials.net/lesson/liskov-substitution-principle/

Interface Segregation Principle

https://dotnettutorials.net/lesson/interface-segregation-principle/

Dependency Inversion Principle

https://dotnettutorials.net/lesson/dependency-inversion-principle/

SOLID Principle in C# Click here
Thursday, August 30, 2018
no image

Displaying Model in _Layout and Creating a Favorites List in .NET Core 2+

Hello!

This is a x-post in StackOverflow. Forgive me if this breaks etiquette. I'm a lurker on the internet, so contributing like this is a little foreign to me. I had to break the silence because this issue has thrown me for a loop for a few days now.

I'm fairly new to programming and I'm trying to create a website to house the web apps I build. I currently have a model, view, and controller to project the contents of my Apps table. These apps are hosted elsewhere, so the tiles that appear in the screenshot below simply link out to other locations. I'd like to include a way to display recently used apps in a drawer, (the code housed in the _Layout).

_Layout Drawer:

App View with _Layout (navbar and drawer)

I'd like to start by displaying ANY model data in the _Layout drawer. If I simply throw my Apps View code into the _Layout, like so:

Layout (partial code, I left out irrelevant parts):

@_Layout, located beneath navbar code and above RenderBody()@ @model IEnumerable<Apps> <div id="footerSlideContainer"> <div id="footerSlideButton"></div> <div id="footerSlideContent"> <div id="footerSlideText"> <div class="parenttile"> @foreach (var Apps in Model) { <a href="http://@Apps.AppLink" target="_blank"> <div class="tile"> <div></div> <div class="tilemid"> <div></div> <div> <img class="tileimage" src="@Apps.AppImage" alt="@Apps.AppName" /> </div> <div></div> </div> <div class="tilebot"> @Apps.AppName </div> </div> </a> } </div> <h3>Recently Used Apps</h3> <p>This section will store all of your most recently used apps. It stays on the screen until you click the drawer icon.</p> </div> </div> </div> 

...I get the following error in Debug on the @foreach line: NullReferenceException: Object reference not set to an instance of an object. .net core. I researched that error here: What is a NullException error and how do I fix it?

  1. I understand the action method comes before the model displays. If I were to use the above code, I would presume that I need to inject the model into the action method - but, does the _layout have a controller?
  2. I researched here: ASP MVC Razor Pass model to view . This looks like the closest solution, but would appreciate someone walking me through it.
  3. Finally, I noticed that I could use a ViewComponent ViewComponent in ASP.NET Core. I could use some help implementing this solution.

Which of these solutions would work/work best?

Then there's the issue of creating the favorites. I think that's a bit more straightforward, as this Display recently viewed items contains all the info I think I need.

Thanks for any help - I'm including my model and controller code below:

Model:

 public class Apps { public int AppID { get; set; } public string AppName { get; set; } public string AdGroup { get; set; } public string AppDescription { get; set; } public string AppLink { get; set; } public string AppImage { get; set; } } 

Controller: (using hard coded, dummy data for now, before I move to db)

public class AppsController : Controller { private List<Apps> _apps; public AppsController() { _apps = new List<Apps>(); //creating test Apps model _apps.Add(new Apps { AppID = 1, AppName = "Test App 1", AdGroup = "Group 1", AppDescription = "First test app.", AppLink = "www.google.com", AppImage = "/images/image1.png" }); //et al } public IActionResult Index() { return View(_apps); } } 

Displaying Model in _Layout and Creating a Favorites List in .NET Core 2+ Click here
Wednesday, August 29, 2018
no image

Need Help : Testing API controllers for existing Microservice

I am actively working on a Microservice, the mistake we did is we did not write tests. Only thing we have to test our web API is JSON payloads saved in Postman.

Given the state we are in what will be your suggestion? Can JSON payloads utilized for testing API controllers? Should I invest time in Postman automation?

Microservice is developed with Hexagonal architecture.

Feel free to ask question.

Need Help : Testing API controllers for existing Microservice Click here
Tuesday, August 28, 2018
no image

Windows 10 Upgrade - IIS Express Can't Render ASP.NET MVC Application

We're running a combination of Windows 10 1609 or 1703 and rolling out windows 10 1709 to all developer systems. We've hit a snag where after the upgrade, running the debugger causes an error code of 403.14 forbidden; the suggestions are to enable directory browsing but that's not really the fix we're after. If we starting with a clean W10 1709 and install all of our development tools, this isn't an issue.

We've repaired the VS installation, re-installed IIS Express but neither seems to do the trick. As a test, we also enabled all the optional IIS features for application and that seems to fix it, but ultimately we'd like to figure out what's causing the problem.

Our environment is Visual Studio 2017, MVC 4, C#7 .NET 4.7.2.

Has anyone else experienced this problem?

Windows 10 Upgrade - IIS Express Can't Render ASP.NET MVC Application Click here
no image

MTA: SW Fundamentals Practice Exam Answer Errors

So I'm studying for the mta Software Fundamentals exam on Sep 6. I'm looking at practice exams online but I don't trust that they're giving me correct info. Here's an example - The question is as follows:

You are designing a class for an application. You need to restrict the availability of the member variable accessCount to the base class and to any classes that are derived from the base class. Which access modifier should you use? A. Internal B. Protected C. Private D. Public

Now my answer is B. But the exam claims it's C, private. This is obviously wrong, right? Now I don't know if I can trust the exam at all. And this isn't the only one. I took an exam on techveze and they had multiple wrong answers. I'll have to post some of those one day. I'm just worried that I can't trust any of these practice exams. Does anyone know of any trustworthy ones? Or am I just arrogant and am actually picking the wrong answer?

MTA: SW Fundamentals Practice Exam Answer Errors Click here
no image

Implement Akka.net in MVC web application

Hello Everyone,

I'm kind of new to Akka.Net programming, Can anyone point me some kind of web app solution which is available online which uses akka.net. Currently, i'm using hangfire, I'm wondering what is the difference between akka.net and hangfire.

Implement Akka.net in MVC web application Click here
no image

Beginning dotnet development.

Hi guys.

I'm a full time laravel developer, 3 months out of college, and I'm looking to switch to C# and dot net. I'm in Dublin Ireland, and the majority of quality jobs seem to use C# and Java with a frontend javascript framework. So it's time to bite the bullet and learn one.

I've worked with C# and MVC5 previously I'm college and enjoyed it, but I never stuck with it. I'm looking for resources and guides on learning Web dev with this technologies.

I have a few questions.

Is Mosh Hamedani on Udemy a good resource?

Is there a Laracasts equivalent?

Who would be the best twitter accounts to follow?

Can I use MVC5 on a mac. I know core is out, and cross platform, but a lot of the jobs in Dublin are still MVC5.

Thanks.

Beginning dotnet development. Click here
no image

Handling COM objects in a vb6 to vb.net migration

Hi community,

I am currently in the process of migrating a substantial vb6 project towards vb.net. This project has a number of referenced dependencies, custom controls and components - essentially additional functionality found in other vb6 projects hooked up to the main project.

After having used the default migration tool in Visual Studio 2008, I’ve noticed that these are now treated as COM objects, unaltered and referenced by the converted project.

My understanding here is that Visual Studio is applying a “.net wrapper” or interpreter to these projects, under a technique known as interoperability. Interoperability allows us to integrate the old with the new in order to run external components not written in a .Net language attached as project references.

  1. Am I able to thus avoid having to alter or migrate these projects in any way?
  2. Are there any possible downsides to this approach? Presumably performance, first and foremost.
  3. If external components can be interpreted by the CLR through Interop, why can’t the whole project, or for example classes within the project? If the only requirement is to make it work on the .Net framework. That logic doesn’t seem right to me so I would just like some clarification/confirmation concering that.

Many thanks in advance!

Handling COM objects in a vb6 to vb.net migration Click here
Monday, August 27, 2018
no image

How to discover what is slowing your application down

We are making a site in Razor Pages using .NET Core 2.1 and are using code first EF Core, dependency injection and iDesign and all the cool conventional ideals. We started it half a year ago and are still working on it. The database it pulls from is small; 5 or 6 columns averaging 10 or so entries per SQL call; about 10 tables. Our entire site is only around 30 MB.

As I try to test it, it takes over a minute after the project built to show up on the screen and each page I click on just has to load a table or a 8ish field form and it takes anywhere from 30 seconds to a minute after the click to load while debugging. I try to do some of the SQL statements it does to see if its just bad indexes but those all finish in well under a second. We have refactored and refactored to the point where we are over budget. It is a basic CRUD site that will need to utilize multiple page loads and while its not incredibly slow on the servers it is quite a few seconds from when you click on a link to when it loads, maybe 10 or so... basically a lifetime in internet time.

So as many of you know, in Chrome you can load a page and it would tell you how long different steps take and with that you can see what thing took a long time and eliminate it. Is there anything like that for .NET Core? I don't know if there is some sort of tracer we can have running on the backend that will tell us what our slow point is. I know Azure has some tools but we are just running this on servers my company manages.

How to discover what is slowing your application down Click here
no image

How many endpoints is too many for an API?

I am creating an API which the app I am developing will utilise. This app will be like a social network, and have various sections to it (Login, Posts, Messages, Friends, etc). This is my first time developing an api to work alongside an app, so I wanted some guidance.

Is it better practice to have a controller for each of these sections (LoginController, MessageController, etc). Or am I better off making seperate APIs for each section (Login API, Messaging API). I suspect each section will contain around 10-15 endpoints.

How many endpoints is too many for an API? Click here
no image

Asp.net core hosting

why all the web hosting companies are not supporting the "asp.net core" deployment on shared hosting. They suggest to go for windows VPS to deploy asp.net core project.

Is there any alternate to host asp.net core in any cheap server?

Asp.net core hosting Click here
The webdev Team