Thursday, May 10, 2018

Get Assembly Version in .NET Core?


Most enterprise application soon or latter, have a requirement to trace out the version of a currently running application. This post shows few example, which demonstrates how to do this in .NET Core.

 var ver = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;

           
 var attrs = typeof(Startup.GetTypeInfo() .Assembly.GetCustomAttributes(); 

var runtimeVersion = typeof(Startup)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyFileVersionAttribute>();  
var tokens = runtimeVersion.Version.Split('.');  
m_Version = new Version(runtimeVersion.Version)

Wednesday, April 18, 2018

Find events bound on an element with jQuery


First Way:

In modern versions of jQuery, you would use the $._data method to find any events attached by jQuery to the element in question. Note, this is an internal-use only method:
// Bind up a couple of event handlers
$("#foo").on({
    click: function(){ alert("Hello") },
    mouseout: function(){ alert("World") }
});

// Lookup events for this particular Element
$._data( $("#foo")[0], "events" );
The result from $._data will be an object that contains both of the events we set (pictured below with the mouseout property expanded):
Console output for $._
Then in Chrome, you may right click the handler function and click "view function definition" to show you the exact spot where it is defined in your code.

Second way:

  • Hit F12 to open Dev Tools
  • Click the Sources tab
  • On right-hand side, scroll down to Event Listener Breakpoints, and expand tree
  • Click on the events you want to listen for.
  • Interact with the target element, if they fire you will get a break point in the debugger
Similarly, you can:
  • right click on the target element -> select "Inspect element"
  • Scroll down on the right side of the dev frame, at the bottom is 'event listeners'.
  • Expand the tree to see what events are attached to the element. Not sure if this works for events that are handled through bubbling (I'm guessing not)

Monday, April 9, 2018

Git on Bitbucket: Remove passphrase


You can easily remove passphrase of your key by using the following command
ssh-keygen -p
On the first prompt, enter the file path (or press Enter to change the default) Second prompt, enter the old passphrase Next prompt, just press enter to unset the passphrase
Looks like this is the easiest way!

Tuesday, January 2, 2018

C# difference between == and Equals()


== Operator

1. If operands are Value Types and their values are equal, it returns true else false.
2. If operands are Reference Types with exception of string and both refer to same object, it returns true else false.
3. If operands are string type and their values are equal, it returns true else false.

.Equals

1. If operands are Reference Types, it performs Reference Equality that is if both refer to same object, it returns true else false.
2. If Operands are Value Types then unlike == operator it checks for their type first and If their types are same it performs == operator else it returns false.

Wednesday, September 13, 2017

Some helpful interview topics (Differences X VS Y)



IEnumrable VS IEnumarator 
IEnumrable VS IQueryable 
IEquatable VS IEqualityComparer VS IStructuralEquatable 
IComparable VS IComparer VS IStructuralComparable 
Delegates VS Events
Shadowing VS Overriding
Yield
Abstraction VS Encapsulation
Lambda expressions , Action , Func and Predicate
Generics
IOC & Dependancy Injection
async, await
MVVM, MVC, MVP
TPL
Indexer
Private Constructor
Private Class

Static Class VS Singleton
Culture and UICulture
LINQ: Single vs. First
a.Equals(b) and a == b?
SQL XML - CROSS APPLY V/S OUTER APPLY
Null values are in Sub query...
Diffrence Int32.parse, Convert.ToInt32, Int32.TryParse
Perform shallow copy of an object VS Deep Copy

Monday, September 4, 2017

Static Class VS Singleton



Static Class:-
  1. You cannot create the instance of static class.
  2. Loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
  3. Static Class cannot have constructor.
  4. We cannot pass the static class to method.
  5. We cannot inherit Static class to another Static class in C#.
  6. A class having all static methods.
  7. Better performance (static methods are bonded on compile time)
Singleton:-
  1. You can create one instance of the object and reuse it.
  2. Singleton instance is created for the first time when the user requested.
  3. Singleton class can have constructor.
  4. You can create the object of singleton class and pass it to method.
  5. Singleton class does not say any restriction of Inheritance.
  6. We can dispose the objects of a singleton class but not of static class.
  7. Methods can be overridden.
  8. Can be lazy loaded when need (static classes are always loaded).
  9. We can implement interface(static class can not implement interface).

Thursday, August 24, 2017

Difference between Culture and UICulture


Difference between Culture and UICulture properties in ASP.NET?

CultureInfo class plays an important role for localizing our application pages. Culture is specific in localizing non-visual parts of the page like DateTime, Currency, number formatting etc.
while UICulture is specific in localizing visual part of a webpage like Language being used to display the contents of the web page.

Wednesday, August 23, 2017

WCF Terminology


  • InstanceContextMode
PerSession
PerCall
Single

  • SessionMode
Allowed
NotAllowed
Required

  • ConcurrencyMode
Single
Multiple
Reentrant

  • WCF Throrrling
 maxConcurrentCalls
        maxConcurrentInstance
        maxConcurrentSessions
  • Message Protection  ( ProtectionLevel )
None
Sign
SignAndEncrypt


Saturday, July 29, 2017

The statement "use strict"; : List of features (non-exhaustive)



The statement "use strict"; instructs the browser to use the Strict mode, which is a reduced and safer feature set of JavaScript.

List of features (non-exhaustive)

  1. Disallows global variables. (Catches missing var declarations and typos in variable names)
  2. Silent failing assignments will throw error in strict mode (assigning NaN = 5;)
  3. Attempts to delete undeletable properties will throw (delete Object.prototype)
  4. Requires all property names in an object literal to be unique (var x = {x1: "1", x1: "2"})
  5. Function parameter names must be unique (function sum (x, x) {...})
  6. Forbids octal syntax (var x = 023; some devs assume wrongly that a preceding zero does nothing to change the number.)
  7. Forbids the with keyword
  8. eval in strict mode does not introduce new variables
  9. Forbids deleting plain names (delete x;)
  10. Forbids binding or assignment of the names eval and arguments in any form
  11. Strict mode does not alias properties of the arguments object with the formal parameters. (i.e. in function sum (a,b) { return arguments[0] + b;} This works because arguments[0] is bound to a and so on. )
  12. arguments.callee is not supported
[Ref: Strict modeMozilla Developer Network]

Wednesday, July 5, 2017

SOLVED: System.IO.FileLoadException exception by unblocking the files


When I was trying to uninstall windows service using InstallUtil.exe (This can also happen when you try to install a windows service). I was getting an error. Please read the complete story.

The command I was trying was,

installutil -u  SearchIndexService.exe

The error was,

Microsoft (R) .NET Framework Installation utility Version 4.0.30319.17929
Copyright (C) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.IO.FileLoadException: Could not load file or assembly 'IDM365SearchIndexService.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515).

After lot of research on internet I have found following solution, You need to run following power shell command for the folder where you want to do the operation.

 get-childitem -recurse *.* | Unblock-File

The command simply unblocks the file.

You can verify the problem & solution by looking at the properties of the target file. it should show something as highlighted in following image.



After you run the command   get-childitem -recurse *.* | Unblock-File it should disappear.
After all this exercise you should be able to install/uninstall windows services.

Thanks
Happy Programming :)