Tuesday, November 24, 2015

First experience with Azure Service Fabric

As a programmer, we all will get excited when we first hear about Azure Service Fabric. Because it provides many thing out of the box which will take considerable amount of time, if we code. Hereafter lets refer it to ASF. Some features are

  • Automatic fail over - If one node fails the requests (even web requests), the service fabric run time will copy our application to another node and traffic will be routed there.
    • Load balancer can never copy our apps
  • If we choose to store our application state with ASF, it will make sure the state if replicated in multiple nodes, if one node fails it moves our data to another node and resume running.
  • During this switches our application will never see failures. (It will retry if one request fails with other node).
  • ASF conducts leader election among nodes to find who can be next master. It depends up the load on different nodes.
  • We can simulate node failure and all in our dev machine itself.

And many...

It was not different with me I jumped into the ASF preview.

Setting up Azure Service Fabric Preview

It was very simple. Get a Windows 8 machine with VS 2015. Install ASF SDK. More details in below link.

There are many samples for ASF out in Github. That is the best place to start ASF. I too started there. As usual hit the first issue

Issue 1 - System.Fabric.FabricConnectionDeniedException

It compiled nicely. The run time exception was as follows.

An unhandled exception of type 'System.Fabric.FabricConnectionDeniedException' occurred in System.Fabric.dll

Additional information: Not authorized to connect

   at System.Fabric.FabricRuntime.Create(Action fabricExitCallback)
   at Microsoft.ServiceFabric.Actors.Samples.Program.Main() in d:\guthub\servicefabric-samples\samples\Actors\VS2013\HelloWorld\HelloWorldActorService\Program.cs:line 16
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Inner exception
{"Exception from HRESULT: 0x80071C43"}
   at System.Fabric.Interop.NativeRuntime.FabricEndCreateRuntime(IFabricAsyncOperationContext context)
   at System.Fabric.FabricRuntime.NativeFabricRuntimeFactory.<>c__DisplayClass1b.<InitializeFabricRuntimeAsyncHelper>b__1a(IFabricAsyncOperationContext callback)
   at System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously)



The exception says I have serious connectivity issues and I turned towards the connectivity side of the story. I thought some ports are not opened for the development Service Fabric run time on my machine as its company machine.

Solution

But after 1 hour, when I looked at the error message I got a click. I am opening VS 2013 sample project in VS 2015 and let me correct that.

Opened correct project in VS 2015 and the issue resolved. This was purely my problem. But Microsoft should have given a meaningful exception something like version mismatch.

Issue 2 - Deployment issue

It compiled well in VS 2015 but it is not able to deploy and run. The exception in the output windows goes as follows

Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.Scripts.ApplicationScriptException


1>------ Build started: Project: HelloWorldApplication, Configuration: Debug x64 ------
2>------ Deploy started: Project: HelloWorldApplication, Configuration: Debug x64 ------
-------- Package started: Project: HelloWorldApplication, Configuration: Debug x64 ------
  HelloWorldApplication -> D:\guthub\servicefabric-samples\samples\Actors\VS2015\HelloWorld\HelloWorldApplication\pkg\Debug
-------- Package: Project: HelloWorldApplication succeeded, Time elapsed: 00:00:01.4545432 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>'D:\guthub\servicefabric-samples\samples\Actors\VS2015\HelloWorld\HelloWorldApplication\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'D:\guthub\servicefabric-samples\samples\Actors\VS2015\HelloWorld\HelloWorldApplication\pkg\Debug' -ErrorAction Stop -DoNotCreateApplication
2>Deploying application...
2>Connecting to the cluster...
2>Get-ServiceFabricDeployedReplica : Node Node.5 is not Up
2>At D:\guthub\servicefabric-samples\samples\Actors\VS2015\HelloWorld\HelloWorldApplication\Scripts\Deploy-FabricApplicat
2>ion.ps1:106 char:12
2>+     [void](Get-ServiceFabricDeployedReplica -NodeName $node.NodeName -Applicatio ...
2>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2>    + CategoryInfo          : NotSpecified: (Microsoft.Servi...usterConnection:ClusterConnection) [Get-ServiceFabricDe 
2>   ployedReplica], AggregateException
2>    + FullyQualifiedErrorId : GetDeployedReplicaErrorId,Microsoft.ServiceFabric.Powershell.GetDeployedReplica
2> 
2>Unregistering application type...
2>Unregister application type succeeded
2>Copying application package...
2>Copy application package succeeded
2>Registering application type...
2>Register application type succeeded
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:15.5324363
2>Exception of type 'Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.Scripts.ApplicationScriptException' was thrown.
========== Build: 1 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========


Spent sometime on the last executed Deploy-FabricApplication.ps1 file. But no chance. Took break. Still no chance. Then decided to learn some theory about Service Fabric and stack overflow. Some days back I have asked in SO about load balancing stateless services. Fortunately there was a reply and it says, we can deploy stateless services to more than one node and load balance the same. There is a config as well to tell how many nodes the application needs to be installed. 

Solution

I am playing around HellWorld Stateless ASF service. When I first installed ASF local cluster, I had stopped one node just to increase performance on the assumption that Why should I test with 5 nodes ? Isn't 4 enough. May be it is trying to deploy to all 5 nodes and it can't do because one is stopped.

Started node 5 and the deploy worked!!!

Issue 3 - Error when debugging...

I run the ASF application from Visual Studio to debug and see the behavior. Visual Studio deploy to the local cluster and just hung for some time then crashes with the below error message.

------------
A 64-bit debugging operation is taking longer than expected.This may be caused by incompatibilities with 3rd party networking software
---------------
Eventually gets into below error
---------------------------
Microsoft Visual Studio
---------------------------
Unable to start debugging 'C:\SfDevCluster\Data\Node.1\Fabric\work\Applications\HelloWorldApplication_App1\HelloWorldPkg.Code.1.0.0.0\helloworld.exe'.

The process has been terminated.

Refresh the process list before attempting another attach.
---------------------------

Tried sometime figuring out what is going on. But less luck. But I was able to run the client application and invoke the service. Yes kind of I am learn it so finally settled without debugging.

Of course I will spend sometime to identify why the debugging it not working. I strongly think that the 4 nodes may be overloading my system and debugger is not able to connect within configured timeout.

References

https://social.msdn.microsoft.com/Forums/azure/en-US/f5d05143-15ce-4685-9899-6b659ffb77a0/debugging-fails-in-vs2015-rc-systemfabricfabricconnectiondeniedexception?forum=AzureServiceFabric&prof=required

Tuesday, November 17, 2015

Adding ReST endpoint/webHttpBinding to an existing WCF service along with basicHttpBinding

The beginning

Long long ago, in the middle of a big system, there was a WCF service who lived happily by serving its WPF based .Net client. When the service is installed in local laptop, it served the requests via net.pipe to the requests in same machine and net.tcp to the requests coming from other machines. When it was in data centers, it was accepting requests in http(s) using basicHttpBinding. In everyplace it was secured with X509 certificates. So it never got attention of attackers. In fact there were no attackers as most of the time it was inside the boundary of corporate network.

Things were good until some crazy boys came up with the idea of converting its huge WPF based business client in to HTML. Though they were excited to create HTML application they were not brave enough to generate HTML inside browser. Instead they tried to create a MVC application from which they called this service and generated HTML to sent to client. Their strategy was to not touch anything much which are working. Just create more things around the existing. Beautiful Open-Closed principle. More than that, their aim was to prove that Yes the WPF based business application can be converted to HTML.

Half the way this leadership of the team go changed. They found that its not good to have all the HTML getting generated at the server side. Why can't we generate HTML / view at client side by calling our little service completely avoiding the intermediate MVC site which was acting like proxy and generated HTML?

It went back and forth. Many meetings held at high level. People debated at high level without looking at the code. Finally in a meeting when the code was exposed in projector, everybody agreed to have a try at client side HTML generation by calling the service.

Minimal changes for ReST

The developers were believing on the policy of "Less code less defects" so they tried to expose service via webHttpBinding with only web config changes though they new the contract needs to be changed. They simply added new endpoint with webHttpBinding.


<service name="WcfService1.Service">
  <endpoint address=""
            binding="basicHttpBinding"
            contract="WcfService1.IService"/>
  <endpoint address="rest"
            binding="webHttpBinding"
            contract="WcfService1.IService"/>
</service>


When they first called our little service via rest endpoint with only web.config changes, the gate keeper WCF framework didn't invoke the service. Instead it wrote the below details in the svclog file.


"The message with To 'http://localhost/WcfService/Service.svc/rest/GetData?value=2' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree."

The developers understood that they missed end point behavior configuration for the new webHttp end point added to the service. They added end point behavior as below and used this in webHttpEndPoint.

<endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp />
        </behavior>
</endpointBehaviors>

After this change they tried to call the service via ReST url. But this time they got another error in the browser.

405 Method Not Allowed

There was no entries in the svclog file. The developers realized that, there is no way to expose a service via ReST using webHttpBinding without a contract change. They did that contract change and compiled the assembly and put into bin folder.

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet]
    string GetData(int value);
}

After that they called the service using direct url and they got the result. Everybody became happy that the service worked. The result was as follows for the URL

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">You entered: 2</string>

But there was one more question. How to use this in browser application where the language is Javascript? If its in JSON, Javascript knows how to process it. They modified the contract again as follows to get in JSON.

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    string GetData(int value);
}

Calling from Javascript

Once they were able to call the ReST url directly from the browser, they used the same url to call from the Javascript code written inside HTML application.


<script type="text/javascript">
    var baseUrl = "http://localhost/WcfService1/Service.svc/rest";
    function testWCFReSTCall() {
        var urlToServiceMethod = getUrlToGetDataMethod();
        
        var xhr = new XMLHttpRequest();
        xhr.open("Get", urlToServiceMethod, false);
        xhr.send();
        if (xhr.status === 200) {
            alert("200" + xhr.responseText);
        }
        else {
            alert("Error on XMLHttpRequest: " + xhr.status + " " + xhr.statusText);
        }
    }
    function getUrlToGetDataMethod() {
        var urlToGetData = baseUrl + "/GetData";
        var urlToGetDataWithParameters = urlToGetData + "?value=2";
        return urlToGetDataWithParameters;
    }
</script>

Tuesday, November 10, 2015

FIPS Again - VS 2015 - An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.CodeAnalysis.Workspaces.dll

Error Context

Recently I got my machine upgraded/re-imaged to Windows 8. Since it is re-imaging with Win 8 image, I need to install Visual Studio versions. Since I am working with VS 2013 and some research is happening around VS 2015, installed both. One main research is going on around Azure Service Fabric. So installed its SDK too. Then tried to open an existing project in VS 2015. As always the first experience was not so smooth. 

The issue is Visual Studio just restarts when I open a code file in the project.

After 3-4 restarts the below exception comes.

An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.CodeAnalysis.Workspaces.dll

Additional information: The type initializer for 'Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticAnalyzerLogger' threw an exception.
System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.CodeAnalysis.Workspaces.dll
Additional information: The type initializer for 'Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticAnalyzerLogger' threw an exception.

Analysis

Step 1

The problem of being a developer caught me as usual. Attached VS 2015 process to VS 2013 for debugging. But it also gives same error.

Step 2

The TypeInitializationException says the type initializer failed. kind of clearly indication that there would be some static things which are getting executed for DiagnosticAnalyzerLogger. 

Since its coming from .Net Compiler Platform and that is open sourced, thought of looking at the source code of DiagnosticsAnalyzerLogger in git.

Yes. There are some smells of static variable initialization.

private static readonly SHA256CryptoServiceProvider s_sha256CryptoServiceProvider = new SHA256CryptoServiceProvider();

Yeah. Something related to security and Win 8 is known for its FIPS. But still don't know whether that is the reason and I should disable FIPS.

Step 3

Next thing obviously is to get the stack track and inner exceptions if any. Since debugging using VS 2013 is not giving more details, started to try with an internal debugger tool to attach into VS 2015 process.

It produced 500 KB of data (exception details) after I attached to VS and opened a project and C# file. Was able to reach to the exception quickly. But getting the inner exception was little difficult. After some time I was able to figure out that as well and it was clear.

Timestamp: 
Message: Type: System.InvalidOperationException
Method: System.Security.Cryptography.SHA256Managed..ctor
Message: "This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms."
Date Time: 

Stack Trace:
System.Security.Cryptography.SHA256Managed..ctor

System.Reflection.RuntimeConstructorInfo.Invoke
System.Security.Cryptography.CryptoConfig.CreateFromName
System.Security.Cryptography.SHA256.Create

System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal
System.Reflection.RuntimeMethodInfo.Invoke
Roslyn.Utilities.SHA256CryptoServiceProvider..ctor
Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticAnalyzerLogger..cctor

As seen in the above log. Microsoft hard coded use of SHA256 Managed version and that is not part of the Windows Platform FIPS validated algorithm list. 

I am not sure whether everybody who install VS 2015 in Windows 8 facing the same issue.

Event Viewer logs

If I am not a developer, may be I would directly goes to the eventvwer and got the below exception immediately.

Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: System.TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticAnalyzerLogger' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
   at System.Security.Cryptography.SHA256Managed..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args)
   at System.Security.Cryptography.SHA256.Create()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Roslyn.Utilities.SHA256CryptoServiceProvider..ctor()
   at Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticAnalyzerLogger..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticAnalyzerLogger.AllowsTelemetry(DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer)
   at Microsoft.CodeAnalysis.Diagnostics.Log.DiagnosticLogAggregator.UpdateAnalyzerTypeCount(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerDriver.<GetAnalyzerActionsAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerDriver.<GetAnalyzerActionsAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Shared.Extensions.DiagnosticAnalyzerExtensions.<GetDiagnosticAnalyzerCategoryAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Shared.Extensions.DiagnosticAnalyzerExtensions.<SupportsSyntaxDiagnosticAnalysisAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer.<ShouldRunAnalyzerForStateTypeAsync>d__64.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer.<ShouldRunAnalyzerForStateTypeAsync>d__63.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer.<AnalyzeSyntaxAsync>d__49.MoveNext()
Stack:
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, System.Action`1<System.Exception>)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.ReportUnlessCanceled(System.Exception)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer+<AnalyzeSyntaxAsync>d__49.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer+<AnalyzeSyntaxAsync>d__49.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetException(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetException(System.Exception)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer+<ShouldRunAnalyzerForStateTypeAsync>d__63.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetException(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetException(System.Exception)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticIncrementalAnalyzer+<ShouldRunAnalyzerForStateTypeAsync>d__64.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetException(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetException(System.Exception)
   at Microsoft.CodeAnalysis.Shared.Extensions.DiagnosticAnalyzerExtensions+<SupportsSyntaxDiagnosticAnalysisAsync>d__2.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task`1[[Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerCategory, Microsoft.CodeAnalysis.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].TrySetException(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerCategory, Microsoft.CodeAnalysis.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].SetException(System.Exception)
   at Microsoft.CodeAnalysis.Shared.Extensions.DiagnosticAnalyzerExtensions+<GetDiagnosticAnalyzerCategoryAsync>d__0.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetException(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetException(System.Exception)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerDriver+<GetAnalyzerActionsAsync>d__39.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetException(System.Object)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetException(System.Exception)
   at Microsoft.CodeAnalysis.Diagnostics.EngineV1.DiagnosticAnalyzerDriver+<GetAnalyzerActionsAsync>d__41.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetResult(System.__Canon)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetResult(System.__Canon)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetAnalyzerActionsAsync>d__8.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetResult(System.__Canon)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetResult(System.__Canon)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeAsync>d__5.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Solution

The solution is same. Just disable FIPS. Earlier it was used as workaround. But now we need to consider as solution.
http://blogs.technet.com/b/secguide/archive/2014/04/07/why-we-re-not-recommending-fips-mode-anymore.aspx

Tuesday, November 3, 2015

Why I recommend Javascript to my wife? And to everybody

Almost everybody who born as human will think about their partners in advance. Only the depth and frequency of thinking might vary. When I graduated and joined first company, I was thinking about a girl who is working in a technology company but not related to software. The reason behind that is, if both of us are in software, we might talk about software development always which will affect some other developments. As I switched companies and when my parents really started searching bride for me, my thought process was different. (Non Indians may not understand what is arranged marriage.Its not at all forced marriage. In our arranged marriage, couples meet twice or thrice alone to talk before they decide to marry. Mostly parents screen the girls first and arrange meetings. More details see wiki).

I was thinking about a girl who knows how software development works or minimum graduated in computer science but not working in software development / coding! Can be computer science teacher in schools or colleges, working in software administration in other industries such as banking to a level of QA in software industry. The reason behind my change was the culture of the company I was working. Most of the days, need to work or I will say need to be in office for more than 12-14  hours. A normal girl who don't know the peculiarities of software development process will have tough time understanding, why I am staying late in the office.

Finally got one who just completed Masters in computer science and offered from Infosys, one of the well known companies for software development. But fortunately or unfortunately after the marriage, the decision has changed to try in teaching field. She got it quickly in a startup engineering college. That college doesn't have computer science dept. But in the first and second years, all the other departments have CS paper. She find it cool teaching C/C++ etc...

The college was far away from where we stayed and it became difficult to travel more than one and half hours when she conceived baby. She had to quit and became house maker. All went well and we now in US obviously she is in H4 jail. Getting into teaching position seemed tough, so she thought of coming again to development. The tough question came. Which language? Which technology & Platform?

When she asked the same to me, I had no confusion on saying 'Learn Javscript'. Not just learn, master it.

Why Javascript?

If we are passionate about software engineering and up to date with the industry this question will be already solved in our minds. For those who are still thinking about learning Javascript, below section s added which explains why to learn Javascript to secure in software development.

Javascript is everywhere

Yes this is the main one reason to learn Javascript. Lets see where all we can run Javascript.
  1. Javascript in web development
  2. With the arrival of faster and multi core processors browsers are now able to render html and process Javascript with very less time. This makes us write javascript driven applications which can run with high response. Another reason is the HTML5 which has more features targeting towards web site to web app transformation. Now we can leverage 3D capabilities via HTML APIs and javascript 3D libraries. It is real and there are many sites out there which uses it. It was not the case earlier. Now we can see lot of process heavy apps are getting written in Javascript and rendered in browser.
    All the mail apps such as gmail, outlook etc...runs smoothly in browser with heavy Javascript. Even there are Javascript based game available which runs smoothly in any average machine.
  3. Javascript in mobile development (cross platform)
  4. Everyone wants to run their application everywhere. But nobody wants to develop more than once. Especially in mobile platform where there are 3 clean leaders whose platforms are not at all compatible except rendering HTML. We can develop apps for mobile in html, but it may not take the capabilities of hardware especially sensors. So selection of mobile platform was very critical in early mobile development. People tried many solutions and one of the best solution is to develop in HTML and Javascript itself and compile into native form. Phonegap is one leading platform in this and there are many technologies in this area.
  5. Javascript in server side
  6. With the launch of Node.JS, Javascript gained popularity in server side as well. It works using chrome V8 Javascript engine and 2 simple C++ libraries for accomplishing event model. It has already proven its scaling abilities and many web apps are already running using it.
  7. Javascript for desktop application development
  8. This is another platform where software is running today and may run for some more years. Earlier there was no popular way to write desktop applications using Javascript. But as of my understanding Microsoft changed the model by bringing support for writing Windows 8 desktop apps using HTML5 and Javascript. They did it in very simple way. Extracted the browser rendering mechanism and hosted it in windows app container. They established binding of native resources / objects into Javascript so that Javascript which is running inside can manipulate anything in the machine. This is what any desktop application platform does.
    But is it not cross platform. We cannot run out Windows 8 application in Linux. It is been addressed by another similar technology named Electron came out from Github. Github used Chromium as their UI container. Chrome already knows how to render HTML and it has good Javascript engine as well. Connected the dots and we got a nice Javascript + HTML based desktop application development platform. Even Microsoft uses this new technology in their cross platform Visual Studio called VS Code.
  9. Javascript for Robotics & IoT / Micro controller boards
  10. Another area where software can run is micro controller boards which is expected to be the heart of IoT. Micro controller means a small computer which has input and out ports, memory and processor to  execute instructions read from memory. Details on what is IoT is available in wiki. In next 5-10 years with the help of IPv6 all the things / devices such as microwave oven, house doors, chairs, tables, fridge,car, medical devices will be connected to internet and all needed to be programmed. If those devices require different languages and tools, it would be difficult to survive both for us as well as companies. Companies needs to hire new people with high salary or spend on training. But the smart people are trying to unify the language and that language is going to be Javascript 99% of time. There are enough controller boards available now which out of the box supports Javascript. eg: Espruino. Even the famous boards such as RapberryPiArduino can also use Javascript. This pretty much shows that robotics programs can be written using Javascript.
  11. Javascript as DSL
  12. Domain Specific Language is everywhere and we use it knowingly or unknowingly. It is not a language by itself. Its the way we model our business domain and expose it to the users. Users can be our fellow team mates or actual users. Once we have our domain objects, the code to manipulate it can be written in any language such as Powershell, Javascript etc...provided there is DSL run-time to execute the DSL scripts from our host application. In fact if we think deep we can realize that in browser we are using Javascript as DSL and the domain objects are the HTML elements and web request. Similarly when it comes to Node.JS same Javascript and engine process different set of domain objects which are nothing but the server side resources such as files, databases etc...
Are there any other areas left where software runs?

Javascript language has less and rest done by frameworks & engines

The core language is always simple with functions as first class citizens. It can simply do manipulations and call methods on the objects which are passed into it during run-time. But its getting all things done and run everywhere with the help of libraries, frameworks and run-time engines.

If it is running in browser the objects passed to it are the DOM, XHR etc...If its running in server side as Node.JS the objects are http request, http response, database driver, file system object etc...If its in mobile the objects available are the sensors, phone calling and messaging system, file system inside mobile, network IO, display provider etc...finally if its running as DSL, the objects passed are the domain objects such as list of customers, employees which are specific to the business.

Why we need to be masters?

Anybody can write code in Javascript and people were surviving because javascript was mainly used to get some interactivity to the web pages. More than that, it was used to implement kind of 'nice to have' features such as client side validation where we already have a server side validation. Even if the Javascript is disabled at client side our web sites should work. In another words, as a second class citizen. The main reason was slow internet connectivity and even if someone tried to develop Javascript driven web site, the chances for a large crowd using it was very low. Because most of the public had no good connectivity. And due to that reason obviously nobody put attention to improve the Javascript language specs as well as the run-time engines. Big issue was, the rendering browsers were not standardized. If we wanted to make Javascript run in all the browsers, we had to work lot and often will miss deliveries.

But now as we seen earlier things are different. Internet connections became faster. People foreseen the change and they put effort in standardizing the browsers, improved the language specs and engine. Finally framework development started which ensured the compatibility among browsers. We got confidence that our code will work in all the browsers, if we use these frameworks such as jQuery . That enabled us to focus on the features instead of spending time on compatibility issues.

Web sites to web applications

Another important change which already seen is the shift from web sites to web apps. Earlier web development means creating bunch of web pages which will be delivered to browser in the form of HTML. Whether we use ASP.Net, PHP or Java all were just mechanism to generate pages dynamically. The business always remained in the server side. One of the belief was Javascript is not secure and we should never keep our business in it.

But now things changed. The server side slowly retired from its web page generation and business logic container duties and the new role is 'web service' or data provider. If the server just keep the data we can develop application in any client device provided there is a constant connectivity to the server and secure communication mechanism. Connectivity now is not at all a problem. Security is enforced via secure communication protocols such as TLS.

Need for writing good Javascript code

If we agree or not Javascript is everywhere. It is now becoming essential part of our application. In such a scenario, if we don't write the application well, it going to fail. As we all know we are paid to develop applications which works and scale. Due to lack of Javascript knowledge, in the earlier days  the failure may happen only to some nice to have client side validations. But in this new era, entire app will not work. If our app is not working, it leads to less revenue to the company and finally it threatens our job.

The natural selection allows only survival of the fittest species. Similarly if we don't know Javascript there are high chances that the software evolution may eliminate us from the industry.

I have seen many people sitting in HR and admin sections who were once programmers and they talk about their programming history with proud. Should they be proud of their programming history which they were not able to survive? Sometimes they might have left the software development due to other reasons. Whatever if we don't want to be in same place after 10 years, it is very much advisable to learn how to write quality Javascript code.

Of course if we are into system side programming using assembly,c or c++ or go languages, it may be slightly different.

Javascript has lot of garbage

Though the language is getting improved, lot of frameworks and standardized browsers, writing good Javascript is still hard. It is because the language contains lot of garbage from the past. It is not going to be removed from the language to maintain backward compatibility. ie There are lot of applications written using the existing / bad language features. They are all working because they are expecting the language to work in that specific way eg == and ===. All of a sudden if the language got breaking changes or remove bad features all those applications will stop working. In Javascript versioning is too not possible. If we had below features we could write better Javascript in new version. But unfortunately that is not possible and doesn't makes sense in Javascript world.

<script type='text/javascript' version='6.0'>
//Source which contains new clean Javascript language(where == acts like === and === is removed)
</script>

Due to backward compatibility, there are lot of ways to achieve same thing in Javascript. Some ways, we can simply avoid and some needs to be careful selected.

References

Books

Links


Disclaimer

This doesn't mean that JS will survive for ever. When a better new language is born or existing language is enhanced, we should focus on that. But be assured that at least for next 3-5 years, Javascript will survive. As everybody knows The only thing which don't change is CHANGE.