Profi Účtenka Printer hell

I bought a new notebook for my wife for her business, tried to setup the already working Profi Uctenkovka with the printer from her old notebook, but it wouldn’t work.

TL;DR Just add Profi Uctenkovka to the CheckNetIsolation.exe tool via “CheckNetIsolation.exe LoopbackExempt -a -n=”55FF9867.26423387A37DD_rp4kqb6eg96dj””

Profi Uctenka is an app that tracks receipts for entreprenuers. It is quite popular in Czech Republic. Easy to work with. Until you want to connect a printer via USB that doesn’t talk with the app via USB. 🤣

The architecture is like this:
– Profi Uctenkovka – UWP C# app that acts as a TCP/IP Client
– USBPrintServerService – C# Windows Service app that acts as TCP/IP Server
– UsbPrinter.dll – C# Library to handle printing via USB
I don’t know why Profi Uctenkovka did not just use UsbPrinter.dll directly, maybe because UWP doesn’t have access to the USBs, dunno.

After setting it up:
– Install drivers for the printer
– Install Profi Uctenkovka
– Download+Unzip the USBPrinteServer
– Run UsbPrintServer and set the port [9101] for it
– Run Profi Uctenkovka and add printer with ip [] and port [9101]
The “Test Printer” button in the Profi Uctenkovka wouldn’t work.

– There was a weird behavior where the standard scenario – Start PC, Services starts, user logs into Windows and then starts the app and presses the Test Printer button – wouldn’t work. However I found out, that when I restarted the USBPrintServerService, it would actually print! So the actual printer and the printing would work, but the connection via TCP was the problem. Later I found out, that Profi Uctenkovka tries to retry the Test Print indefinitely, that is why after restarting Windows service it went through somehow 😂
– I knew that it would work somehow, because the previous notebook worked with this printer. So I started to dig deeper.
– I poke into the apps if they are C# apps by trying to disassemble them with dnSpy.
– To my surprise and luck, the USBPrintServerService and UsbPrinter.dll were indeed C# apps. However the Profi Uctenkovka is Xamarin.Forms app that is compiled to UWP, Android and Apple apps. The UWP part is not disassembleable.
– I tried to attach debugger to the USBPrintServerService and look what was happening. I was TcpListener started, but the connection wouldn’t go through.
– At first I reproduced the C# code of the USBPrintServerService so that I could debug it more easily. But that didn’t change anything.
– So I tried to mockup new C# Console app that would connect to that service. And it worked straight away.
– Here I tried to look at the communication via WireShark on the loopback interface with [tcp.port == 9101] filter.
– The ConsoleApp+MyNewService were sending standard TCP/IP SYN and SYN+ACK packets, everything normal.
– However the ProfiUctenkovka+MyNewService would only send SYN from the client and it would not arrive to the MyNewService. In the wireshark there was a “[TCP Retransmission] [TCP Port numbers reused] 59996 → 9101 [SYN] Seq=0 Win=65535 Len=0 MSS=65495 WS=256 SACK_PERM”
– At some point I thought it would be the firewall. But it wasn’t. Tried to disable it and it still wouldn’t work.
– After some searching I found these 2 articles:
In both sources there was basically the same conclusion:
– Check UWP Capabilities to have “privateNetworkClientServer”
– To add “uap4:LoopbackAccessRules”
– To add the Profi Uctenkovka uwp app id in the “CheckNetIsolation.exe” tool
– I looked into the Profi Uctenkovka AppxManifest if there were the capabilities as listed and they were not.
– Here I created new UWP the same way as the ConsoleApp for checking the connection from client side. And after deploying it to my PC it worked immediatelly only with the capability “internetClient” that Profi Uctenkovka already had. => So it had to be something else.
– I then checked the list of apps registered in that “CheckNetIsolation.exe” tool and this new UWP app was immediately there!!!
– So then I tried to find the ID of the Profi Uctenkovka app so that I could add it manually there, found it somehow through “Get-AppxPackage” command
– I Added the Profi Uctenkovka ID into the “CheckNetIsolation.exe” via “CheckNetIsolation.exe LoopbackExempt -a -n=”55FF9867.26423387A37DD_rp4kqb6eg96dj”” => And VOILA it started to work.
– I knew, that UWP apps have sandbox-like isolation from the rest of the computer, but I didn’t know, that they have additional loopback isolation firewall. Funny thing is, that the second scenario with restarting the Windows Service works. Maybe there is a bug in that firewall or something.

On a paper retrospectively it looks easy, but more than 20hours took me to fix this problem. It took quite a toll on my brain. Hopefully in the future I won’t have this problem with it again after writing this article. And hopefully this article will help other people that have the same problem.

Kudos to Ondra and Homie from my workplace for moral and technical support to get through this hell. Thank you! 🧡

Beware of localhost

One day at work we encountered odd bug with our application. It was Windows Service that was client/server for TCP/IP connections.

The bug was that the server part didn’t seem to listen to any connection.

The oddness of this bug was, that this bug occurred only when service started automatically after restarting PC. When we restarted the service it started to work.

My first idea was that somehow DNS service was connected. (thinking back, it was totally stupid from me thinking that) So my first attempt was disabling DNS cache. Obviously that didn’t help.

Secondly I thought that maybe there were some dependent services for network communication which started after our service. So I set our service to start automatically but delayed. This fixed the underlining issue. But obviously I wasn’t satisfied without knowing what was the culprit.

Then I finally remembered that I can enumerate all listening ports. So I did that. First I enumerated when the service didn’t work and then when the service worked. To my big surprise on this port the IP addresses were different… So by taking this into consideration I deduced that network is not immediately connected after restart so our service bound to the wrong network instead of our internet facing IP address.

Good thing that I investigated this further, because If I was satisfied with delayed autostart I wouldn’t find that our server bound on localhost IP. Why binding to specific IP? Why not to listen globally on all networks?

In the end, we changed binding to IP which listens on all networks.

My take from this is to investigate issues into depth and not be satisfied with “just a quick-fix”


Reblog: Deep Synergy Between Testability and Good Design

  • Testable code does not imply Good design.
  • Good design should imply testable code.

But if you think your code base have a Good Design and you can’t easily test your code, then you can be biased about good design from your point of view.

However real good SOLID design imply easily testable code.

Why am I talking about this? Because in video below Michael Feathers really nicely explains that into big depth. After watching this I got a lot of nice guides how to design better for easily testable code.

Enjoy watching it!

Lumia 950 won’t connect to PC

I don’t know how long has it been, that my phone (Lumia 950) wouldn’t connect to my PC. But one day I really needed to copy some photos from my phone (Lumia 950) to my PC. And that damn phone still just wouldn’t connect! So I started my investigation in Device Manager, where there was an Unknown Device of type “MTP Device”. After trying to update that driver I got this:

“INF is invalid”

This also was a case for Lumia 650. The same problem.

Then I started googling and after a few minutes my problem was solved:

This issue was bugging me for weeks or even monts and it took only few minutes to fix it. So if you have some issue that is bugging you a long time, don’t be lazy and give it a few minutes and you might solve it in a few minutes like I did.


Youtube 1.25x speed lagging problem

Funny thing happend to me. I was reinstalling my PC the other day and when I set it up again, I wanted to watch some youtube videos. But when I started to watch them in 1.25x speed or more they were seriously lagging and obviously I didn’t have ANY clue why. So I backtracked some of my steps of installing and setting up my PC. And guess what change fixed that youtube problem… Reverting my Playback Device Advanced Setting Format from 24bit, 192KHz to something lower fixed it. Possibly my default sound card couldn’t handle this much data and youtube was compensating for it by lagging. So the sound card could keep up.

My way of learning

I don’t read books. Heck I’ve read only like 4 books in my life from start to finish. So how do I learn? I watch and listen. It’s that simple! Most often the tempo of the speaker is too slow and my brain is wandering off to other thoughts. So I am compensating that by speeding the video or track up a bit. My best speed-up range is from 1.4x to 1.9x. It depends on how fast can you process the speaker, if he is understandable at that speed and how am I accommodated to that certain speed. I often start slower and then speed up. Then I am 100% on the topic and that is the most effective way for me to learn something.


I am starting this blog because of one person. He has an amazing blog, where he only documents his experiences and it brought me some value. He’s writing it funny, understandable and short as it should be. So let’s hope I will do too.