Friday, May 08, 2020

Error message 401.2.: Unauthorized: Logon failed due to server configuration. IIS Express ASP.NET

When you are running ASP.net application using visual studio and configured to run with IIS Express and if you are getting following error, I resolved to following below steps.

Error message 401.2.: Unauthorized: Logon failed due to server configuration.



Friday, November 22, 2019

Error: Parser Error Message: Could not load type” in Global.asax

I resolved this error to change project OutputPath property to "bin" instead of "bin\Debug" or "bin\Release"

Go to the Project right click and select Property > Compile and change "Build output path" to "bin\"


or Unload project and open for Edit and Modify Outputpath property to "bin\" instead of "bin\Debug" or "bin\Release".
and also you can check IIS pool should be in correct .NET version (2.0 or 4.0)

Create Pipeline build to Push DLL into Nuget Repository using Azure DevOps


Here simple steps to follow and create new Automated Build using Azure DevOps to push your DLLs into NuGet Repository 

You mainly needed three task to Restore, Pack and Push library into NuGet repository.

Go to Pipeline > Build > Create New Build , Add following Task on your build 

  1. Get a Sources
    1. Choose Repository (TFVC or Git)
  2. Add Agent Job
    1. NuGet Tool Installer : leave all default
                                                    i.     Type: Map
                                                   ii.     Server Path: choose source code location
                                                  iii.     Clean: true
                                                  iv.     Clean Options: sources
                                                   v.     Label sources: OnSuccess
                                                  vi.     Label format: $(Build.BuildNumber)
    1. NuGet  for Restore
                                                    i.     Choose command : restore
                                                   ii.     Path to solution, packages.config, or project.json (.sln file path)
                               iii.     Use packages from this Azure Artifacts/TFS feed
                                iv.     Check: Use packages from NuGet.org
    1. Update AssemblyInfo
                                                    i.     Root Folder: $(Build.SourcesDirectory)
                                                   ii.     File pattern (AssemblyInfo.cs)
                                                  iii.     Version: $(Build.BuildNumber)
                                                  iv.     File Version: $(Build.BuildNumber)
    1. Visual Studio Build
                                                    i.     Solution :   .sln file path
                                                   ii.     Visual Studio Version: Latest
                                                  iii.     Platform : AnyCPU
                                                  iv.     Configuration: Release
                                                   v.     Check: Clean
    1. NuGet (for pack)
                                                    i.     Command: pack
                                                   ii.     Path for proj or nuspec
                                                  iii.     Pack Option: “Use the build number”
    1. NuGet (for Push)
                                                    i.     Command : push
                                                   ii.     Path to NuGet package to publish ($(Build.ArtifactStagingDirectory)/*.nupkg)
                                                  iii.     Target Feed: Select a feed hosted in this account. You must have Package Management installed and licensed to select a feed here.”

Go to this video for more details 

Common errors when you automate build using Azure DevOps build


Error-1
The nuget command failed with exit code(1) and error(System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.

Solution
I observed this error when I was trying to create automated build using Azure DevOps Pipeline and I changed **/*.csproj  from **/*.Sln as a file to build.

To Resolve this error, in the Pipeline Task select  NuGet & use Pack Option instead of Restore Option, Restore Option work for Solution file only not for project file.

Error-2
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(775,5): Error : The OutputPath property is not set for project 'ABC.csproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Release'  Platform='Any CPU'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project.

Solution
Again if you are switching from .Sln file to .csproj or .vbproj file to be build then make sure you are selecting the correct "Platform" property.

For Project file , Platform property value is "AnyCPU" and 
For Solution file, Platform property value is "Any CPU" (with space)

so, you need to open project file in notepad and check PropertyGroup section and OutputPath tag should look like below.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <OutputPath>bin\Release\</OutputPath>
      .
      .
</PropertyGroup>

Error-3
Response status code does not indicate success: 409 (Conflict - The feed already contains “*.dll <Version Number>”)

Solution:
When you get this error that mean project is building correctly but not increasing the build number, so server trying to push same dll version into NuGet and it not allow duplicate version number, and throw 409 error
If you choose "Skip duplicate version" option then it will resolve the issues but that will not be correct because latest version never deployed into NuGet server. 

The best solution I found, in NuGet Task select following option 
Command : pack
Automatic package versioning : Use the build numbers 

This will create new version every time when new DLL build successfully, so No 409 error.

Wednesday, November 13, 2019

Error: The visual tree has been changed during a 'VisualTreeChanged' event.

Error: The visual tree has been changed during a 'VisualTreeChanged' event.

Solution: 
Go to Visual Studio, Tools >> Options and unchecked "Enable UI Debugging Tools for XMAL"

 

Tuesday, November 12, 2019

Error: The authentication schemes configured on the host ('Ntlm, Anonymous') do not allow those configured on the binding 'BasicHttpBinding' ('Negotiate'). Please ....

ErrorThe authentication schemes configured on the host ('Ntlm, Anonymous') do not allow those configured on the binding 'BasicHttpBinding' ('Negotiate').  Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly.  Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.

Solution:

I have done following two things in IIS setting to resolve following error

1) Make sure for Hosted WebSite/App two Authentication option is set to Enabled
     Anonymous Authentication = Enabled and Window Authentication = Enabled


2) Right click on Window Authentication >> Providers
     make sure you have NTLM and Negotiate is added as Enabled Providers, If not just add it.



Sunday, May 19, 2019

How to add innerHTML or Multi line text to NgbPopover


I was trying to show multi line text on Popover and want to format my display contain as I want using HTML tag. text construction has to be done in .ts file.

I achieved this in following way.

Label where, on mouseover I want to show popover with employee detail data.
I want when use mouseover then popover display and if user click outside or click “esc” then popover disappears. You can also use moverover and mouse leave using triggers="mouseenter:mouseleave"

npm install --save @ng-bootstrap/ng-bootstrap

app.module.ts

//Popover- menu item
import { NgbPopoverModule, NgbModalModule, NgbAlertModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({imports: [NgbPopoverModule]})

Employee.html file 

            name="EmployeeProfile "
(mouseover)="getEmployeeProfileData()"
            [ngbPopover]="ShowEmployeeProfile" 
popoverTitle="Employee Detail Profile"
            triggers="mouseenter" [autoClose]="'outside'">
</label>

 <ng-template #ShowEmployeeProfile >
 <div[innerHtml]="employeeDetailDataForToolTip"</div>
</ng-template>

Employee.ts file

employeeDetailDataForToolTip: string ="";

getEmployeeProfileData(): string
{
this.employeeDetailDataForToolTip="";
this.employeeDetailDataForToolTip+='<ul><u>Ritesh Kesharwani</u>';
this.employeeDetailDataForToolTip+='<li>Address: Mile City, USA</lt;li>';
this.employeeDetailDataForToolTip+='<li> Department: Education</li>';
this.employeeDetailDataForToolTip+='<li> Salary: $300000</li>';
this.employeeDetailDataForToolTip+='<li> Base Location: MN</li></ul>'
}
If you want scroll bar on Popover then you need to override style sheet
.popover {
  max-width500px !important;
  background#F9F9F9 !important;
  max-height400px !important;
  overflowscroll !important;
}

sample pop over on label mouse over 


Tuesday, May 07, 2019

During Test Debug control not hits to the break points + Not able to debug test case


Go to the project property > Build and Uncheck following
  • Allow unsafe code
  • Optimize Code

 And Select Platform target: Any CPU



Error: testhost.x86.exe' has exited with code 0 (0x0).


Error: testhost.x86.exe' has exited with code 0 (0x0).

After my research I found, below nuget package was missing from my project.

I have installed below and it resolved the issue.

MSTest.TestFramework

Make sure following package are installed in your test project

MSTest.TestFramework And MSTest.TestAdapter

Monday, May 06, 2019

Render Date field in specific Date Format into ag-Grid Angular 6

In you ag-Grid if you want to display date field in specific format do the following steps

  1. npm Install moment --save
  2. in your .ts file use below

 import * as moment from 'moment';

columnDefs =
[{
headerName: 'Effective Start Date', field: 'EffectiveStartDate',
cellRenderer: (data) => {
return  data.value ? (moment(data.value).format('MM/DD/YYYY')) : '';}
}];


For more info on moment please use https://momentjs.com/


Add hyperlink click event into ag-Grid Angular 6

I had spent lots of time to figure how to add hyperlink into ag-grid column and how to call function executed at on click event. This was looking very difficult but later it came with very simple solution.
My requirement was to add hyperlink on Grid column with the rendered data, so no button where we have static word like “Add” etc.

Simple solution I could figure out is to add cellClicked event

.html page

<ag-grid-angular
    (cellClicked)='onCellClicked($event)'>
</ag-grid-angular>

And when cellClicked   by user execute Type Script function

.ts page

onViewCellClicked(event: any)
  {
    if (event.column.colId =="FirstName" ) // only first column clicked
    {
      // execute the action as you want here in on click of hyperlink
    }
// here you can add multiple if statement based on colId to do the action      //on cell clicked
  }

Your column definition as below

columnDefs = [{
headerName: 'First Name', field: 'FirstName', suppressMenu: false, unSortIcon: true, width:150,
      cellRenderer: function(params) {
        // below line is just to create empty without any action hyperlink
// to trick the user, but actual action happen onViewCellCliced() // function
        return '<a href="#">' + params.value + '</a>';
            },
            tooltipField: "FirstName", headerTooltip: "First Name"     
      }];

Thursday, June 07, 2018

Error: 'IApplicationBuilder' does not contain a definition for 'UseIdentityServerAuthentication' and...

When I was trying to implement security to one of my .net core Web API, I encountered below error

'IApplicationBuilder' does not contain a definition for 'UseIdentityServerAuthentication' and no extension method 'UseIdentityServerAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

After long struggle, I found that .Net Core 2.0 does not support the security the way .NET Core 1.0 used to support, Code need to rewritten in different way, actually need to follow the steps to migrate your Web API to .NET Core 2.0 using Microsoft.AspNetCore.Authentication.JwtBearer; 

Please follow migration steps to resolve this issues
https://elanderson.net/2017/09/identity-server-api-migration-to-asp-net-core-2/

Saturday, September 09, 2017

$window.open('url') directs to currenthost + url instead of just url in AngularJS

Issues:When I am trying following code in AngularJS, it works but opening new window with url like below 

http://localhost/pages/www.facebook.com

JS File
  $scope.OpenWindow = function (url, _blank) {
         window.open(url, '_blank', 'heigth=600,width=600');
     }
HTML File

 img class="FacebookIcon" ng-click="OpenWindow('www.facebook.com')"

Solution: Add 'http://' in the url

JS File
  $scope.OpenWindow = function (url, _blank) {
         window.open( "http://" + url, '_blank', 'heigth=600,width=600');
     }

It will work and open  https://www.facebook.com

Friday, June 30, 2017

.NET Core 1.0.1 Entity Framework – Scaffolding

If you are using .NET Core version 1.0.1, you might have faced some issues to auto-generate database context and Model. There is one more option available to generate database context using command prompt.  

But you have to take care of adding supported/matched DLL reference from Nuget/Nexus.
Go to “project.json” file and make sure you have added following references

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Entityframeworkcore.Sqlserver": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
    "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

Now go to the folder where “project.json” file exist and open command prompt.
  1. Generate database Model for selected table only
                C:/Ritesh/EFScafoldingDemo:> dotnet ef dbcontext scaffold “Server={db server name},{port number};Database={db name};Trusted_Connection=True;” Microsoft.Entityframeworkcore.Sqlserver –t “Product”,”Order”
  1. Generate entire database Model    
C:/Ritesh/EFScafoldingDemo:> dotnet ef dbcontext scaffold “Server={db server name},{port number};Database= db name};Trusted_Connection=True;” Microsoft.Entityframeworkcore.Sqlserver

There are multiple option available to generate database model for .NET Core entity framework, you can see from Microsoft site for more detail

After above command executed successfully you can see, dbProductContext.db , Product.cs, Order.cs files.

Friday, June 23, 2017

.NET Core or .NET Framework, What is right for your application?

.NET Framework and .NET Core are two choices for building .NET server-side applications. Both share a lot of the same .NET platform components and you can share code across the two. However, there are fundamental differences between the two and based on what you want to accomplish, your requirement your choice will depend. 
You should use .NET Core for your server application when:
  • You have cross-platform needs.
  • You are targeting microservices.
  • You are using Docker containers.
  • You need high performance and scalable systems.
  • You need side by side of .NET versions by application.
You should use .NET Framework for your server application when:
  • Your application currently uses .NET Framework (recommendation is to extend instead of migrating)
  • You need to use third-party .NET libraries or NuGet packages not available for .NET Core.
  • You need to use .NET technologies that are not available for .NET Core.
  • You need to use a platform that doesn’t support .NET Core.