Category Archives: How to

Visual Studio 2017 update 15.9.0 – Package ‘Microsoft.Azure.Storage.Emulator.Msi, version=5.7.0’ failed to install.

Yesterday I had the pleasure to install latest update of VS 2017 15.9.0. Unfortunately at the end I was notified about minor problem I reported here :
https://developercommunity.visualstudio.com/content/problem/381783/packageidmicrosoftazurestorageemulatormsipackageac-13.html

The problem with solution is, that I had nothing more running on my machine (I installed after hours, at home, not to trash bandwidth at work) and that the solution was for a different package. MS guys closed the problem tagging it as duplicate and pointed me to older error report that is closed with result : its already fixed. Thank you MS, very helpful!

While looking at the error, you can see this path :

C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.Azure.Storage.Emulator.Msi,version=5.7.0

I was looking for the package all over the internet, but I was not able to find standalone installer of Microsoft Azure Storage Emulator with version 5.7.0 (maybe just me and there is a common place to find all these packages).

But, if you peek in this folder (with version number at the end), you should be able to find installer there, yay!!!
You won, if you have the problematic installer and can install it by hand :)
Hope this helps.

Kde nájdem informáciu o zvyšnej veľkosti predčasnej splátky bez poplatku v internet bankingu mBank

Chcel by som sa s vami podeliť o jednu drobnosť (iste ide len o glitch) v UX IB mBank ktorá sa zhodou okolností vyskytuje na mieste, kde by ste ju najmenej čakali. Hádate správne, na mieste zistenia výšky sumy ktorú ešte môžete splatiť do konca aktuálneho výročia. V mBank totiž podľa aktuálnych pravidiel môžete splatiť 20% istiny ročne.

OK, takže without further ado, hľadajte tu :

v sekcii Detaily o účte musíte kliknúť na UX element ktorým sa zväčša reordrujú items v liste (červený rámček).

Hľadaný údaj nájdete ako posledný v liste.

Enjoy.

How to convince Facebook to display your panorama pictures like 360 ones

Facebook for some time now has the possibility to upload and display your pictures as 360 ones. But you don’t need to have 360 photos from some special HW camera. All you need to do is to make a big enough photo and tell Facebook to display the photo as 360 one.

I am not sure about the minimal size of picture that could be displayed as 360 but all my old panoramas were OK when I tested.

I found not much relevant articles about this problem but here is one from FB itself that will explain much.
https://facebook360.fb.com/360-photos/

Tool you need :

exiftool – https://www.sno.phy.queensu.ca/~phil/exiftool/

How to :

exiftool -Make=”Apple” -Model=”iPhone 6s” your_photo.jpg

This will add EXIF information to the file, claiming it was created by iPhone with model iPhone 6s. Now I haven’t really investigated about models that are fine for FB. I suppose from before mentioned FB page, FB would be also fine with some 360 camera makers EXIFs.
It is really funny that pictures that are OK in all ways are not displayed as 360 just because of this EXIF.
Maybe some day we will get a checkbox to display our pictures as 360 from some size.

Hope this helps somebody :)

Don’t forget to Automatically Authenticate calls when using Fiddler

I tend to forget some simple things I just don’t use that often.

One of these is when working with some ASP.NET apps which are using Windows Authentication with 401 HTTP Challenge (Kerberos) set like this in IIS manager :

asp dot net iis windows auth sample

For bigger HTTP debugging “jobs” I am using Fiddler, as most of us do. So, if you want to forge a new HTTP request in Composer and see something like this (401 in the lines 14-21) :

calls without automatically authenticate

You clearly need to check Automatically Authenticate in Composer Options tab.

So what do we see here. This is a random session on my dev box. My browser undergo 401 challenge in the step 1 and 2. From there, everything had 200 because we are authenticated. This is done by the browser, “automagically”. I drag and dropped POST request on position 12 to Composer and not checked Automatically Authenticate (I forgot to) and I got all those nice 401s from 14 to 21.

Please note, that even if you drag and drop some request from browser that got 200 from IIS,  the Fiddler will not get 200 also. Fiddler is for IIS just another client, just replaying the very same request will not make it authenticated. This is by design, not a bug.

If you allow automatically authenticate, you will see that you will get 401 at first, but Fiddler will do it’s job and issue another request, which will get 200 this time. Something like this :

calls with automatically authenticate

All requests from that point will get 200.

Hope this helps guys.

Using Azure App Service Web Apps continuous deployment with GitHub organizations

I am using happily deployments from GitHub to Azure functions, but I wanted to use a repo I have in another Organizations collection.
I came across this article : https://azure.microsoft.com/en-us/blog/using-app-service-web-apps-continuous-deployment-with-github-organizations/ which is currently just partially true, because GitHub UI changed a bit.

In Installed GitHub apps where the Azure Management Portal app should be I see 0 apps :
installed github apps

but Authorized OAuth Apps is now the tab where you should go.

authorized oauth apps

and clicking on the name of app (Azure Management Portal) you will now see a list of your organizations that could be granted to be listed in your account (here I already granted access for one ogranization):
github granted permissions

Now in http://portal.azure.com you could see something like this :
azure github with organizations

Where to find audio settings for Skype built into Windows 10

I will just leave this small “note to self” here also for others to ease their pain.

Find out where to change audio settings in built Skype in Windows 10 is not as easy as it looks like.

So here are the steps :

  • Click on your icon in the top left corner (alternatively you can use CTRL+I) – skype_w10_icon
  • Modal window will appear where you can click Settings and you are good – skype_w10_settings

Plan B is to change setting during call :

skype_w10_during_call_setting

Hope this helps.

How to run StyleCop as opt-in feature with msbuild from command line

The tool :

So everyone knows wonderful tool from Microsoft, named StyleCop. StyleCop is a tool that runs against C# code (not against IL assemblies – already build code) and based on rules saved either per machine, or per project (we will show us how to save them per project) gives you feedback , if you violated some of these rules. StyleCop started on codeplex (MS take on similar portal like github) and currently moved to GitHub – https://github.com/StyleCop. If you see closely, on GitHub we have two projects :

We will go down the free path and take a look at first option. There are two plugins I will speak about today :

(please note that in StyleCop repo there is a note about recommendation to use Roslyn based StyleCop from https://github.com/DotNetAnalyzers/StyleCopAnalyzers repo)

So, you can add NuGet StyleCop.MSBuild package and now running msbuild from command line will trigger analysis. Which is what we want on CI server, but not for builds from Visual Studio. You can try to run build from VS and see what happens.

How to turn off StyleCop.MSBuild for VS builds :

After some search on the interwebz I found out, that there is a property StyleCopEnabled in StyleCop.MSBuild.Targets that is set to true if nothing is specified, which we need to set to false as default. So you need to edit your .csproj (or any other .proj file) and insert

<br />
&lt;StyleCopEnabled&gt;false&lt;/StyleCopEnabled&gt;<br />

in some PropertyGroup.

This will enable you to do following thing :

  • run msbuild to trigger just plain old build
  • run msbuild  /p:StyleCopEnabled=true to pass parameter to msbuild that will do the analysis after the build.

If you guess that the first will be “used” when building from VS and second to get analysis on your CI server, you are right :)

And if you questioned yourself, “why not to pass  /p:StyleCopEnabled=false” from VS build, then AFAIK from VS also in 2017 we cant just pass parameters to msbuild. Shame, I know.

How to handle async functions inside constructors in TypeScript

In this post we will discuss some options you have with calling async functions in constructor of your TypeScript classes.

So, first of all – why would you do this? Well, maybe you need some data from a web API to fill the object with data, or you need some input from user, or some API in code from a colleague is async. Reasons may vary, but the problem is still the same :
in TypeScript, you can’t have await statement in constructor, because constructor returns instance of object, not Promise<yourObjectType>. (All of this indeed is tied to current version of TypeScript 2.2. maybe in future with native async/await keywords in JS, things will change).

So, possible solutions depend on what happens in your async functions and if you need results from this call / calls at the time you return the object.

Solutions :

1. Try to avoid async stuff in constructor. As said earlier, constructor is a function, that should initiate the object in some way and return it immediately, not return a promise that has to be awaited. That is considered a bad practice and TypeScript doesn’t allow this. More on this problem here

http://stackoverflow.com/questions/11856778/asynchronous-constructor

http://stackoverflow.com/questions/24398699/is-it-bad-practice-to-have-a-constructor-function-return-a-promise

http://stackoverflow.com/questions/36363278/does-async-await-will-allow-us-to-be-used-on-constructors

So in some sense, need for async stuff in your constructor might be considered code smell, you are doing too much in constructor. Refactor your code.

2. If you want your async code to stay in constructor for some reason, do you need results from async calls? If not and you want to call them and let them just execute, you might consider calling async functions without await. In this way you will unfortunately be unable to receive (await) the result from these calls (values passed back via resolve).
Please note, that this might result in some non deterministic issues because of how JS handles async code and I really don’t recommend this. Also another downside is, that if you would wrap everything inside constructor with try, promises that would be rejected (analogy with throwing exception in async sense will be not caught but become unhandled exceptions).

Your constructor might then look like this :

<br />
class SomeClass1 {<br />
  constructor() {<br />
    getConfirmAsync(&quot;1 - 1&quot;);<br />
    getConfirmAsync(&quot;1 - 2&quot;);<br />
    getConfirmAsync(&quot;1 - 3&quot;);<br />
  }<br />
}<br />

Sample with try/catch block might look like this :

<br />
class SomeClass2 {<br />
  constructor() {<br />
   try {<br />
     delayAsync(3000);<br />
     delayAsync(2000);<br />
     delayAsync(1000);<br />
   } catch (e) {<br />
     console.log(e);<br />
   }<br />
  }<br />
}<br />

No awaits means that code will continue to run and your constructor will finish and hand over new instance of your class sooner than code triggered from constructor will finish its execution. Scary, right? Don’t do it!!!!

Another take on this same approach is to leave an async self executing function in constructor like this :

<br />
class SomeClass3 {<br />
  constructor() {<br />
    console.log(&quot;SomeClass3 - entry&quot;);<br />
      (async () =&gt; {<br />
        try {<br />
          await delayAsync(3000);<br />
          await delayAsync(1000);<br />
          await delayAsync(2000);<br />
        } catch (e) {<br />
          console.log(`catch triggered with exception ${e}`);<br />
        }<br />
      })();<br />
      console.log(&quot;SomeClass3 - exit&quot;);<br />
  }<br />
}<br />

Again, object would return from constructor but it would still lack calls to all async functions but this time, with proper async function, await and try/catch will work. So if for some reason first function would throw, all the others will not be hit (you can try to change the first call from 3000 to 2999 and see the results). Again, this is not recommended!

3. Simple “factory” function :

This is a way you might potentially want to go because it’s the safest one. All calls will be awaited and instance of you class will be in the state it should be.
All logic from constructor would have to be removed and stored in function that will have the logic of preparing object to the right shape. But, it is OK to separate the logic of creation from class to different function/files that knows what to do to make the object “right”?
Also you might want for safety reasons to “hide” somehow the class itself to prevent from instantiation without the factory function.
This could be done by exporting (from module) only interface of the object and “factory” function and not the class itself. Downside is, that all functions that are called in “factory” function need to be also public because “factory” function is not inside the class itself, but it is a separate function.

<br />
//exporting interface so we can work with the object outside<br />
export interface ISomeClass {<br />
	stringPublic: string;<br />
	numberPublic: number;<br />
}</p>
<p>//not exported = not visible<br />
class SomeClass implements ISomeClass {<br />
	public stringPublic: string;<br />
	public numberPublic: number;</p>
<p>	private somePrivateFn() {<br />
		console.log(&quot;this is private fn&quot;);<br />
	}<br />
}</p>
<p>export async function createSomeClassAsync(): Promise&lt;SomeClass&gt; {<br />
	let res = new SomeClass();</p>
<p>	await delayAsync(1000);<br />
	await getConfirmAsync(&quot;1&quot;);<br />
	await delayAsync(3000);<br />
	await getConfirmAsync(&quot;2&quot;);<br />
	await delayAsync(2000);<br />
	res.numberPublic = 1;<br />
	res.stringPublic = &quot;aa&quot;;<br />
	// res.somePrivateFn(); since we are not inside function this would fail</p>
<p>	return res;<br />
}<br />

This is TS that has export and import statements, but in my examples on GitHub I have this implemented without export and import. I can make a sample for you that is using modules (like the one above) but I decides to cut complexity for my readers and not use any bundling tool like webpack or browserify (I recommend webpack over browserify but that is just a matter of taste).
5. You want to hook a browser event inside the constructor , like some ready event or some other that will trigger some async functions once it happened.

Your constructor might look like this :

<br />
function ready(fn) {<br />
    if (document.readyState !== &quot;loading&quot;) {<br />
        fn();<br />
    } else {<br />
        document.addEventListener(&quot;DOMContentLoaded&quot;, fn);<br />
    }<br />
}</p>
<p>class SomeClass {<br />
    constructor() {<br />
        console.log(&quot;SomeClass5 - entry&quot;);<br />
        ready(async () =&gt; {<br />
            try {<br />
                await delayAsync(3000);<br />
                await delayAsync(1000);<br />
                await delayAsync(2000);<br />
            } catch (e) {<br />
                console.log(`catch triggered with exception ${e}`);<br />
            }<br />
        });<br />
        console.log(&quot;SomeClass5 - exit&quot;);<br />
    }<br />
}<br />

I am using a helper function from http://youmightnotneedjquery.com/ to avoid adding jQ to the project, but you get the point.

If my samples doesn’t make sense for you, please to to my GitHub repo, you can find all the code I made as examples can be found there : https://github.com/rostacik/asyncTsCtorSolutions .

If  you have TypeScript installed as global npm package, just type

<br />
tsc<br />

in the root. If you dont have TypeScript installed, you just need to do to install npm packages :

<br />
npm install<br />

and run TypeScript compiler to build all .ts files :

<br />
 &quot;node_modules/.bin/tsc.cmd&quot;<br />

Feel free to ask or discuss in the comments :)

How to filter particular TypeScript errors in build result

Hi interwebz.
I just want to share this short poor man’s fix when migrating TypeScript to filter out some particular errors in TypeScript build.

Why the hell you (might) need it?

So what would be the common use case , why to bother mask/mute errors on build? Compile is the first test our code need to undergo, like first pass of “unit tests”.

Our situation : currently we have a lot of .js files that let’s say most of the time worked and we need to iterate on way to migrate fully from JavaScript only to TypeScript only. So we rename .js to .ts and then we ran into errors like (among others) :

  1. error TS2365 Operator ‘>=’ cannot be applied to types ‘string’ and ‘number’.
  2. error TS2365 Operator ‘==’ cannot be applied to types ‘string’ and ‘number’.
  3.  error TS2345 Argument of type ‘number’ is not assignable to parameter of type ‘string’.

Yes indeed these are against the “logic” of TypeScript – bring types to JavaScript. But I know I want it there for some short timespan. Just to test. I don’t want to wade through 1500 same errors I know I will have to fix, but among them TypeScript also tells me big and real problems, but buried under many same errors about types.

We are not alone in this, more ppl write about it here :
https://github.com/Microsoft/TypeScript/issues/6114

https://github.com/Microsoft/TypeScript/issues/4094

https://github.com/Microsoft/TypeScript/issues/9448

and also here https://github.com/Microsoft/TypeScript/issues/11051

Solution :

So the solutions vary from custom branch of TypeScript as such to stupid grep on the command line output. And since I am on Windows 10 (my dev box) , I chose to stick with PowerShell so this is snippet that should do the job.

Lets say we want to mute TS2365 and TS2345 errors and your TS build gulp task has name someTSBuildTaskName.

PS script – output to some file :

<br />
node .\node_modules\gulp\bin\gulp.js someTSBuildTaskName --color | Select-String -NotMatch &quot;TS2365&quot; | Select-String -NotMatch &quot;TS2345&quot; | Out-File &quot;grepts.txt&quot;<br />

PS script – output just to console (just drop the last part after pipe) :

<br />
node .\node_modules\gulp\bin\gulp.js someTSBuildTaskName --color | Select-String -NotMatch &quot;TS2365&quot; | Select-String -NotMatch &quot;TS2345&quot;<br />

PS: I am calling here the gulp task without gulp installed with -g flag (global) so you can just call

<br />
gulp someTSBuildTaskName<br />

with globally installed gulp and you are also good to go.

Found any better solution? Pls let us know in comments! :)

AD: you can also use this console log parser on Jenkins:

Regular Expression :

<br />
([\w\\\.]+)\((\d+),\d+\):\s+\w+\s+((?!TS2365|TS2345)\w+):\s+(.*)$<br />

Mapping Script :

<br />
import hudson.plugins.warnings.parser.Warning</p>
<p>String fileName = matcher.group(1)<br />
String line = matcher.group(2)<br />
String category = matcher.group(3)<br />
String message = matcher.group(4)</p>
<p>return new Warning(fileName, Integer.parseInt(line), &quot;TS Error&quot;, category, message);<br />

and plug this into your build pipeline.

How to use NuGet packages even with PowerShell projects with Visual Studio 2015

Most of developers doesn’t use PowerShell on day to day basis, but Microsoft in Visual Studio 2015 made it 1rst class citizen by making PowerShell Tools for Visual Studio 2015 plugin optional on install. (Before that, we had just optional plugin for VS 2013 and VS2012 by same author).

More on this here : http://blogs.msdn.com/b/powershell/archive/2015/04/19/do-not-delete-publish-powershell-tools-for-visual-studio-now-available.aspx

and here

https://channel9.msdn.com/Shows/MsftPowerShell/Visual-Studio-2015-PowerShell-Tools-Overview

and would all be good, but there is still one downside and that is :

you can’t use NuGet packages in PowerShell projects in VS2015 (at least that is how stuff works on my machine). I am really not sure, if this “feature” was introduced with VS 2015 or with NuGet 3.x, but my project worked with VS 2013 + plugin for VS2013.

On my dev box I get error like this one when trying to right clicking References and Manage NuGet Packages…:

powershell nuget error menu

and like this one using Package Manager Console :

powershell nuget error console

The problem is, that it seems like NuGet doesn’t support .pssproj projects, so however your project contains packages.config it will be ignored and you will not be able to update packages. You will have track what you installed and reinstall same version, but you will not be able to update these. Which is quite shame.

There is currently no simple solution to this but you can do these workarounds :

Solution 1 :

If you have small number of packages, install them by hand from command line with help of command line NuGet.

  • download NuGet.exe from https://www.nuget.org/  ,
  • cd to directory where NuGet.exe is (or if you have NuGet.exe in your PATH, you don’t need to cd),
  •  nuget install package_name -o “path_to_packages_folder_or_folder_where_to_store_packages” – which will install latest version of package you want,
  • use the package

You can indeed make a shell script for this. With this solution, the shell script will hold the information about packages you need/want to have installed.

Solution 2 :

If for some reason you want to preserve packages.config file, than you will have to manually update latest versions of packages it contains (since update is not working). Then this file will bear the information about what packages NuGet will install/restore. If this is your way to go, you can follow these steps :

  • download NuGet.exe from https://www.nuget.org/  ,
  • cd to directory where NuGet.exe is (or if you have NuGet.exe in your PATH, you don’t need to cd),
  • update the packages.config file with latest version numbers from https://www.nuget.org/  ,
  • nuget install “path_to_packages.config\packages.config” -o “path_to_packages_folder_or_folder_where_to_store_packages”,
  • use the package

All these solutions are for for scenarios where you need NuGet packages in Packages folder (inside solution folder).

But what there is another way, if you can install chocolatey on you dev box and if you can find in chocolatey repository the package you need.

Then you can do this :

Solution 3 :

  • install Chocolatey from https://chocolatey.org/,
  • run “choco install package_name” (choco should also make sure your new tool will be in PATH),
  • use the package

I would suggest you will make a shell script and automate install of your packages. Again, the file that will hold the information about packages is the shell script.

And if you ask, what is the reason for all this, what NuGet package you might want to use in PowerShell project, my answer is : https://github.com/pester/Pester

Hope this helps,

Dušan