Friday, October 03, 2014

VS 2010: The key file may be password protected error When Building

Symptom:

  1. You pulled a fresh project (i.e., the porject you never had on your machine) from a source control such as Git
  2. You build it on Visual Studi 2010 (or even may be later version) and you get the following type of error and cannot proceed.
  3. You know you have the .PFX file in your project.

Error 1 Cannot import the following key file: XYZZY42.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_07B0CF4FE777D718

Root Cuase:


It just simply cannot locate the cached password (I don't know where it stores it.)Fix

If you do know the password and the fix is easy. If you don't know it might as well create another new pfix file of your own.

Steps to Fix:


1. Go to the Property of the Project

2. On the left panel, click Signing

3. Under "Choose a strong name key file" pull it down and select Browse, and select the same key file as indicated. This will prompt you the password and you should be all set to go.



Tuesday, September 09, 2014

Windows 8, IIS WCF Service Fails to Add Service Reference

Symptom,


When I tried to add a WCF Service Reference to a WCF Application hosted on IIS 8 (Windows 8), I got the following type of message,

'http://localhost/MyDataServices/DataService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost/DataServices/DataService.svc'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
If the service is defined in the current solution, try building the solution and adding the service reference again.

Root Cause


The IIS configuration is incorrect or has become corrupted in some ways.

How I Got It To Work Right

  1. Uninstall and Reinstall IIS from Programs and Features
  2. When re-installed the IIS, be sure to restart the computer. The OS will not ask you to restart on re-install, but in my case the IIS was completely stuck.
  3. Next and most important is this, Be sure that in the .NET Framework 4.5 Advanced Services, and under WCF Services, the HTTP Activation is enabled. 


Side Notes/ Don't Go There...

  • First test with the IIS Express built into your Visual Studio. If that does not work, then there can be a coding issue.
  • Do not bother with editing the web.config file yet (to create behaviors and endpoints). The default ought to work.


Tuesday, August 26, 2014

dcm4chee 2.7 Mac OS Mavericks Installation Note

dcm4chee is a DICOM Server system (and a lot more) that runs under Java runtime environment. It can store medical images and send them out in the DICOM format. If you are reading this article, you must have been familiar with the medical imaging environment in your institution, so I am not going much deeper than that.

I had a chance to install dcm4chee on my Mac OS Mavericks today. I would like to supplement the instructions that have been given on their home site. I think following these steps should save you a couple of hours of finding and trying.

JBoss-4.2.3GA Installation

JBoss must be copied from http://sourceforge.net/projects/jboss/files/JBoss/JBoss-4.2.3.GA/
The link on the instructions page is broken.

JDK Related

I have used jdk1.7.0_09. This is available from the Java Download site (note, at this time of writing the latest JDK is Java 8). 

The JAVA_HOME environment variable should be pointing to (for jdk1.7.0._09) to /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home

Note that Contents/Home in the path.

If you are testing this on your own environment, then JAVA_HOME should be set in your ~/.bash_profile file.

So it would add a line that looks like;


export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home

Fix the ARR Schema Creation Script for the Latest MySQL

  • The latest version of MySQL uses engine= instead of type=  You will need to correct this.
  • It is also best to manually create the schema even though the document says it will auto-create, it actually does not.

mysql -uarr -parr arrdb < dcm4chee-arr-mysql.ddl

Sunday, August 17, 2014

CAR IT: Mazda CX-5 Fails Download Text Messages

Symptom:


You have a compatible Android phone (like the MotoX or Galaxy) but the text message download fails. Note that iPhone is not compatible with your Mazda.

Root Cause:


You have too many messages.

Fix:


Remove and clear all previously stored text messages. Keep the limit to about 200 or less.

Note also that having your SMS mode in Hangout or not does not make the difference. If the message count is small enough it will work both ways.

Sunday, July 20, 2014

Understanding the C# Yield

We have all seen the new "yield" keyword in C# at one point or another, but if you are like me, sometimes, we just say, "what's the big deal, I can do that myself" and move on.

But this weekend, I took time to get a bit more understanding of "yield."  I looked around on the net to to see various examples, but none of them still made sense to me.  So I decided to write a bit of code to experiment. The example included on this post contains the complete code that you can run as a console app.

I found that most examples show the use of the yielding function from within another loop, and that did not make much sense to me, since if you do that, then I would think that why not even bother having a separate loop. But hardly no examples showed me to use an Enumerator to iterate through, throughout a part of program, and that's what I plan to demonstrate here.

First, a bit about the example. Let's say that we need a program for the shipping department of a computer store and you want to make sure the employees will not forget to pack each part in the right box. You would have a list of parts like monitor, keyboard etc., and display the instructions what goes where etc.

What I wanted to get out of this example is to see if my assumptions are correct, and in one case I was not, and glad I caught that by writing this example.

So here is what I have learned;

It's a Way To Implement the Deferred Computation Pattern

  • The yield consutruction is probably good for performing complex calculations within a loop and especially the computation for a specific part of iteration is not performed until you request it, you might save resource or time.

    This approach appears to be very effective if I create an Enumerator then use MoveNext() to the next item, and that's where its power lies. For example, accessing a database or looking up something from a web service. You can defer the computation like this just until you call MoveNext(), and you do not need to write a special state management between the calls. Come to think of it, that's how LINQ works and that's the core of IEnumerable is about. Makes sense!

    We can certainly do this without yield, but to do the same thing, I have to keep track of the states and either store them as private data members or in a separate class structure and pass that back and forth. Also some loops take a decent effort to initialize, and in the yeild approach, we can certainly reduce that effort.

    As the functional programming approch recommends, the more states we create and must manage locally, they tend to cause hard-to find/fix bugs.

    So the advantage with this is a much simpler (hence reliable and testable) design.

My Bad Assumption Cleared

  • If you create a foreach loop again, the iteration will reset from the position 0 for each loop. I misunderstood this aspect. I thought if I have left the loop (say picked up first 3 items) and then did another loop for the next set, I thought I can pick up from where I left off. It does not work that way. So you have also been warned now.

The Code

using System;
using System.Collections.Generic;
using System.Linq;

namespace Yield
{
    class Program
    {
        static void Main(string[] args)
        {
            var sample = new YeldSample();
            sample.Run();
        }
    }

    public class YeldSample
    {
        public void Run()
        {
            var packingList = new List<string>
            {
                "A: Memory""A: Disk""A: DVD Drive",
                "B: Display",  "B: Monitor Cable""B: Monitor Power Cord",
                "C: Mouse""C: Memory Card""C: Keyboard",
            };

            var itemCount = 0;
            var iterator = YieldPart(packingList);

            var enumerable = iterator as string[] ?? iterator.ToArray();
            foreach (var item in enumerable)
            {
                Console.WriteLine("{0} Done!", item);
                itemCount++;
                if (itemCount == 3) break;
            }

            Console.WriteLine("\r\nBad Example Below. This will begin the loop from the start again.\r\n");
            itemCount = 0;

            foreach (var item in enumerable)
            {
                Console.WriteLine("{0} packed again!", item);
                itemCount++;
                if (itemCount == 3) break;
            }

            Console.WriteLine("\r\nExample Using the Enumerator\r\n");

            var items = enumerable.GetEnumerator();

            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);

            Console.WriteLine("\r\nTake a break!\r\n");

            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);

            Console.WriteLine("\r\nTake a break!\r\n");

            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);

        }

        public IEnumerable<String> YieldPart(List<String> parts)
        {
            foreach (var part in parts)
            {
                var dest = "";
                if (part.StartsWith(("A:"))) dest = "main carton.";
                if (part.StartsWith(("B:"))) dest = "monitor carton.";
                if (part.StartsWith(("C:"))) dest = "accessory carton.";

                var phrase = String.Format("Put {0} in the {1}", part.Substring(3), dest);
                yield return phrase;
            }
        }
    }
}

Thursday, July 17, 2014

Google Drive Windows & Mac - "Sign into a different account" does not work

Symptom:


You have either left a company that was using the Google Apps, or you may have recently removed a Google Account and then changed to another. Now you try to connect to the Google Drive, it won't let you change the account, instead it remembers your previous account, and clicking the "Sign into a different account" performs nothing.


Do Not Go Down This Route!


First, it took me about 8 hours to solve this fairly serious flaw and I also checked on the net to see if there has been any solutions.

  • There is no need for you to go to the C:\Users... \Drive folder to remove it. 
  • There is no need to uninstall.
  • There is no need to run CC Cleaner
  • There is no need to clear the history of Chrome. It's not where this issue is happening.
  • There is nothing in the registry so don't look there.

Root Cause:


It is the IE caching the log-in credentials. Not the Chrome. But to make the matter worse, you need to log-into the new Google Account in the IE to clear the previous credential that was cached.

The Fix

I will now explain the steps.

First, go to the Internet Options of the IE, then Delete the browsing history.




Now this is the important part. By default "Preserve Favorite website data." You would not want to do that. So you must UNCHECK that box. The illustration below shows it is checked. Again uncheck this (if you know what to do, you could just remove the cookie for your previous account.)


Wait for the cache to be cleared, then, next thing you need to do is to Sign In to Your New Google Account with the User and Password of the new account.




Mac OS Mavericks Procedure (Inconclusive but Worked For Me)


You will run into the identical problem if you also have a Mac. You are also likely to have Safari and Firefox installed, therefore you need to do this with Chrome, Firefox and Safari in that order.

First, clear the stored password from every browser you have.

Then close all the browsers and do the following steps on every browser from Chrome, Firefox and then Safari in that order.

  • Go to http://www.google.com and if it is still logged into a Google account, log out of it and then log back in.
  • Go to http://drive.google.com now and click your profile photo on the top right of the page. If you do, you should see Add Account button. If you do not see this button, log out and log back in. If you have more than one Active account, then you should add those now.
  • Close the browser and do the same to the next browser.
When you are all done with them, you have cleared the any cached log-in information and you can now re-launch the Google Drive app and you should be able to log-in.

You may still get the following dialog box after all of that;




This is due to the leftover config files that's been on your ~/ (home) directory. There are two places
  • Remove everything in the Google/Drive folder  
    • /Users//Library/Application Support/Google/Drive
  • Remove 
    • in /Users//Library/Preferences

    • com.google.GoogleDrive.plist com.google.GoogleDrive.plist.lockfile



Mazda IT: TomTom Navigation Map Starts to Spin Aound For No Good Reason

Symptom

Around June of 2014 or later, your Mazda TomTom (CX-5 in my case) map start to jigger and spin around and also indicate "acquiring a signal."

What Fixed It

Update the firmware on your TomTom, this is possible by going to the TomTom web site and then downloading the TomTom Home software then update the SD card.

Visual Studio 2012 Installation Hangs

Note: You might be wondering why this is about VS 2012 and not 2013. It turns out that I had to install 2012 for a gig that required it, then I ran into this problem.

Symptom:

You started to install Visual Studio 2012 (Pro in my situation). You have tried the Web install as well as the DVD install and it launches the installer, but shortly after there is no window and installation is hang up no matter how long you wait.

Fix:

Uninstall .NET Framework 3.5.1 (or possibly any other ones) before proceeding to start the installer. Your .NET Framework is likely corrupted in the manner that VS 2012 would not work.

Friday, July 04, 2014

IIS 8 - Get 405 (Method Not Allowed) on DELETE

Symptom


You have implemented an Web API interface (in my case Web API 2) for Delete operation. Your GETs as well as POST works, but when you try to execute DELETE, you get a 405 error code.

DELETE http://localhost/MySite/MyApp 405 (Method Not Allowed)

What Worked For Me


Since I have explicitly set up my environment not to get into CORS situation, it was clear to me that something else was an issue. However, if you are using the built-in IIS from the Visual Studio to test your interface, it will come with a special port number and it is highly likely that you are running into the CORS situation so be sure to check that as well.

What fixed was to modify a part of the web.config file in the following manner.


By removing ExtensionlessUrlHandler-ISAPI-4.0_64bit, it started to work.

The Microsoft KB Article http://support.microsoft.com/kb/224609 was most helpful in deriving this solution for me.

According to the above article, the configuration catches "like" configurations first and thus by the time it is at your level of web application, the configuration is basically "messed up."


Side Note


Also, I did not have a proper configuration on my web interface declaration and after above issue was fixed I was starting to get an error code 500. This goes to say that if you get the error 500, the DELETE is trying to execute and you are out of the web.config issue.

In my case, I forgot to add "{id}" in my Route declaration.

      [Route("{id}")]
        [HttpDelete]
        public void Delete(Guid id)
        {


Thursday, July 03, 2014

Super Beginner Guide to AngularJS - Uncaught Object

OK, I will admit. I am just starting out learning AngularJS and already spent numerous hours where an experienced programmer won't step into. Well, just a few months from now, though, I won't be in that situation, nor I would remember the kind of traps I got into. So it's time to blog about them because if I ran into them, you would too.

What to Do If You Get Uncaught Object on Chrome Console

So your text book author said, "you can test in any browser you choose so long as it is Chrome." And you believed it, didn't you. You tried your first program, and you get the following message in the JavaScript console.

Uncaught object
  (anonymous function) angular.js:78
  (anonymous function) angular.js:1751
  ensure angular.js:1675
  module angular.js:1749
  (anonymous function) app.html:9

Unlike a debugging in C# or Java, it does not tell you where and what the issue is. Very frustrating. You even set a breakpoint where the issue was found and it says "missing ngLocale" module to that effect when you have not even plan to reference such a module in your code.

This turns out to be a current (as of July 2014) bug in Chrome. May be it has been fixed by the time you read this, but it goes to say that when debugging JavaScript it might be worthwhile trying another browser than just Chrome. Especially Firefox and IE are great choices as the JavaScript implementation is totally different from Chrome or Webkit based.

Error: [$injector:nomod] Module 'undefined' is not available! You have either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.0-beta.11/$injector/nomod?p0=undefined angular.js
Error: [$injector:nomod] Module 'mtSample' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.0-beta.11/$injector/nomod?p0=mtSample angular.js

Now at least here the debug console output will be more specific as to the nature of the problem. For above example, I have purposely eliminated a comma after "mtSample" from angular.module("mtSample" ["ngRoute"]).

Go Ahead, Try the IE too!

I know, I know, we are supposed to sit and code at Petes with our latest Mac Books and bash the IE ( I am writing this artile on my iMac by the way). But you will be surprised to know how much changes Microsoft has made to embrace the latest open source technology. You can even run Linux on Microsoft Azure now!

So, even on the IE, the message is clear! In fact, it is the cleanest and clearest of all in this specific example. So at least, let's give some hands to the Micrsoft folks. We should not lose a sight that as software engineers our task is to get our job done. I would use any tool I can lay my hands on.



A Side Note - Do Not Mix and Match Angular Libraries

I have accidentally mixed in additional Angular components (like routing package) from the latest into the rest which was in a pervious version. If you do this, you will run into a very similar issue. When in doubt, refresh the complete AngularJS library to the same perstine version.


... to be continued.

Friday, June 20, 2014

Avoiding CORS on localhost testing via Simple Node.js Proxy Server

What Is CORS Anyway?

Before I get deeper into this topic, I just want to tell you a bit about CORS. CORS an abbreviation of "Cross Origin Resource Sharing", and it is described in this Wikipedia Article.  To make a short summary of this issue, basically, what it means is that there is a security mechanism in just about every modern browser that prevent you to perform AJAX requests from a different server than where your original content came from.

For example, a typical tutorial lesson you get from books may require that you have a simple web server running on Node.js (really easy and cool) then a separate database server that's serving up JSON data (for example, via a Deployed service), you would do something like http://localhost:5000 for your web contents and then http://localhost:5500 for JSON data server. That triggers CORS.

Of course, if you ask most experts, they will say, the answer is easy. They will say just enable CORS on the server side. But it is not that simple. This is a blog about answers that experts do not know how to answer after all.

The reason I am writing this article is because I spent a couple of days to explore different ways of resolving this issue when I was writing some local development and testing environment to learn Angular.js

Because of a very specific way Angular.js performs the HTTP Get and Post the JSON data, you will find it difficult to get around CORS issue. There is even an extension in Chrome to allow CORS in Chrome but even with it, the POST part of the equation does not work for me. In my case, even if I (thought) modified the header to do;

Access-Control-Allow-Origin *
It still did not give me the result I wanted. I even read that on Firefox, a * is not even permitted, and that a specific host be specified. Pretty tricky if you want to test various browsers too! (*I even implemented a version of Microsft IIS site with web.config edited to allow CORS with no avail!)

It is also even worse when dealing with a localhost than any other hosts to get around CORS.

The Proxy Based Solution

In my situation, what ended up working the best is to completely avoid CORS altogether and make it look as if the database service is coming from the same server. And as a bonus of using Node.js it is quite easy to implement it.

It is basically the use of proxy-middleware (e.g. npm install proxy-middleware) that solved this. In this case, all of my test implementation files are stored under ./angularjs folder, so for example, http://localhost:5000/app.html will pull the file from ./angularjs/app.html

I then created a Deployd server at port 5500 (i.e., http://loclhost:5500) and I wanted my server to proxy all of these requests to that when an AJAX request is made to http://localhost:5000/db  So this means that when I was originally doing http://localhsot:5500/products to get the Products JSON data, I will request http://localhost:5000/db/products

var connect = require('connect')
    , url = require('url')
    , proxy = require('proxy-middleware')
    ;
var app = connect();
app.use(connect.logger('dev'));
app.use(connect.static('./angularjs'));
var proxyFunc = proxy(url.parse('http://localhost:5500'));
app.use('/db', proxyFunc);
app.listen(5000);

Stupid Side Note:

Actually, when I tried this the first time, it did not work, the POST failed, because I had some leftover modifications like this in my code

      app.config(['$httpProvider', function ($httpProvider) {
            //Reset headers to avoid OPTIONS request (aka preflight)
            $httpProvider.defaults.headers.common = {};
            $httpProvider.defaults.headers.post = {};
            $httpProvider.defaults.headers.put = {};
            $httpProvider.defaults.headers.patch = {};
        }]);

Be sure to back out any attempts you've done to fix the issue.  It should just work with a bare-bone POST call of Angular.js HTTP provider!




Wednesday, June 18, 2014

JavaScript for C# Programmers: Enumerating Properties

JavaScript Tips for C# Programmers


If you are from the C# (C or C++ too) world, mainly and you are planning to dive into more of "current" way of the JavaScript, you'd run into situations where "I can do this in C#" but why not in JavaScript, or what is going on here, it's not possible in C#.  Here are some notes I was taking as I was learning to apply to my situations. I think you are likely looking for the same answers.
Two Key Concepts in Understanding JavaScript Object

As I got up to speed with JavaScript coming from years of C# only programming, it dawned on me that there are two key concepts that really helps to un-do your C#, C++ minds.  The first one is the dynamic aspect of JavaScript, and also the rampant use of in-line function declarations.

It is Dynamic!


The most important thing to be aware of as a C# or C++ programmer is that the language is dynamic. This is very important in understanding the source codes.

For example, you'd be often confused reading lines of code and suddenly you run into a new property like .address in the example below,

myInfo.address = "1234 Main St.";

You could be wondering where is this .address come from? Where is it declared?

The key to understanding this is that the address member was just added now. There is no requirement in JavaScript to declare anything. You just build your object as you go. This approach is so different that even if you understood it first in a textbook, it will catch you off-guard. We are so fixated in the declaration part of it, it is hard to get rid of that thought. (Note there is a type of declaration, in JavaScript but I am not getting into that now.)

The easiest way to understand this in another way is that if you have used C# Dictionary<> then any JavaScript object is the equivalent of  MyObject.

Add("address", "1234 Main St."); In other words, JavaScript objects are nothing but key value pairs of name and objects.
Rampant Use of Function "Pointers or Delegates"

This is also another difficult part to undo your minds.

A JavaScript object can be a function and JavaScript programmer uses almost exclusively of this. And to confuse the matter even more, many of these functions are anonymous functions. And because you can do that a function are defined usually in a context of a function call! This is so widely used that without understanding this, you would not understand the most JavaScript code these days

var  myFunc = function(x) { return x = x + 1; }

is an example of anonymous function that's assigned to a pointer variable (so to speak) myFunc.

So later on the code you can do y = myFunc(2);

I don't like the term "anonymous" function as everything has to have some reference point. In fact, it does have a name in my example, which is myFunc. So whenever you hear about anonymous function, think of it as a function that's assigned to a variable which is like a function pointer in C or C++, or a delegate in C#.

This approach is used very commonly in callbacks.

myCallback(function(data) { ... });

This is same as

var myFunc = function(x) { return x = x + 1; };
myCallback(myFunc)

But it is done "in-line" in the calling parameters, which is especially odd looking with the C#, C++ mindset. But if you accept the fact that you can write a function as a parameter to a call, then it will start to sink in.

How To Access A Property That's All in Numeric String.


Given this is a very esoteric situation, it also illustrates a point that you can simply access any member of an object using the object['memberName'] notation.

Consider this situation (this is from Medical Imaging, DICOM protocol JSON obeject except that I have added 'patientName" to demonstrate the following example.)

theData={
'patientName' : { 'vr' : 'PN', 'Values' : ['Smith^John'] }

  '00100010' : { 'vr' : 'PN', 'Values' : ['Smith^John'] },

  '00100020  : { 'vr' : 'LO', 'Values' : ['123456'] }
}

The above is equivalent of the C# code like this.

public class myData
{
   public patientName = new DataElement();
   public  DataElement 00100010 = new DataElement();
   public  DataElement 00100020 = new DataElement();
};

Of course, this is not an acceptable syntax in C#, but it is in JavaScript it is possible to have something like this (and it is a part of the DICOM Web standard.

The patientName part is easy to get to just say something like myDataInstance.patientName, but if you try to do myData.00100010  it won't accept that (neither in C# nor in JavaScript actually).

Fortunate in JavaScript the objects are accessible as key value pairs and so it is possible to say theData['00100010'] to get to its content.


How About Finding All Its Properties?


You can iterate through

for (var prtop in heData) {
     var name = prop;
     var val = theData[prop];
        }

What is the === Stuff?

Remember, just this important point. JavaScript auto-converts types when doing an "==" comparison, so you can compare a string that just contains digits against an actual number and come out to be equal. === prevents that from happening.

To be continued...