Shane Ray – Invisible Character Visualizer

Background

In this post, we will use Shane Ray’s Invisible Character Visualizer to view non-printable Unicode characters.

Artifacts

As our content contains un-printable characters, it is easier to avail the contents in a file that is easily share-able.

GitHub

As always here we will go with GitHub.

The small sample file is available here :-

unicodeSampleFiles/sql/dbo.customer.sql
Link

 

Text

Here is the text we will be working with :


USE [tempdb]
GO

/****** Object:  Table [dbo].[customer‬]    Script Date: 6/19/2019 8:52:08 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

Usage

Shane Ray

Invisible Character Visualizer

Visual Studio – Visual Studio Community Edition 2017

Launched Visual Studio 2017 Community Edition.

Original View

Here is the original view in Visual Studio
usage.01.20190622.0857AM

 

Outline

Let us install and use the Visual Studio Extension :-

  1. Access Visual Studio Gallery
  2. Install
    • Choose the Visual Studio Installs to target
  3. Launch Visual Studio
  4. Load Files

Access Visual Studio Gallery

artifact.20190622.0901AM.PNG

Install

Install downloaded Visual Studio Extension

It is easy enough to launch it just like any other application.

Screen Shots
Invisible Character Visualizer – Install

install.20190622.0534AM.PNG

Invisible Character Visualizer – Installing

installing.01.20190622.0535AM.PNG

Invisible Character Visualizer – Install Complete

install.Complete.01.20190622.0535AM.PNG

File View – Post Install
Image

usage.02.20190622.0914AM.PNG

Extension

We can quickly see the invisible character (0x202C).

Referenced Work

  1. Visual Code Issues
    • noraj
      • Display invisible character #58252
        • Profile :- noraj opened this issue on Sep 8, 2018
          Link
    • Juan Potato
      • View invisible characters #31291
        • Profile :- JuanPotato opened this issue on Jul 23, 2017
          Link

 

Dedicated

We can clearly see that Shane Ray’s Visual Studio Extension, Invisible Character Visualizer, is very capable.

 

MSBuild – Error – ‘error MSB4066: The attribute “Version” in element is unrecognized.’

Background

Wanted to highlight an error one might experience trying to build a Visual Studio Application from the command line.

Error

Error – Image

Error – Text

error MSB4066: The attribute “Version” in element is unrecognized.

Troubleshooting

Google

Googled on the error message and thanks goodness Stack Overflow came to rescue.

The solution is to ensure that one uses a newer version of MSBuild.

In essence locate the ones that come with Visual Studio and not previous versions.

Solution

Outline

  1. Find Visual Studio’s MSBuild
  2. Target the found MSBuild in your build script

Tasks

Find Visual Studio’s MSBuild

Where

Script

setlocal

set "_option=/R"

set "_folder=C:\Program Files (x86)\Microsoft Visual Studio"

set "_app=MSBuild.exe"

where %_option% "%_folder%" "%_app%"

endlocal

Output
Output – Image

Output – Text
>findVSBuild.cmd

>setlocal

>set "_option=/R"

>set "_folder=C:\Program Files (x86)\Microsoft Visual Studio"

>set "_app=MSBuild.exe"

>where /R "C:\Program Files (x86)\Microsoft Visual Studio" "MSBuild.exe"
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe

Explanation
  1. Found MSBuild.exe under Visual Studio 2017
    • C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe

Target MSBuild in Build Script

Script


setlocal

	set "_folder=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\"

	set "_file=msbuild.exe"

	set "_solution="

	"%_folder%"\%_file% %_solution% /p:configuration=debug

endlocal

pause

Credit

Crediting Martin Ullrich.

As always via Via Stack-overflow (  here ).

Looks like you are not building using the MSBuild.exe that is included in VS 2017 (/ build tools) but rather the MSBuild.exe that ships with .NET Framework, which is an old version (and won’t be updated).

 

Visual Studio.Net – Build Error – “Error CS0229 Ambiguity between …”

Background

Experiencing error building a project in Visual Studio.

Error

Error Image

 

Error Message

  1. Error CS0229 Ambiguity between ‘_jobSummary’ and ‘_jobSummary’
  2. Error CS0121 The call is ambiguous between the following methods or properties: ‘ExecJobActionAsync(Func<DbConnection, Task<int>>)’ and ‘ExecJobActionAsync(Func<DbConnection, Task<int>>)’
  3. Error CS0229 Ambiguity between ‘IsEnabled’ and ‘IsEnabled’
  4. Error CS0229 Ambiguity between ‘IsRunning’ and ‘IsRunning’

 

Troubleshooting

After a full day’s work, realized that the source of the problem is that I had backed up one of the source code files before editing it.

Unfortunately, the backup file was placed in a folder underneath the project’s working directory.

Remediation

To correct please do one of the following :-

  1. Move the folders and files outside of the project’s working directory
  2. Explicitly exclude the folder or file from the project

 

Visual Studio .Net Project

Outline

  1. Choose the folders or files to exclude
    • Right click on your selection
    • From the drop-down menu, please choose Exclude

Image

Image – Exclude From Project ( Initiate )

 

Image – Exclude From Project ( Completed )

 

Review

Project

To review included and excluded files you can do the following :-

Outline

  1. Ensure that Solution Explorer is tailored to show all files
  2. Review each .csproj file

 

Image

Solution Explorer

Image – Show All Files

 

Project File ( .CSProj )

Image

Explain

  1. Upon reviewing the .csproj file we notice the following
    • A new ItemGroup
    • The Item is tagged with “Compile Remove

 

Summary

Please be careful where you place copied files as it might inadvertently be included in your project.

Visual Studio – Xamarin – Traffic Light

Background

Here we go with our first small CSC 101 application in Xamarin.

Outline

  1. addControls
    • instantiate Button Object
    • If in manual mode
      • Add event handler for Button Click
    • Instantiate StackLayout
      • Add Button
  2. OnButtonClick
    • handle buttonclick event
      • call triggerNextState
  3. triggerNextState
    • Call Device.BeginInvokeOnMainThread
      • Have next method be processed on main thread
  4. reflectState
    • Update Button Text
    • Base next procession based on whether manual or automated
      • Enable Button
      • Update Button Background Color
  5. initializeData
    • Instantiate each trafficLightState
    • Add trafficLightState object to collection list
  6. initializeTimer
    • Instantiate timer
    • instantiate Time Event Handler
  7. Process Timer Event
    • call triggerNextState

Code

Add Controls


 void addControls()
{

	btnTL = new Button
	{

		  Text = btnLTText + " " + strMode
		, HorizontalOptions = LayoutOptions.StartAndExpand

	};

	if (bManualOrAutomated == false)
	{
		btnTL.Clicked += OnButtonClicked_btnTL;

	}

	// Assemble the page.
	this.Content = new StackLayout
	{

		Children =
		{
			new StackLayout
			{

				  // Stack Orientation
				  Orientation = StackOrientation.Horizontal

				  // Add Children
				, Children =
				{
					btnTL
				}

			 } // Stack Layout
		} // Children

	}; // Assemble the page.

} // addControls() 

OnButtonClicked_btnTL


void OnButtonClicked_btnTL(object sender, EventArgs args)
{

	Button button = (Button)sender;

	if (button == btnTL)
	{

		triggerNextState();

	}

}

triggerNextState


void triggerNextState()
{

	//prepare for next transition
	iTrafficLightStateCurrent = iTrafficLightStateCurrent + 1;

	try
	{
		Device.BeginInvokeOnMainThread
			(
				() =>
				{
					reflectState();
				}
			);
	}
	catch (Exception)
	{

	}

}

reflectState


void reflectState()
{

	try
	{

		//reset display
		//btnTL.Text = btnLTText;
		btnTL.Text = btnLTText + " " + strMode;

		if (dtSignalTime != null)
		{
			btnTL.Text += " ("
							+ dtSignalTime.ToLongTimeString().TrimStart()
							+ " )"
							;
		}

		btnTL.IsEnabled = (bManualOrAutomated == false);

		//reset marker if at end of line
		if (
				(iTrafficLightStateCurrent > iTrafficLightStatesCountZeroBased)
		   )
		{
			iTrafficLightStateCurrent = 0;
		}

		// get object at current node
		objTLSCurrent = objTLS[iTrafficLightStateCurrent];

		// if valid object
		if (objTLSCurrent != null)
		{

			//set background color
			btnTL.BackgroundColor = objTLSCurrent.color;

		}

	}
	catch (Exception ex)
	{

		//show exception
		btnTL.Text = ex.Message;

		//reset counter
		iTrafficLightStateCurrent = 0;

	}
}

initializeData


void initializeData()
{

	tlStateRed = new trafficLightState();
	tlStateRed.color = Color.Red;
	objTLS.Add(tlStateRed);

	tlStateGreen = new trafficLightState();
	tlStateGreen.color = Color.Green;
	objTLS.Add(tlStateGreen);

	tlStateYellow = new trafficLightState();
	tlStateYellow.color = Color.Yellow;
	objTLS.Add(tlStateYellow);

	// Get Number of Elements
	iTrafficLightStatesCount = objTLS.Count;

	// Get Number of Elements ( 0 Based )
	iTrafficLightStatesCountZeroBased = objTLS.Count - 1;

	// Set Current at 0
	iTrafficLightStateCurrent = 0;

}

initializeTimer


void initializeTimer(Boolean bTimer)
{

	if (bTimer)
	{

		// Create a timer with a two second interval.
		objTimer = new System.Timers.Timer(lSecondsInThousands);

		// Hook up the Elapsed event for the timer.
		objTimer.Elapsed += OnTimedEvent;

	}
	else
	{

		if (objTimer != null)
		{

			//unsubscribe
			objTimer.Elapsed -= OnTimedEvent;

			objTimer = null;

		}

	}

	if (objTimer != null)
	{

		objTimer.AutoReset = bTimer;

		objTimer.Enabled = bTimer;

	}

}

OnTimedEvent


private void OnTimedEvent(Object source, ElapsedEventArgs e)
{

    dtSignalTime = e.SignalTime;

    triggerNextState();

}

Source Code Control

GitHub

VS Studio Xamarin Traffic Light
Link

References

  1. Microsoft
    • Microsoft | Docs
      • Docs / .NET / .NET API Browser / Xamarin.Forms / Device / Methods / BeginInvokeOnMainThread
        Link

 

Visual Studio – Installation – Mobile Applications with Xamarin

Background

Last week tackled creating a Windows Service with Visual Studio.

This week wanted to explore creating Mobile Applications with same.

Visual Studio

Product

Our Product is Visual Studio 2017.

Edition

As always, no bootleg, nevertheless Free; as in Community Edition.

Launch

Launched Visual Studio.

New Project

Accessed menu options and chose New \ Project.

Image

Here are the Project Type options :-

NewProject.20181206.0829PM.PNG

Explanation

  1. Project Types
    • Missing
      • Mobile
  2. Framework
    • .Net Framework 4.6.1

 

Remediation

Outline

  1. Exit Visual Studio
  2. Control Panel \ Programs & Features
    • Launch Control Panel
    • Access Programs and Features Applet
    • Visual Studio
      • From  the list of Applications choose Visual Studio
        • Choose to modify Application
          • Select Mobile, specifically Xamarin
  3. Close Installer
  4. Restart Visual Studio

 

Steps

Exit Visual Studio

Exit Visual Studio.

Programs & Features

Launch Control Panel and access the Programs & Features Applet.

Visual Studio Installer

Modify

Let us modify our install.

Workloads

Outline
  1. We will stay on the Workloads tab
    • Mobile Development with .Net
      • Confirm that Mobile Development with .Net is not currently checked
      • Check that option
      • Review additional storage requirement ( 10 GB )
    • Mobile Development with JavaScript
      • Confirm that Mobile Development with JavaScript is not currently checked
      • Check that option
      • Review additional storage requirement ( 17 MB )
Images
Workloads – Original

modify.workloads.20181206.0830PM.PNG

Workloads – Mobile Development with .Net ( Post )

modify.workloads.mobileDevelopementWithNet.20181206.0831PM.PNG

Workloads – Mobile Development with JavaScript ( Post )

modify.workloads.mobileDevelopementWithJavaScript.20181206.0834PM.PNG

Installing

Installing – Images
Image – Close Visual Studio

installing.BeforeWeGetStarted.20181206.0838PM.PNG

Image – Installing – 01

installing.Downloading.20181206.0840PM.PNG

Image – Installing – 02

installing.Downloading.20181206.0854PM.PNG

 

Image – Installing – 03

installing.Downloading.20181206.0901PM.PNG

Image – Installed

installing.Downloading.20181206.0909PM.PNG

Review Installed Components

Relaunched Visual Studio and access Menu/About.

Image

About.20181207.720AM

Explanation

Confirmed the following installed products :-

  1. Xamarin
  2. Xamarin Designer
  3. Xamarin Templates
  4. Xamarin.Android SDK
  5. Xamarin.iOS and Xamarin.Mac SDK

 

Service Application via Visual Studio ( Day 1 )

Background

Let us lay out a lithe Service Application using Visual Studio Community Edition.

Visual Studio

Overview

  1. Install Visual Studio Community Edition
  2. Create New Project ( Windows Service )
  3. Installer Module
    • Add Installer Module
    • Customize Installer Module
  4. App.Config
    • Add Application Configuration Items
  5. Application
    • Configuration Items
      • Read Configuration Items
      • Log Configuration Items
  6. Install Service
  7. Configure Service
  8. Start Service

Download Install

Download & Install Visual Studio Community Edition if you don’t have it yet.

Usage

Create New Project – Service Application

Outline

  1. Create New Project
    • Visual C#
      • Windows Desktop
        • Type :- Windows Service (.Net Framework )

Image

newProject.20181130.0836AM.PNG

Add Installer

Outline

Link

  1. In Solution Explorer, access Design view for the service for which you want to add an installation component.

  2. Click the background of the designer to select the service itself, rather than any of its contents.
  3. With the designer in focus, right-click, and then click Add Installer.
    • A new class, ProjectInstaller, and two installation components, ServiceProcessInstaller and ServiceInstaller, are added to your project, and property values for the service are copied to the components.
  4. Click the ServiceInstaller component and verify that the value of the ServiceName property is set to the same value as the ServiceName property on the service itself.
  5. To determine how your service will be started, click the ServiceInstaller component and set the StartType property to the appropriate value.

Customize Installer

Outline

  1. serviceInstaller
    • Solution Explorer
      • Customize Service Installer Property Sheet
    •  constructor
      • InitializeComponent()
        • Make sure that you preserve the call to InitializeComponent
      • Customize Service
        • serviceName
        • displayName
        • description

Solution Explorer

Service Installer Property Sheet

Outline
  1. Access Solution Explorer
    • Access Item :- serviceInstaller.cs
      • Access Properties page
        • Adjust Service Properties
Image

serviceInstaller.20181130.0634PM.PNG

 

Code


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;

namespace journalBible
{
    [RunInstaller(true)]
    public partial class serviceJournalInstaller : System.Configuration.Install.Installer
    {

        static string appName = "journalBible";
        static string appDisplayName = "journal Bible";
        static string appDescription = "journal Bible Application ( Sample)";

        public serviceJournalInstaller()
        {

            InitializeComponent();

            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

            this.serviceInstaller1.ServiceName = appName;

            this.serviceInstaller1.DisplayName = appDisplayName;

            this.serviceInstaller1.Description = appDescription;

        }

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {

        }

        private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {

        }
    }
}

Configuration

App.Config

Outline

  1. Add appSettings section
    • add Keys
      • smtpServer
      • emailAddress

Code

App.Config.20181130.0235PM

Main Code

Outline

  1. serviceInstaller
    • Methods
      • OnStart
        • Initialize
          • configurationRead
            • read configuration data from app.config file
          • configurationLog
            • write configuration data into Application Event Log

Code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

using System.Configuration;
using System.IO;
using System.Security;

namespace journalBible
{
    public partial class ServiceJournalBible : ServiceBase
    {

        static String strAppName;

        /*
         * Configuration App.Config - ID
        */
        static String ID_STMP_SERVER = "smtpServer";
        static String ID_EMAIL_ADDRESS = "emailAddress";

        /*
         * Configuration in App.Config - Variables
        */
        static String strSMTPServer;
        static String strEmailAddress;

        public ServiceJournalBible()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            initialize();
        }

        protected override void OnStop()
        {
        }

        protected void initialize()
        {

            try
            {

                configurationRead();

                configurationLog();

            }
            catch (Exception)
            {

            }

        }

        /*
         * Get Application Name
        */
        private String getAppName()
        {

            String strAppFriendlyName;
            String strAppName;

            strAppFriendlyName = AppDomain.CurrentDomain.FriendlyName;

            strAppName = Path.GetFileNameWithoutExtension(strAppFriendlyName);

            return (strAppName);

        }

        /*
         * https://docs.microsoft.com/en-us/dotnet/framework/windows-services/how-to-log-information-about-services
        */

        public System.Diagnostics.EventLog customLogging()
        {

            System.Diagnostics.EventLog objEventLog = new System.Diagnostics.EventLog();

            Boolean bEventLogSourceExist = false;

            // Turn off autologging
            this.AutoLog = false;

            strAppName = getAppName();

            // create an event source, specifying the name of a log that
            // does not currently exist to create a new, custom log
            bEventLogSourceExist = System.Diagnostics.EventLog.SourceExists(strAppName);

            if (bEventLogSourceExist == false)
            {
                System.Diagnostics.EventLog.CreateEventSource
                (
                      strAppName
                    , strAppName
                );

            }

            // configure the event log instance to use this source name
            objEventLog.Source = strAppName;

            //objEventLog.Log = strAppName;

            return (objEventLog);

        } //customLogging() 

        protected void configurationRead()
        {

            System.Collections.Specialized.NameValueCollection objAppSettings;

            objAppSettings = System.Configuration.ConfigurationManager.AppSettings;

            strSMTPServer = objAppSettings[ID_STMP_SERVER];

            strEmailAddress = objAppSettings[ID_EMAIL_ADDRESS];

        } //configurationRead()

        protected void configurationLog()
        {

            String strLog;

            EventLog objEventLog;

            objEventLog = customLogging();

            //Set Source Name
            //objEventLog.Source = strAppName;

            //Prepare Log Entry
            if (strSMTPServer != String.Empty)
            {
                strLog = ID_STMP_SERVER + " :- " + strSMTPServer;

                //Write Log Entry
                objEventLog.WriteEntry(strLog);
            }

            //Prepare Log Entry
            if (strEmailAddress != String.Empty)
            {

                strLog = ID_EMAIL_ADDRESS + " :- " + strEmailAddress;

                //Write Log Entry
                objEventLog.WriteEntry(strLog);

            }

        } //configurationLog()

    }
}

Install Service

Outline

  1. use InstallUtil.exe to install Service

Code

Syntax


C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe [exe-name]

Sample


setlocal

	set "_appInstallerFolder=C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
	set "_appInstallerTargeted=InstallUtil.exe"

	set "_appInstaller=%_appInstallerFolder%\%_appInstallerTargeted%"

	set "_appTargetedFolder=bin\Release"
	set "_appTargetedModule=journalBible.exe"

	set "_appTargeted=%_appTargetedFolder%\%_appTargetedModule%"

	%_appInstaller% %_appTargeted%

endlocal

Source Control

GitHub

DanielAdeniji/svcjournalApp
Link

Referenced Work

  1. Microsoft
    1. Docs > .NET > .NET Framework > Developing Windows Service Applications
      • How to: Install and Uninstall Services
        Link
      • How to: Add Installers to Your Service Application
        Link

Visual Studio – Build – Warning – “The referenced component ‘Microsoft.Web.Infrastructure’ could not be found.”

Background

Downloaded a new Application.  One that I will have to build myself.

Launched Visual Studio and issued Build Command via menu.

Error

Ran into build errors.

The first one reads:

The referenced component ‘Microsoft.Web.Infrastructure’ could not be found.

Remediation

Have a lot of work to do this Saturday morning.

And, so let us address.

Package Manager Console

Running Visual Studio 2017 Community Edition, and the steps to access the Package Manager Console are:

  1. Navigate to the top menu
  2.  Menu Item
    • Tools
    • NuGet Package Manger
    • Package Manager Console

 

Install-Package

Code


Install-Package Microsoft.Web.Infrastructure

 

 

Output

Image

Textual
Attempting to gather dependency information for package 'Microsoft.Web.Infrastructure.1.0.0' with respect to project '[ProjectA]', targeting '.NETFramework,Version=v4.5.1'
Gathering dependency information took 120.25 ms
Attempting to resolve dependencies for package 'Microsoft.Web.Infrastructure.1.0.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.Web.Infrastructure.1.0.0'
Resolved actions to install package 'Microsoft.Web.Infrastructure.1.0.0'
Retrieving package 'Microsoft.Web.Infrastructure 1.0.0' from 'nuget.org'.
Adding package 'Microsoft.Web.Infrastructure.1.0.0' to folder '<app>\\packages'
Added package 'Microsoft.Web.Infrastructure.1.0.0' to folder '<app>\\packages'
Added package 'Microsoft.Web.Infrastructure.1.0.0' to 'packages.config'
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0' to <ProjectA>
Executing nuget actions took 5.42 sec
Time Elapsed: 00:00:07.5704133
PM> 

Credit

Crediting Joshua Davis per “FileNotFoundException: Could not load file or assembly ‘Microsoft.Web.Infrastructure“.  Here is the Link.

Joshua Davis’s about page is worthy of good, congratulatory read.  Here is the link to that page.

 

References

  1. NuGet.Org
    • Microsoft.Web.Infrastructure 1.0.0
      • This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time.
        Link
  2. fsprojects/Paket
    • Problem referencing Microsoft.Web.Infrastructure #1393
      Link