<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SOCAR</title>
    <description>The latest articles on DEV Community by SOCAR (@socar).</description>
    <link>https://dev.to/socar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F979247%2F1d1bf6ce-1405-40fb-8b01-d561397287d1.png</url>
      <title>DEV Community: SOCAR</title>
      <link>https://dev.to/socar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/socar"/>
    <language>en</language>
    <item>
      <title>What font `2600` mag use ?</title>
      <dc:creator>SOCAR</dc:creator>
      <pubDate>Mon, 17 Nov 2025 14:40:34 +0000</pubDate>
      <link>https://dev.to/socar/what-font-2600-magazine-uses--2c97</link>
      <guid>https://dev.to/socar/what-font-2600-magazine-uses--2c97</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;2600 magazine (&lt;a href="https://www.2600.com/" rel="noopener noreferrer"&gt;https://www.2600.com/&lt;/a&gt;) been around for few decades, however I've just recently realized that pages and pages of small text (printed edition is about B5 format?) are pleasure to read. Maybe it's because of high quality of materials from interesting people or maybe it's... font. Quick search in generative language models suggest some sort of TimesNewRoman but not exact match. Opening recent issue PDF in Adobe Acrobat Reader lists a hefty amount of fonts that you would need to go one by one and eyeball for a match. So question is what font  for given text in PDF is used? There is another way...&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Writing a python script that uses &lt;code&gt;PyMuPDF&lt;/code&gt; &lt;a href="https://pymupdf.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;https://pymupdf.readthedocs.io/en/latest/&lt;/a&gt; quickly gives you which font is used on exactly what piece of text on page of your choice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fitz&lt;/span&gt;  &lt;span class="c1"&gt;# PyMuPDF
&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fitz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;2600.pdf&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# page 1 (0-based)
&lt;/span&gt;
&lt;span class="n"&gt;text_dict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dict&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;text_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;blocks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;spans&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]):&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;font&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;size&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gives you nice view what font is used and where &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfq6e5bji0636umrosle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfq6e5bji0636umrosle.png" alt="Font information" width="800" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Answer
&lt;/h2&gt;

&lt;p&gt;2600 magazine uses &lt;code&gt;TimesLTPro&lt;/code&gt; size of 8.6pt for their articles. That's it, roll credits. &lt;/p&gt;

&lt;h2&gt;
  
  
  but...
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;TimesLTPro-Roman&lt;/code&gt; is the PostScript font name of the Roman style in the Times LT Pro family. Vendors and "foundries" (I imagine it's common in some communities to call "foundry" some place font originates) show such font as “Times LT Pro Roman”. Also there's a lot of variations of Times New Roman across operating systems and embedded fonts that are being sold on the market. Lets dive deeper.&lt;/p&gt;

&lt;p&gt;PDF File produced by 2600 have quite few fonts embedded. Not sure if all of those are used however I'm focusing only on one we read mostly in the magazine, as previously identified &lt;code&gt;TimesLTPro-Roman&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fihfa0ebfdersi77o7hp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fihfa0ebfdersi77o7hp3.png" alt="font details" width="795" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's object number 619 embedded in the pdf file, however typical attempt on extracting all items from the pdf, does not produce *619 file.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mutool extract 2600.pdf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;results in missing id:619 object extraction&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3amv3f893l82aco50cbc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3amv3f893l82aco50cbc.png" alt=" " width="800" height="161"&gt;&lt;/a&gt;&lt;br&gt;
To our advantage comes previously used python library: &lt;code&gt;PyMuPDF&lt;/code&gt;&lt;br&gt;
After intalling it with pip it also exposes set of oneliner tools that can be used to extract pdf fonts as well&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pymupdf extract -fonts 2600.pdf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;extracting all 67 fonts (and preserving their names)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttz8o8wevnobdnymj2ir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttz8o8wevnobdnymj2ir.png" alt=" " width="442" height="69"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CFF
&lt;/h2&gt;

&lt;p&gt;CFF is not natively supported under Microsoft Windows. Compact Font Format and TTF (TrueType) are both outline font formats, but they’re built differently: TTF uses quadratic Bézier curves with TrueType hinting, while CFF is a compact PostScript-based format (often seen inside OpenType-CFF fonts) using cubic Bézier curves. TTF became dominant on Windows and the web, but CFF is still in use because produces smaller file sizes, integrates very well with PostScript/PDF workflows, and has long-standing support in professional publishing and print environments—so a lot of high-end text and type foundry workflows still rely on CFF-based fonts.&lt;/p&gt;

&lt;p&gt;To open CFF under windows (or other systems) you can use FontForge &lt;a href="https://fontforge.org/en-US/" rel="noopener noreferrer"&gt;https://fontforge.org/en-US/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to it we can now preview the file and see it's details&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjwko308a9j9g1f5s8x8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjwko308a9j9g1f5s8x8.png" alt=" " width="800" height="806"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article I've shown how to establish what fonts are used in PDF file and their copyright owners. &lt;/p&gt;

&lt;p&gt;From what it seems, this nice looking font, is a professionally licensed and bought product, from another corporation and used since 2014 at least. From legal perspective it's use anywhere outside of agreed terms would be violation, so anyone considering using it for their own benefit would need probably go one and only &lt;em&gt;"the-bay-way"&lt;/em&gt;. &lt;/p&gt;

</description>
      <category>automation</category>
      <category>python</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Error during VMWare installation</title>
      <dc:creator>SOCAR</dc:creator>
      <pubDate>Fri, 05 Apr 2024 14:47:47 +0000</pubDate>
      <link>https://dev.to/socar/error-during-vmware-installation-14ac</link>
      <guid>https://dev.to/socar/error-during-vmware-installation-14ac</guid>
      <description>&lt;p&gt;I'm big fan of VMWare Workstation Player, which allows me to test different software configurations and run older operating systems with ease. However sometimes, during upgrade (or reinstall) of the software I hit following error:&lt;br&gt;
&lt;code&gt;Service 'VMware Authorization Service' (VMAuthdService) could not be installed.&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdbfjuzodqnj1b3b13t79.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdbfjuzodqnj1b3b13t79.png" alt="Error while installing" width="611" height="486"&gt;&lt;/a&gt;&lt;br&gt;
Lets leave this error as it is, and fix the problem, so we can later click &lt;strong&gt;Retry&lt;/strong&gt; and continue the install. &lt;/p&gt;

&lt;p&gt;It seems, VMware Workstation Player setup guide have some issues when uninstalling previous version of the software, causing mentioned service to remain on the system. Usually it's defunct entry in visible in MMC service snap-in, which we can run by typying &lt;code&gt;services.msc&lt;/code&gt; in &lt;code&gt;START -&amp;gt; Run&lt;/code&gt; dialog.&lt;/p&gt;

&lt;p&gt;Usually that screen will be populated with &lt;code&gt;ERROR2: Cant read description&lt;/code&gt; or similar. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbj8wiexfdvryebuh6r1h.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbj8wiexfdvryebuh6r1h.jpg" alt="Error in services.msc" width="800" height="39"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To fix this issue and continue with install we have to get rid of the service. To do that we will use &lt;code&gt;sc&lt;/code&gt; tool:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;Command Prompt&lt;/em&gt; as Administrator&lt;/li&gt;
&lt;li&gt;type in &lt;code&gt;sc delete VMAuthdService&lt;/code&gt; and press ENTER key&lt;/li&gt;
&lt;li&gt;You should see &lt;code&gt;[SC] DeleteService SUCCESS&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Go back to VMware Workstation Player installation and click &lt;strong&gt;RETRY&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6va5es856m6voh5rwlb9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6va5es856m6voh5rwlb9.png" alt="Command to fix the problem" width="507" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Documentation for &lt;code&gt;sc.exe&lt;/code&gt; tool: &lt;a href="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sc-delete" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sc-delete&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Quick Guide to Mouse Clicking in C#</title>
      <dc:creator>SOCAR</dc:creator>
      <pubDate>Sun, 24 Sep 2023 19:41:17 +0000</pubDate>
      <link>https://dev.to/socar/quick-guide-to-mouse-clicking-in-c-oke</link>
      <guid>https://dev.to/socar/quick-guide-to-mouse-clicking-in-c-oke</guid>
      <description>&lt;h2&gt;
  
  
  Clicking the mouse
&lt;/h2&gt;

&lt;p&gt;Clicking mouse in Windows is done using "&lt;a href="https://learn.microsoft.com/en-us/dotnet/framework/interop/" rel="noopener noreferrer"&gt;Windows API&lt;/a&gt;". We will require some methods from Microsoft Windows &lt;code&gt;user32.dll&lt;/code&gt;. Also we need to remember that click is a two stage process: first you click the mouse button down, which generate one event, followed by releasing button (second event). Having said that, here's the steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add &lt;code&gt;using System.Runtime.InteropServices;&lt;/code&gt; to your &lt;code&gt;*.cs&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add two methods from &lt;code&gt;user32.dll&lt;/code&gt; that we will be using:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int 
dy, int cButtons, int dwExtraInfo);
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;mouse_event&lt;/code&gt;&lt;a href="https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event" rel="noopener noreferrer"&gt;(?)&lt;/a&gt; is method responsible for clicking, while &lt;code&gt;SetCursorPos&lt;/code&gt; &lt;a href="https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcursorpos" rel="noopener noreferrer"&gt;(?)&lt;/a&gt; sets mouse cursor where we want on the screen&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We define human readable variables of earlier mentioned two events - LMB_Down and LMB_Up. Its not necessary as we can just provide hex numbers to the &lt;code&gt;mouse_event&lt;/code&gt; function, as well.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public const int LMBDown = 0x02;
public const int LMBUp = 0x04;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now we make a click at screen position x=128 and y=256&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SetCursorPos(128,256);
mouse_event(LMBDown, 128, 256, 0, 0);
mouse_event(LMBUp, 128, 256, 0, 0);
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;and thats it! &lt;br&gt;
Working example: &lt;a href="https://gitlab.com/-/snippets/3602168" rel="noopener noreferrer"&gt;https://gitlab.com/-/snippets/3602168&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Where's my cursor at?
&lt;/h2&gt;

&lt;p&gt;As only few of us have superhuman ability of telling exact x,y  position of the cursor, we can use this piece of code (for example running in separate console app) to tell where the cursor is now at. We still have to use "WinAPI" function &lt;code&gt;GetCursorPos&lt;/code&gt; &lt;a href="https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorpos" rel="noopener noreferrer"&gt;(?)&lt;/a&gt; which returns position result using &lt;code&gt;out&lt;/code&gt; parameter modifier &lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier" rel="noopener noreferrer"&gt;(?)&lt;/a&gt; to a &lt;code&gt;struct&lt;/code&gt; that we will have to create on our own as well.&lt;/p&gt;

&lt;p&gt;Full code of getting the position of the cursor looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.Runtime.InteropServices;
class Program
{
    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(out CursorPos lpPoint);
    public struct CursorPos { public int X; public int Y; }
    static void Main(string[] args)
    {
        CursorPos position;

        do
        {
            if (GetCursorPos(out position))
                Console.Write($"{position.X},{position.Y}\r");
        } while (!Console.KeyAvailable);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gitlab.com/-/snippets/3602169" rel="noopener noreferrer"&gt;gitlab&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>automation</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Data is Null. When "safety" is in the way.</title>
      <dc:creator>SOCAR</dc:creator>
      <pubDate>Mon, 05 Jun 2023 17:39:35 +0000</pubDate>
      <link>https://dev.to/socar/data-is-null-when-safety-is-in-the-way-398a</link>
      <guid>https://dev.to/socar/data-is-null-when-safety-is-in-the-way-398a</guid>
      <description>&lt;p&gt;Back in .NET 2.0, which was my starting point of using .NET stack, &lt;code&gt;null&lt;/code&gt; was important aspect, around which we were building our software architecture, meticulously crafting code that was &lt;code&gt;NullReferenceException&lt;/code&gt; safe. &lt;/p&gt;

&lt;p&gt;Nowadays, new safety features of .NET ecosystem introduced &lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts" rel="noopener noreferrer"&gt;Nullable contexts&lt;/a&gt; which are here to “save” us from need of additional null checking. Sometimes however they can introduce unexpected behavior causing exceptions in places you would not expect. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Project
&lt;/h2&gt;

&lt;p&gt;In below example we track and store followers count of profiles in some generic social network.&lt;/p&gt;

&lt;p&gt;Visual Studio solution is split up in several projects that reuse code between them. It's outline looks like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrj97byja771gs2ou621.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrj97byja771gs2ou621.jpg" alt="Visual Studio solution example" width="392" height="332"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;IFM.BackgroundWorker&lt;/code&gt; is gathering data by scraping the website and using &lt;code&gt;IFM.DBA.MSSQL&lt;/code&gt; saves it to Microsoft SQL Server. &lt;code&gt;IFM.Shared&lt;/code&gt; holds DBO (DataBase Object) used by Entity Framework Context consumed by 3 project: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;IFM.DBA.MSSQL&lt;/code&gt; - access layer to the database&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IFM.BackgroundWorker&lt;/code&gt; - uses &lt;code&gt;IFM.DBA.MSSQL&lt;/code&gt; directly to save the data &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IFM.WebApi&lt;/code&gt; - Reads the data using &lt;code&gt;IFM.DBA.MSSQL&lt;/code&gt; for downstream clients&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;Now lets consider &lt;code&gt;string notes;&lt;/code&gt; A &lt;code&gt;string&lt;/code&gt; can be &lt;code&gt;null&lt;/code&gt; and for decades we used &lt;code&gt;String.IsNullOrEmpty()&lt;/code&gt; to check that. The same goes for databases such as Microsoft SQL Server (MSSQL) which allows you to have a &lt;code&gt;NULL&lt;/code&gt; value in column of &lt;code&gt;NVARCHAR&lt;/code&gt; type&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F15t7obhge6drbhg9tbxl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F15t7obhge6drbhg9tbxl.jpg" alt="Microsoft SQL Server table schema" width="415" height="272"&gt;&lt;/a&gt;&lt;br&gt;
To glue this together in .NET you can use &lt;a href="https://learn.microsoft.com/en-us/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; (EFCore) with &lt;em&gt;Database First&lt;/em&gt; approach creating &lt;code&gt;DbContext&lt;/code&gt; and following DBO:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhw02pbvre8yckyb450c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhw02pbvre8yckyb450c.png" alt="Database Object used by Entity Framework Core" width="534" height="580"&gt;&lt;/a&gt;&lt;br&gt;
Assuming we have some data in the table, we create a method which filters out reports for specific profile using EFCore.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fguctrdqms8xc3awuggf3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fguctrdqms8xc3awuggf3.png" alt="Method fetching filtered data from the database" width="800" height="165"&gt;&lt;/a&gt; &lt;br&gt;
Finally we write the test, expecting everything to be fine... Just getting data for one of profiles.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkkr9enek0iqhwqundyuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkkr9enek0iqhwqundyuz.png" alt="Example test fetching the data" width="614" height="198"&gt;&lt;/a&gt;&lt;br&gt;
And test… fails (as well any implementation of this code in any of the projects). It will throw exception when attempting to create list in &lt;code&gt;GetAllStatsForProfile&lt;/code&gt; method and provide relatively cryptic info about this: &lt;code&gt;System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuw6u36q6g09ax6h85yhe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuw6u36q6g09ax6h85yhe.png" alt="ExceptionScreenshot" width="800" height="308"&gt;&lt;/a&gt;&lt;br&gt;
Reason for this exception is &lt;code&gt;notes&lt;/code&gt; column in &lt;code&gt;FollowersData&lt;/code&gt; table that allows &lt;code&gt;NULL&lt;/code&gt; values. Previously shown &lt;code&gt;FollowersDataDBO&lt;/code&gt; class was coded by hand, however using a &lt;code&gt;dotnet ef dbcontext scaffold&lt;/code&gt; gives same results – creates class that have &lt;code&gt;notes&lt;/code&gt; property not marked as nullable. &lt;code&gt;string&lt;/code&gt; type which can be &lt;code&gt;null&lt;/code&gt; is not "accepting" null coming from the database&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;At this point we are facing a problem not only because exception is breaking execution of the application but how to address it in regards of architecture. In this example, we control the source code, but what if the project would be closed source? &lt;/p&gt;

&lt;h2&gt;
  
  
  The Fix
&lt;/h2&gt;

&lt;p&gt;Here's 3 suggestions how to fix the issue:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Marking &lt;code&gt;notes&lt;/code&gt; property of DBO class to accept &lt;code&gt;null&lt;/code&gt; values
&lt;/h4&gt;

&lt;p&gt;Assuming we can modify the source code of the &lt;code&gt;FollowesDataDBO&lt;/code&gt; class we can mark &lt;code&gt;string notes&lt;/code&gt; property as accepting &lt;code&gt;null&lt;/code&gt; values by adding &lt;code&gt;?&lt;/code&gt; after the type definition. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpt13ljy3xs8s7qk722b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpt13ljy3xs8s7qk722b4.png" alt="Fix1 String Accepting Null" width="440" height="72"&gt;&lt;/a&gt;&lt;br&gt;
Interestingly enough the &lt;code&gt;null forgiving operator&lt;/code&gt; can't be used here (&lt;code&gt;public string notes {get;set;} = null!&lt;/code&gt;) and would not resolve the issue &lt;/p&gt;

&lt;h4&gt;
  
  
  2. Disabling &lt;code&gt;&amp;lt;Nullable&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Disabling null checking by setting in the project file &lt;code&gt;&amp;lt;Nullable&amp;gt;&lt;/code&gt; value to &lt;code&gt;disable&lt;/code&gt; do the trick as well. However it have be done in project which holds the DBO file (and not projects that reference that project), which affect all other projects that might have logic relying on that setting. In our case we would have to modify &lt;code&gt;IFM.Shared.csproj&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8e1f0x26msaww361lm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8e1f0x26msaww361lm9.png" alt="Fix2 Disable nullable" width="467" height="277"&gt;&lt;/a&gt; &lt;br&gt;
Obviously from global perspective we cant predict what impact on projects that reference this and rely on &lt;code&gt;&amp;lt;Nullable&amp;gt;&lt;/code&gt; to be enabled&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Change database schema
&lt;/h4&gt;

&lt;p&gt;Finally, the "worst" approach to fix the issue, that we could introduce, is changing database schema by setting &lt;code&gt;notes&lt;/code&gt; column to &lt;code&gt;NOT NULL&lt;/code&gt; (Allow Nulls = false) but as projects might be dependent on such schema, the introduced risk of breaking change in this case is big.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this example I have shown that new safety features might backfire in specific conditions. Proper design of application as well continuous testing is important to catch such errors on early stage of project development. Such safety features might be also a breaking change while migrating from older .NET stack and cause additional workload while mitigating potential risks and architecture changes. &lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnetcore</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
