Monday, March 25, 2019

RegEx: regular expression to copy fields with same name and data type from an object

Often time we need to copy values for objects having same property names and data types. Sometimes this can be done efficiently using libraries such as AutoMapper. However I have found it to be cumbersome to use it and also it adds lot of testing issues like explained at

https://softwareengineering.stackexchange.com/questions/167250/am-i-wrong-in-thinking-that-needing-something-like-automapper-is-an-indication-o

https://cezarypiatek.github.io/post/why-i-dont-use-automapper/

Instead I personally prefer plain old code and have found some useful shortcuts to reduce the efforts.

1) The following regex can be used in Find and Replace window to copy values between two such objects

Find:       [a-zA-Z]* [a-zA-Z]*[\?]? ([a-zA-Z]* ){ get; set; }
Replace:  $1 = SourceObj.$1,

2) Another regex
Find: public (?:virtual )?(?:\w+\<)?\w+\??(?:\>)? (\w+) { get; set; }
Replace: this.$1 = obj.$1;

2) Use custom reflection method as explained at

https://www.pluralsight.com/guides/property-copying-between-two-objects-using-reflection

Although end result by this method is similar to that of AutoMapper, a very big advantage is since we have entire source code in our project, it is easier to debug or add custom functionality to it.

Tuesday, March 19, 2019

Visual studio enable dot net framework source debugging

To enable dot net framework source debugging, enable this option as explained in the following post, and if for some reason it does not work, then export current settings, reset settings and re-import the saved settings.

https://stackoverflow.com/questions/40320257/cannot-find-cs-files-for-debugging-net-source-code

SharePoint Provider Hosted App - SecurityTokenException: Invalid issuer or signature

More often than not, this error simply means that SharePoint client secrets are incorrect. A detailed explanation and steps to resolve this error can be found at 

https://kirkbarrett.wordpress.com/2018/01/19/provider-hosted-app-error-invalid-issuer-or-signature-persists-after-update/

If we are absolutely sure that the client secrets are correct, then a possible reason for this error is mismatch between datetime zones of SharePoint online and Azure servers. Read more information at https://blogs.technet.microsoft.com/sharepointdevelopersupport/2015/03/11/provider-hosted-app-fails-on-spo/

Some solutions for this problem are listed below


  1. If the website is hosted in an azure server, wait for eight hours for the server to be in sync
  2. Remove service principle using Remove-MsolServicePrincipal powershell command in MSOnline Powershell. More information can be found at https://techcommunity.microsoft.com/t5/SharePoint-Developer/Invalid-issuer-o-signature-error-in-SPO-Provider-Hosted-AddIns/m-p/165697#M4444
  3. Use HostedAppHostNameOverride in web.config as described at https://www.credera.com/blog/technology-insights/microsoft-solutions/sharepoint-2013-provider-hosted-applications-windows-azure-paas/ 



SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...