<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ferry To on Medium]]></title>
        <description><![CDATA[Stories by Ferry To on Medium]]></description>
        <link>https://medium.com/@ferrywlto?source=rss-f5ada568f082------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wu7dW0z_ut6kn4X8aw_zbA.png</url>
            <title>Stories by Ferry To on Medium</title>
            <link>https://medium.com/@ferrywlto?source=rss-f5ada568f082------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:27:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ferrywlto/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reduce Review Fatigue in the AI Coding Era: My .NET Guardrails]]></title>
            <link>https://ferrywlto.medium.com/reduce-review-fatigue-in-the-ai-coding-era-my-net-guardrails-c91cb8bf4730?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/c91cb8bf4730</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[ai-coding]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Thu, 19 Feb 2026 22:32:04 GMT</pubDate>
            <atom:updated>2026-02-19T22:40:53.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xQrQR4TDSAyS4GwF" /><figcaption>Photo by <a href="https://unsplash.com/@elimendeinagella?utm_source=medium&amp;utm_medium=referral">Elimende Inagella</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the AI coding era, we type less and let the machine do the heavy-lifting.</p><p>However, unlike the productivity boost from compilers, assemblers, linkers, high-level languages and IDEs, LLM output is not deterministic, yet.</p><p>In just a few years, our productivity has shifted from trying to type as fast as we can read and think, to having coding agents generate more code than we can realistically review. If the output quality is poor, it slows us down rather than speeding us up.</p><p>In order to have the LLM to produce production quality code while minimize our mental energy to review the code it produces, setting up good guardrails is essential. Since LLMs don’t get tired, the strictest compiler/analyser rules can detect when the model starts drifting off spec.</p><p>Here I am sharing my .NET project configuration I use in my projects:</p><ol><li>The rules set in Directory.Build.props applies to all projects under that directory tree (and can be overridden lower down).</li></ol><pre>&lt;!-- MSBuild settings that will auto import to each project. --&gt;<br>&lt;!-- Strict Mode --&gt;<br>&lt;Project&gt;<br>  &lt;PropertyGroup&gt;<br>    &lt;!-- Enable nullable reference type analysis and annotations. --&gt;<br>    &lt;Nullable&gt;enable&lt;/Nullable&gt;<br>    &lt;!-- Auto-import common framework namespaces so fewer explicit using directives are needed. --&gt;<br>    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;<br>    &lt;!-- Fail the build when any warning is produced. --&gt;<br>    &lt;TreatWarningsAsErrors&gt;true&lt;/TreatWarningsAsErrors&gt;<br>    &lt;!-- Turn on built-in .NET analyzers. --&gt;<br>    &lt;EnableNETAnalyzers&gt;true&lt;/EnableNETAnalyzers&gt;<br>    &lt;!-- Use the latest analyzer rule set available in the current SDK. --&gt;<br>    &lt;AnalysisLevel&gt;latest&lt;/AnalysisLevel&gt;<br>    &lt;!-- Run all analyzer categories. --&gt;<br>    &lt;AnalysisMode&gt;Recommended&lt;/AnalysisMode&gt;<br>    &lt;!-- Enforce code-style rules during command-line build, not only in the IDE. --&gt;<br>    &lt;EnforceCodeStyleInBuild&gt;true&lt;/EnforceCodeStyleInBuild&gt;<br>    &lt;!-- Produce deterministic binaries for reproducible builds. --&gt;<br>    &lt;Deterministic&gt;true&lt;/Deterministic&gt;<br>    &lt;!-- Apply CI-focused build behaviors (for example, reproducibility/source-link conventions). --&gt;<br>    &lt;ContinuousIntegrationBuild&gt;true&lt;/ContinuousIntegrationBuild&gt;<br>    &lt;!-- Compile integer arithmetic in checked mode to detect overflow/underflow at runtime. --&gt;<br>    &lt;CheckForOverflowUnderflow&gt;true&lt;/CheckForOverflowUnderflow&gt;<br>    &lt;!-- Disallow unsafe code blocks unless explicitly overridden in a project. --&gt;<br>    &lt;AllowUnsafeBlocks&gt;false&lt;/AllowUnsafeBlocks&gt;<br>    &lt;!-- Continue restore if some configured NuGet sources are temporarily unreachable. --&gt;<br>    &lt;RestoreIgnoreFailedSources&gt;true&lt;/RestoreIgnoreFailedSources&gt;<br>    &lt;!-- Emit XML documentation output during build. --&gt;<br>    &lt;GenerateDocumentationFile&gt;true&lt;/GenerateDocumentationFile&gt;<br>  &lt;/PropertyGroup&gt;<br>&lt;/Project&gt;</pre><p>2. We can then fine-tune the rules for specific file/project when needed in .editorconfig :</p><pre>root = true<br><br># Base whitespace/newline defaults for all text files.<br>[*]<br>charset = utf-8<br>end_of_line = lf<br>insert_final_newline = true<br>trim_trailing_whitespace = true<br><br># C# style and analyzer policy.<br>[*.cs]<br>indent_style = space<br>indent_size = 4<br>csharp_new_line_before_open_brace = all<br><br># Prefer explicit type when it improves readability; allow var when obvious.<br>csharp_style_var_for_built_in_types = false:suggestion<br>csharp_style_var_when_type_is_apparent = true:suggestion<br>csharp_style_var_elsewhere = false:suggestion<br><br># Fail for unnecessary usings and unused parameter.<br># IDE0005: Using directive is unnecessary<br>dotnet_diagnostic.IDE0005.severity = warning<br># IDE0060: Remove unused parameter<br>dotnet_diagnostic.IDE0060.severity = warning<br><br># Keep XML docs generated, but do not fail builds for missing public comments.<br># Team can raise/lower this severity later without touching MSBuild.<br>dotnet_diagnostic.CS1591.severity = suggestion<br><br># Non-C# indentation defaults.<br>[*.{json,yml,yaml,md,astro,mjs}]<br>indent_style = space<br>indent_size = 2</pre><p>3. Make use of pre-commit and pre-push git hook:</p><p>.git/hooks/pre-commit:</p><pre>#!/usr/bin/env bash<br># exit on error<br>set -e<br><br>dotnet restore<br>dotnet format --verify-no-changes<br>dotnet build</pre><p>.git/hooks/pre-push:</p><pre>#!/usr/bin/env bash<br># exit on error<br>set -e<br><br>dotnet test --no-build</pre><p>By doing this, you force a coding agent to iterate until the output satisfies the compiler and analyzers — catching drift early.</p><p><strong>You might be surprised: this doesn’t only guard AI-generated code, it also maintains good human development hygiene for engineering excellence.</strong></p><p>Guardrails are only a precautionary measure, though. Security-minded prompting, solid test coverage, and good engineering practices are equally important.</p><p>And you still need human review to ensure no secrets (API keys, tokens, connection strings) slip into the repository.</p><p>See you next time and happy coding! 😀 — I still genuinely enjoy writing code by hand.</p><p>This blog post is also available on my <a href="https://ferrywl.to/blogs/2026/02/2026-02-19-reduce-review-fatigue-in-the-ai-coding-era-my-net-guardrails/">blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c91cb8bf4730" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Last Mile of Quality: Why GenAI Won’t Replace Professionals]]></title>
            <link>https://ferrywlto.medium.com/the-last-mile-of-quality-why-genai-wont-replace-professionals-7b118a5efddd?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b118a5efddd</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[professionalism]]></category>
            <category><![CDATA[accountability]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[career-advice]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 16:41:31 GMT</pubDate>
            <atom:updated>2026-01-05T21:19:48.554Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why GenAI won’t replace professionals — and why the “X is dead” narrative is harmful.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*uUWY46yVKf0K1MCmQCoULA.png" /></figure><h3>Victim of fear propagation</h3><p>I’ve been a paid ChatGPT user since the beginning, and for a long time it was genuinely helpful.</p><p>Then, in early 2024, my social feed changed. Every day it was some variation of the same narrative: “software engineering is finished”; “AI replaces programmers”. It wasn’t a debate any more — it got into my head. I didn’t just feel annoyed. I felt threatened.</p><p>For months, I questioned my own decades of craft and wondered if I was becoming redundant in real time — stuck in loops of self-doubt even while actively learning modern AI tools. I still felt replaceable. It didn’t stay at my desk — it affected my relationship with my partner to the point that we sought therapy.</p><p>What bothered me most is that this fear isn’t limited to software engineers. It hits designers, writers, and musicians — anyone whose work gets reduced to “just waving a magic wand”.</p><p>It took me months to consolidate and organise my thoughts here, and this essay is my pushback: an attack on fear propagation and low-accountability vibe coding, a defence of professionalism, and a practical framework that helped me recover — and might help you too.</p><p>By “<strong>the last mile of quality</strong>”, I mean the final few percent that decide whether something survives in production — where someone is accountable for the consequences.</p><h3>The harmful narrative</h3><p>By “vibe coding”, I mean shipping AI-generated code you don’t truly understand, without the engineering discipline that makes it safe in production.</p><p>Vibe coders claim they can build apps with no technical knowledge, then sell that promise to outsiders — creating the illusion that the world no longer needs software engineers.</p><p>Others go further and claim writers, graphic designers, and musicians are now redundant because AI can generate text, code, images, and music “without learning anything”.</p><p>This narrative is harmful because it reduces every craft to zero. It mocks the years it takes to learn, practise, and master a profession — and it conveniently ignores the one thing that matters most in the real world: production accountability.</p><p>Livelihoods are affected when employers make decisions based on hype rather than reality, and teams end up shipping low-quality work that creates chaos later — security incidents, API key leaks, and outages.</p><p>Most importantly, it forgets one obvious fact: professionals — songwriters, illustrators, designers, and software engineers — use AI too, and they tend to use it better precisely because they understand the craft.</p><h3>The framework that pulled me out</h3><p>Over time, I figured out a simple anxiety-to-clarity framework that helps me handle doom claims and rebuild clarity. I hope it helps you too.</p><h4>Step 1: Separate noise from reality</h4><p>Social feeds reward certainty, not accuracy. Doom claims spread because they’re emotionally sticky — not because they’re careful.</p><p>Treat them as marketing noise by default until they can be verified by the filters described in the next step.</p><p>Curate aggressively. Mute or unfollow accounts that sell certainty, post absolutes, or farm outrage. Keep people who show trade-offs, limitations, and production context.</p><h4>Step 2: Run three filters before you believe anything</h4><p>When a claim shows up in your feed, ask:</p><ul><li><strong>Incentives:</strong> What does the author gain if you believe this — attention, followers, courses, consulting, tool sales? If a message is high-certainty, low-evidence, and perfectly aligned with what the author is selling, treat it as marketing until proven otherwise.</li><li><strong>Production:</strong> Is this about shipping and operating real systems, or just a demo that “runs on my machine”? (demo/benchmark ≠ production)</li><li><strong>Last mile:</strong> Who handles the final few percent — edge cases, security, reliability, maintainability, compliance — and who is accountable when it breaks?</li></ul><h4>Step 3: Respond based on the analysis</h4><p>If a narrative avoids evidence and trade-offs, ignores production realities, and hand-waves the last mile, you should ignore it.</p><p>In the next section, I’ll explain why these narratives look convincing in the first place: Dunning–Kruger, plus the demo illusion.</p><h3>The hype from the demo illusion</h3><p>It’s easy to buy into the vibe-coding vision because the visible part of software is the user interface, not the years of production discipline behind it. If software development looks like “just typing”, then AI looks like replacement.</p><p>So when people see AI generate some React code, run it on localhost, and produce a working screen, they assume the story is finished — and that they’re one step away from a “groundbreaking app” (and becoming a millionaire overnight). That confidence fits a classic Dunning–Kruger pattern: when you don’t know what the hard parts are, you can’t see what’s missing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*OFJfBSTVAcTfR8SKZv_nRw.png" /><figcaption>Dunning-Kruger Effect from Wikipedia CC4.0</figcaption></figure><p>What they’re seeing is a prototype. The missing part is production: security, reliability, scalability, compliance — and the cost of being wrong.</p><p>Coding isn’t just typing. In fact, typing is a negligible part of the job. The value of inputting text has been diminishing for decades since the dawn of the digital world. Software engineering is, at its core, thinking and communication — turning ambiguous needs into reliable systems that survive reality.</p><p>If you apply the same lens, the doom narrative starts to look less like a forecast and more like a misunderstanding of where quality is decided: the last mile.</p><p>AI reduces the cost of prototyping; it doesn’t replace battle-tested professionals who ship production systems and take accountability.</p><h4>Case Study: proving the framework works in real-world doom claims</h4><p><strong>The claim:</strong> imagine a tweet quoting two “authoritative” sources and then concludes: <strong>“Software engineering is done.”</strong>:</p><ul><li><a href="https://fortune.com/2025/03/13/ai-transforming-software-development-jobs-meta-ibm-anthropic/">Anthropic CEO said 90% of code will be written by AI</a></li><li><a href="https://openai.com/index/introducing-gpt-5-2/">GPT-5.2 reached 80% on a verified software engineering benchmark</a></li></ul><p>Now apply the framework:</p><p><strong>Separate noise from reality</strong></p><ul><li>Label it as noise and do not believe it.</li></ul><p><strong>Run the three filters</strong></p><ul><li><strong>Incentives:</strong> engagement (doom spreads), identity signalling (“I’m ahead; you’re behind”), or vendor cheerleading (praising a model/tool)?</li><li><strong>Production:</strong> “90% of code written by AI” is ambiguous. <em>Where is it written, and how is it measured?</em> Is it final code shipped without human refinement after review, testing, and security audit?</li><li><strong>Last mile:</strong> even if a model reaches 80% on an SWE benchmark, that still means 20% fail in a benchmark environment. In production, that remaining percentage is exactly where the harm lives. Even if AI writes 90% of the text, professionals still own 100% of the consequences. Who is responsible for the incident? Can the consequence be fixed or avoid without software engineers?</li></ul><p><strong>Respond based on the analysis</strong></p><ul><li>The tweet has incentives, avoid production realities, ignoring the last mile.</li><li>We ignore it and mute/unfollow the account.</li></ul><p>That last mile — accountability under real constraints — is what doesn’t get replaced by a benchmark score.</p><h3>Professionalism is accountability</h3><p>Any commercial product will face problems such as:</p><ul><li>Security and privacy</li><li>Scalability and performance</li><li>Availability and reliability</li><li>Compliance and regulation</li></ul><p>People don’t pay a lawyer for the act of typing documents. They pay for judgement: the legal advice, the professional standard behind it, and the fact that someone is accountable for the consequences.</p><p>Software engineering works the same way. Our value often comes down to one word: <strong>production</strong>.</p><p>When a production incident happens, you can’t point at the tool and say, “It wasn’t me — AI wrote the code.” Someone still has to own the impact, diagnose the failure, communicate clearly, and fix it safely.</p><p>This is the part that doom narratives and vibe-coding hype tend to ignore: professionalism is not “typing quickly”. It’s the discipline of delivering systems people can trust — and taking responsibility when reality disagrees with your assumptions.</p><p>The best professionals in any craft — engineers, designers, writers, and musicians — share the same traits:</p><ul><li>They keep learning</li><li>They stay disciplined</li><li>They respect the craft (and other crafts)</li><li>They use new tools without outsourcing responsibility</li></ul><p>Software engineering is particularly unforgiving because technology changes fast. The work demands sustained focus, clear thinking, and continual sharpening of judgement. Better tools don’t remove that need — they raise the bar for what “good” looks like.</p><p>It’s easy to look smart by declaring professions dead. It’s harder to be accountable for shipping.</p><h3>Quality always persists</h3><p>Tailors still exist centuries after the loom. Doctors still exist even as robotics automates parts of surgery. In any field where outcomes matter — where someone can be harmed, money can be lost, or trust can be broken — society still needs professionals who will put their name behind the work and be accountable when things go wrong.</p><p>This is why quality remains the differentiator.</p><p>When AI and machines automate the repetitive 90–95% — drafts, boilerplate, the “typing” — professionals gain time to focus on the final few percent that actually makes the difference: judgement, taste, and production-grade quality.</p><p>A fashion designer, for example, doesn’t compete with mass production by stitching faster. They compete by shaping the final details — the cut, the fit, the finish — that make something worth wearing.</p><p>AI can help you produce more output (<strong>quantity</strong>).</p><p>Only professionals can reliably produce trustworthy outcomes (<strong>quality</strong>).</p><h4>What matters is what and why, not how</h4><p>Take refactoring as an example: it doesn’t matter whether you rename a variable line by line, use an IDE command, or ask AI to do it. The value isn’t in the typing. The value is in what you changed, why you changed it, and whether the system became safer, clearer, and easier to maintain.</p><p>For illustrators, software engineers, writers, and musicians, AI mostly accelerates the noise and the non-essential parts of the work — freeing more time for the parts that still require humans: intent, judgement, creativity, and the last mile of quality.</p><p>And to be blunt: people who only want the cheapest mass-produced output were never the audience for high-craft work in the first place — with or without AI.</p><p>That final few percent is what I call the last mile of quality.</p><p>I will never say “graphic designers are done” just because I can generate a few meme images to send to friends.</p><p>I would rather pay a professional graphic designer for branding, using an AI-generated draft to roughly express what I need and improve communication.</p><h3>Will software engineers (or other professions) be “done”?</h3><p>In the age of AI, there are four common combinations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*uU7v0G8ADy8vQctHEHJohQ.png" /><figcaption>AI adoption vs domain mastery matrix</figcaption></figure><ul><li>Quadrant 1: Outsider without AI (hard to ship anything)</li><li>Quadrant 2: Outsider with AI (can demo)</li><li>Quadrant 3: Master without AI (can ship)</li><li>Quadrant 4: Master with AI (ship faster)</li></ul><p>There’s no doubt Quadrant 4 beats Quadrant 1.</p><p>The real question — and the core doom narrative — is this: will Quadrant 2 replace Quadrant 3?</p><h4>Speed is not the same as quality</h4><p>AI can massively speed up task completion through automation. But in a production context, speed is not the bottleneck — quality and accountability are. At best, AI is natural-language automation, not a miracle wand.</p><p>The Dunning–Kruger demo illusion makes Quadrant 2 look unstoppable: “an outsider becomes 100× more productive”. But productivity only matters if the output is correct, safe, maintainable, and shippable.</p><p>Without AI, an outsider may struggle to complete the task at all. With AI, they can often produce something that appears to work. The gap closes dramatically for low-stakes, low-quality work — and that’s real.</p><p>But production-grade work is decided by the last mile.</p><h4>Why Quadrant 3 still matters in production</h4><p>Masters were already shipping production-quality deliverables before GenAI. With AI, they ship faster — because they can:</p><ul><li>set constraints and recognise wrong outputs,</li><li>review for security and reliability,</li><li>integrate changes into real systems,</li><li>and own the consequences when something breaks.</li></ul><p>In other words: AI boosts people who understand the craft. It’s “slower without AI” versus “never without AI”.</p><p>In fact, the doom narrative is not valid. In real world Quadrant 3 will keep shrinking due to domain masters are smart and will move to Quadrant 4 eventually.</p><h4><strong>Benchmarks don’t end the profession</strong></h4><p>Even when models score highly on coding benchmarks, they are still probabilistic and can be confidently wrong. In production, a small error rate is not “just 1%” — it can be the difference between a secure system and an incident, or between correct behaviour and a costly failure.</p><p>That is exactly why the remaining few percent — judgement, taste, and accountability — continues to be the differentiator. Vibe coders and casual AI users struggle with that last mile because they don’t have the training to recognise and manage risk.</p><p><strong>A quick example: “Project managers will replace software engineers”</strong></p><p>Sometimes people claim project managers will overtake software engineers because AI can do the coding. In practice, on a product small enough, a software engineer can still deliver a production-grade outcome without a dedicated PM. The reverse isn’t true: coordination cannot substitute for engineering judgement, especially when quality and accountability are on the line.</p><h3>Pivoting with AI: a faster feedback loop</h3><p>There’s a transition in learning from unknown to mastery:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*UHmkJC13gv5oNxVtDt9Sww.png" /><figcaption>Improved feedback loop with AI</figcaption></figure><ul><li>When I’m unfamiliar with a topic, AI helps me understand it faster and in a more organised way.</li><li>When I already understand a topic, AI helps me do more with less typing — automation instead of repetition.</li></ul><p>The time saved goes back into learning and improving judgement. That creates a compounding loop: faster feedback, better decisions, higher-quality output.</p><p>AI works best when you already know what you want and can specify constraints — it becomes an automatic typing machine while you do the thinking.</p><p>In my legacy codebase refactoring case, the value wasn’t in having AI “write code”. The value was that I could ask AI to apply specific refactoring and migration patterns, then verify the result, instead of opening hundreds of files and reading line by line. (If you’re curious, here’s the write-up: <a href="https://ferrywl.to/blogs/2025/12/2025-12-15-using-openai-codex-to-refactor-a-legacy-codebase/">Migrate from GitHub Copilot to OpenAI Codex: Refactor a legacy codebase</a>.)</p><p>Some people use AI to generate huge amounts of unmaintainable code that they don’t truly understand. I use it to reduce tech debt: less typing, more thinking about quality — by combining clear intent, constraints, and disciplined verification.</p><p>AI enables me to automate highly repetitive tasks in the background while I learn new tech, writing blog posts, or hand-coding other projects at the same time — like the asynchronous dispatch pattern in programming terms.</p><p>To align with the last mile of quality: AI drafts; I refine, test, review, and run production checks.</p><h3>Conclusion</h3><p>There’s nothing wrong with increasing productivity or generating code with AI tools. The harm comes from the “X profession is dead” doom narrative — whether it’s driven by the Dunning–Kruger demo illusion, engagement incentives, or both.</p><p>To recap the framework for living in the AI era:</p><ul><li>Avoid toxic narratives. If a claim makes you feel uncomfortable, test it with the filters and label it as marketing if it doesn’t pass.</li><li>Focus on quality. The last mile — judgement, craft, and responsibility — is the differentiator that doesn’t disappear. Stay accountable.</li><li>Keep doing what you’re doing. Stay focused on your craft while pivoting with AI to boost productivity.</li></ul><p>Kudos to everyone who takes software engineering — and every craft — seriously.</p><p>This essay is also available on my <a href="https://ferrywl.to/blogs/2025/12/2025-12-30-the-last-mile-of-quality-why-genai-won-t-replace-professionals/">blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b118a5efddd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate from GitHub Copilot: Using OpenAI Codex to refactor a legacy codebase]]></title>
            <link>https://ferrywlto.medium.com/using-openai-codex-to-refactor-a-legacy-codebase-9896b552e397?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/9896b552e397</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[github-copilot]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[openai-codex]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Mon, 15 Dec 2025 23:01:08 GMT</pubDate>
            <atom:updated>2025-12-17T22:12:26.747Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rIdhywe2d-1NaeQ6kTYgA.png" /></figure><p>I was an early GitHub Copilot Pro subscriber from its debut. A few months ago, the company I work for started rolling out GitHub Copilot Enterprise.</p><p>Because we’re allowed to use our personal GitHub account for work, I was asked to enrol with it. However, when I enrolled under the company’s Copilot subscription, GitHub automatically refunded my personal subscription — because a GitHub account can only have one active Copilot licence.</p><p>Reference: <a href="https://github.com/orgs/community/discussions/56234">GitHub Community discussion</a></p><p>To avoid any potential IP ownership disputes, I decided to stop using GitHub Copilot entirely on my personal machine.</p><p>At the same time, I’m a ChatGPT Plus subscriber. I use it for learning and daily creative tasks. Even though I treat it like a technical search engine quite often (and I’ve tried the web agent), I didn’t realise Codex could run locally inside VS Code until very recently (tried Codex CLI long ago but the experience wasn’t great).</p><p>So I decided to try it on a genuinely challenging project: refactoring a legacy backend codebase.</p><h3>The legacy situation</h3><p>The codebase consisted of:</p><ul><li>A data object project mixing multiple concerns.</li><li>Thirteen containerised nano-services deployed to <strong>GCP Cloud Run</strong></li><li>Everything targeting <strong>.NET Core 3.1</strong> (around five to six years old at the time of writing)</li></ul><h3>Refactoring objectives</h3><ul><li>Consolidate the shattered nano-service projects into a single API project</li><li>Migrate from <strong>.NET Core 3.1</strong> to <strong>.NET 10</strong></li><li>Move from a poorly organised project structure into a <strong>DDD-style structure</strong></li><li>Enable strict mode across all projects (<strong>TreatWarningsAsErrors</strong>)</li></ul><h3>My Codex setup</h3><ul><li>Plan: ChatGPT Plus</li><li>Model: GPT-5.1-Codex-Max</li><li>Agent: Full Access</li><li>VS Code extension: <a href="https://marketplace.visualstudio.com/items?itemName=openai.chatgpt">Codex — OpenAI’s coding agent</a></li><li>Reasoning effort: Medium</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NmAIlNWjJG78nNGfoIdIKA.png" /><figcaption>Codex VSCode extension</figcaption></figure><p><strong>Before and after comparison:</strong></p><pre>+--------+---------+----------+---------+<br>|        | C# files| Total LOC| Classes |<br>+--------+---------+----------+---------+<br>| Before |     527 |   45,927 |     390 |<br>| After  |     394 |   44,393 |     408 |<br>+--------+---------+----------+---------+</pre><p>It also helped fix <strong>thousands of errors</strong> when I enabled strict mode.</p><p>Even with AI, it still took me around <strong>10 nights</strong> (about <strong>2 hours per night</strong>) to complete. There was one time Codex told me I’d run out of usage quota and needed to wait 24 hours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*G3WcKokm2ozY4nWwDCPTdw.png" /></figure><p>This would have been extremely difficult to do manually without a significant time investment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*Y2s_OzSXm_9NgypaAHTGKQ.png" /><figcaption>Diff of my pull request</figcaption></figure><h3>How I feel about Codex afterwards</h3><h3>Pros</h3><ul><li>The model was able to pause and ask for meaningful confirmation, like:</li></ul><blockquote><em>This is a very large refactor (hundreds of lambdas/short params across all services and tests). Doing it in one shot risks regressions and will take a lot of time.</em></blockquote><ul><li>It also felt faster and more accurate (for this kind of refactor) than my typical experience with Copilot.</li><li>And with a single Plus subscription, it offered strong value — not just for Codex, but also for day-to-day learning and creative productivity.</li></ul><h3>Cons</h3><ul><li>It’s a bit of a pity it doesn’t have <strong>Next Edit Suggestions (NES)</strong> like GitHub Copilot, which I personally find more useful for tight, single-file editing.</li></ul><h3><strong>Conclusion</strong></h3><p>In the past Codex CLI requires OpenAI API account and charge by token consumption, this discovery saved me a few bucks from monthly subscription cost. :)</p><p>This post is also available on my personal <a href="https://ferrywl.to/blogs/2025/12/2025-12-15-using-openai-codex-to-refactor-a-legacy-codebase/">blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9896b552e397" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CLI command to deploy MAUI App to iOS device with .NET 10]]></title>
            <link>https://ferrywlto.medium.com/cli-command-to-deploy-maui-app-to-ios-device-with-net-10-19d4d0d9ff28?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/19d4d0d9ff28</guid>
            <category><![CDATA[msbuild]]></category>
            <category><![CDATA[maui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Sat, 29 Nov 2025 00:14:50 GMT</pubDate>
            <atom:updated>2025-11-29T00:59:04.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OtfXrTTyLd2eOoQu" /><figcaption>Photo by <a href="https://unsplash.com/@mrw0rld?utm_source=medium&amp;utm_medium=referral">Ilnur</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>CLI command to deploy MAUI App to iOS device with .NET 10</h3><p>A short snippet to make your MAUI app development life easier.</p><p>When developing MAUI app, we usually use <a href="https://visualstudio.microsoft.com/">Visual Studio</a> or <a href="https://www.jetbrains.com/rider/">Rider</a>. I have been a paid Rider user for many years. To be honest it is great and it will help you do much of the heavy lifting out of the box when you need to deploy your app to a physical device for testing.</p><p>However I use <a href="https://code.visualstudio.com/">VSCode</a> most of the time and try to figure out ways to use the CLI to do as many things as possible, because I am a minimalist and the best part of the CLI is that it is good for automating tasks in scripts. In addition, it may save you the subscription fee if all you need is a way to deploy the app to your device.</p><p>I assume you have the latest Xcode installed with <a href="https://developer.apple.com/download/all/">Xcode CLI</a>. In .NET 10, the command you use to build your app for iOS device should be:</p><pre>dotnet build -f net10.0-ios -r ios-arm64</pre><pre>&lt;Target Name=&quot;DeployToDevice&quot; AfterTargets=&quot;Build&quot; Condition=&quot;&#39;$(TargetFramework)&#39;==&#39;net10.0-ios&#39; And $(RuntimeIdentifier) == &#39;ios-arm64&#39;&quot;&gt;<br>  &lt;PropertyGroup&gt;<br>    &lt;MlaunchPath&gt;$(DOTNET_ROOT)/packs/Microsoft.iOS.Sdk.net10.0_26.1/26.1.10494/tools/bin/mlaunch&lt;/MlaunchPath&gt;<br>    &lt;DeviceName&gt;PinkRabbit&lt;/DeviceName&gt;<br>    &lt;AppId&gt;VerdantSparks.OurTimeLeft&lt;/AppId&gt;<br>    &lt;AppBundlePath&gt;$(MSBuildProjectDirectory)/bin/Debug/net10.0-ios/ios-arm64/OurTimeLeft.Maui.app&lt;/AppBundlePath&gt;<br>    &lt;iOSSdkVersion&gt;14.2&lt;/iOSSdkVersion&gt;<br>    &lt;XcodeSdkRoot&gt;/Applications/Xcode.app/Contents/Developer&lt;/XcodeSdkRoot&gt;<br>    &lt;Command&gt;$(MlaunchPath) --devname $(DeviceName) --killdev $(AppId) --wait-for-unlock --argument=-connection-mode --argument=usb -sdk $(iOSSdkVersion) --sdkroot $(XcodeSdkRoot)&lt;/Command&gt;<br>  &lt;/PropertyGroup&gt;<br>  &lt;Exec Command=&quot;$(Command) --installdev &amp;quot;$(AppBundlePath)&amp;quot;&quot; /&gt;<br>  &lt;Exec Command=&quot;$(Command) --launchdev &amp;quot;$(AppBundlePath)&amp;quot;&quot; /&gt;<br>&lt;/Target&gt; </pre><p>Then the magic comes from this:</p><pre>/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net10.0_26.1/26.1.10494/tools/bin/mlaunch</pre><p>Which /usr/local/share/dotnet is the value of the environment variable DOTNET_ROOT.</p><p>If you look at the content of the packs folder you can see the SDKs installed for different platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LVo2rbUl1XdEswmV7avBIQ.png" /><figcaption>packages inside pack folder.</figcaption></figure><p>To deploy your built .app into your iOS device, there are multiple switches you will need along side the mlaunch executable:</p><pre>$(DOTNET_ROOT)/packs/Microsoft.iOS.Sdk.net10.0_26.1/26.1.10494/tools/bin/mlaunch \<br>--devname [YouriPhoneDevice] \<br>--killdev [YourAppId] \<br>--wait-for-unlock \<br>--argument=-connection-mode \<br>--argument=usb \<br>-sdk 26.1 \<br>--sdkroot /Applications/Xcode.app/Contents/Developer \<br>--installdev [YourProjectRoot]/bin/Debug/net10.0-ios/ios-arm64/[YourAppName].app</pre><p>These switches specify your device by its name, connect to it via a USB cable, wait for you to unlock the device, close your app if it is already installed and running, and finally install your app.</p><p>To find your device name, you can run:</p><pre>xcrun xctrace list devices</pre><p>That’s all for deploying your app to an iOS device.</p><p>What if you also want to launch the app automatically after deployment?</p><p>You will have to call the same command again but this time replace the--installdev switch with --launchdev :</p><pre># These have to be separate mlaunch commands for install and launch.<br><br>$(DOTNET_ROOT)/packs/Microsoft.iOS.Sdk.net10.0_26.1/26.1.10494/tools/bin/mlaunch \<br>--devname [YouriPhoneDevice] \<br>--killdev [YourAppId] \<br>--launchdev [YourProjectRoot]/bin/Debug/net10.0-ios/ios-arm64/[YourAppName].app \<br>--wait-for-unlock \<br>--argument=-connection-mode \<br>--argument=usb -sdk 26.1 \<br>--sdkroot /Applications/Xcode.app/Contents/Developer</pre><p>If you don’t like manually calling this command in shell scripts by your own like me, I have created a MSBuild target to automate this:</p><pre>&lt;Target Name=&quot;DeployToDevice&quot; AfterTargets=&quot;Build&quot; Condition=&quot;&#39;$(TargetFramework)&#39;==&#39;net10.0-ios&#39; And $(RuntimeIdentifier) == &#39;ios-arm64&#39;&quot;&gt;<br>  &lt;PropertyGroup&gt;<br>    &lt;MlaunchPath&gt;$(DOTNET_ROOT)/packs/Microsoft.iOS.Sdk.net10.0_26.1/26.1.10494/tools/bin/mlaunch&lt;/MlaunchPath&gt;<br>    &lt;DeviceName&gt;YourDeviceName&lt;/DeviceName&gt;<br>    &lt;AppId&gt;Your.App.Id&lt;/AppId&gt;<br>    &lt;AppBundlePath&gt;$(MSBuildProjectDirectory)/bin/Debug/net10.0-ios/ios-arm64/YourApp.app&lt;/AppBundlePath&gt;<br>    &lt;iOSSdkVersion&gt;26.1&lt;/iOSSdkVersion&gt;<br>    &lt;XcodeSdkRoot&gt;/Applications/Xcode.app/Contents/Developer&lt;/XcodeSdkRoot&gt;<br>    &lt;Command&gt;$(MlaunchPath) --devname $(DeviceName) --killdev $(AppId) --wait-for-unlock --argument=-connection-mode --argument=usb -sdk $(iOSSdkVersion) --sdkroot $(XcodeSdkRoot)&lt;/Command&gt;<br>  &lt;/PropertyGroup&gt;<br>  &lt;Exec Command=&quot;$(Command) --installdev &amp;quot;$(AppBundlePath)&amp;quot;&quot; /&gt;<br>  &lt;Exec Command=&quot;$(Command) --launchdev &amp;quot;$(AppBundlePath)&amp;quot;&quot; /&gt;<br>&lt;/Target&gt;</pre><p>So that when you run the command from the beginning of this post, your app will get deployed to and launched on your iOS device after build succeeds.</p><p>I hope this short post will save you time (and perhaps money) in MAUI development. 😀</p><p>This post is also available on my <a href="https://ferrywl.to/blogs/2025/11/2025-11-29-cli-command-to-deploy-maui-app-to-ios-device-with-net-10/">personal blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19d4d0d9ff28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating iOS Widgets with MAUI — Part 3: Communicating between MAUI App and iOS Widget]]></title>
            <link>https://ferrywlto.medium.com/creating-ios-widgets-with-maui-part-3-communicating-between-maui-app-and-ios-widget-b177dd0e40a6?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/b177dd0e40a6</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[maui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Wed, 19 Nov 2025 09:02:05 GMT</pubDate>
            <atom:updated>2025-11-22T15:52:52.876Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating iOS Widgets with MAUI — Part 3: Communicating between MAUI App and iOS Widget</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9_l0VLHfAxn1Vlx77IfoA.png" /></figure><p>This is the last part of the series recording how I managed to create a MAUI app that can interact with an iOS widget. In this post, we will explore how to communicate between the iOS widget and the our MAUI app we created from the previous posts. I highly recommend reading the first and second post, [<a href="https://ferrywlto.medium.com/creating-ios-widgets-with-maui-part-1-interoperability-d73d6f2c563c?postPublishedType=repub"><strong>Creating iOS Widgets with MAUI — Part 1: Interoperability</strong></a>] and [<a href="https://ferrywlto.medium.com/creating-ios-widgets-with-maui-part-2-bundling-ios-widget-5c5f5f5f5f5?postPublishedType=repub"><strong>Creating iOS Widgets with MAUI — Part 2: Bundling iOS Widget</strong></a>], if you haven’t read them yet, as the topic in this post will require knowledge from the previous ones.</p><p>Disclaimer: I am just sharing my personal experience. I do not guarantee the information in this post is 100% correct or accurate. I am not, by any means, expressing that I am an expert in mobile development.</p><h4><strong>Sharing data between MAUI app and iOS widget</strong></h4><p>To share data between the MAUI app and the iOS widget, we can use App Groups. App Groups allow multiple apps or extensions to share access to a common container.</p><p>We need to make sure both of our MAUI app and the iOS widget are part of the same App Group.</p><p>In Xcode:</p><p>1. Open the widget extension target project created in Part 2.</p><p>2. Create a <strong>.entitlements</strong> file for the widget extension if you haven’t done so. Name it to something like <strong>HelloWidgetExtension.entitlements</strong>.</p><p>3. Open the <strong>.entitlements</strong> file and add the following:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;<br>&lt;plist version=&quot;1.0&quot;&gt;<br>  &lt;dict&gt;<br>    &lt;key&gt;com.apple.security.application-groups&lt;/key&gt;<br>    &lt;array&gt;<br>    &lt;! - Replace with your app bundle identifier →<br>    &lt;string&gt;group.MyOrg.hello-maui-widget&lt;/string&gt;<br>    &lt;/array&gt;<br>  &lt;/dict&gt;<br>&lt;/plist&gt;</pre><p>Or clicking on the top level project &gt; TARGETS &gt; widget extension &gt; Signing &amp; Capabilities &gt; click “<strong>+ Capability</strong>” &gt; App Groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*56Qgu8TJwTM6YLVtsS33JA.png" /></figure><p>There will be a App Groups section shown at the bottom. Click the “<strong>+</strong>” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*6PrnuTLENNdGEk3Vf1zCww.png" /></figure><p>Make sure your newly created App Group is checked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*O7fBaLLRLKDw8lsPuM-qHQ.jpeg" /></figure><p><strong>4. Do the same for the Xcode App project as well to make sure the provisioning profile managed by Xcode contains this entitlement.</strong> Xcode will warns you if you forget to do this when you try to build build the MAUI app.</p><p>Note: App Group identifiers must be prefixed with <strong>group.</strong>, it is Apple’s convention.</p><p>Back to the MAUI app project:</p><p>1. Go to <strong>Platforms/iOS</strong> folder, create a new file named <strong>Entitlements.plist</strong> if it doesn’t exist.</p><p>2. Copy the same content from the widget extension’s <strong>.entitlements</strong> file into this file.</p><p>3. Open the MAUI project file to configure the same code sign entitlements as the Xcode App project did by adding the following PropertyGroup:</p><pre>&lt;PropertyGroup Condition=&quot;$([MSBuild]::GetTargetPlatformIdentifier(&#39;$(TargetFramework)&#39;)) == &#39;ios&#39;&quot;&gt;<br>  &lt;CodesignEntitlements&gt;Platforms/iOS/Entitlements.plist&lt;/CodesignEntitlements&gt;<br>&lt;/PropertyGroup&gt;</pre><p>Now we will make use of NSUserDefaults with the App Group to share data.</p><p>Note: Although MAUI provides <strong>Microsoft.Maui.Storage.Preferences</strong>, it defaults to <strong>NSUserDefaults.StandardUserDefaults</strong> under the hood, which does not support App Groups by design.</p><p>Think of it as an in-memory key-value storage that both the MAUI app and the iOS widget can access, just like using Redis. iOS manages when the values are flushed to persistent storage.</p><p>What we are trying to do is to have the MAUI app write a value to the shared NSUserDefaults, and call the bridge to have the iOS widget read that value and display it.</p><p>3. Open <strong>MainPage.xaml.cs</strong> in your MAUI project, and add the following code above the HelloWorldBridge.SayHelloStaticLib() line we added in Part 1:</p><pre>// replace with group.[your_app_group_identifier]<br>using var defaults = new NSUserDefaults(&quot;group.MyOrg.hello-maui-widget&quot;, NSUserDefaultsType.SuiteName);<br>defaults.SetString(count.ToString(), &quot;helloValue&quot;);</pre><p>We have just written the current counter value to the shared NSUserDefaults with key “<strong>helloValue”</strong>.</p><p>Now the last piece of the puzzle is to have the iOS widget read that value and display it.</p><h4><strong>Reload widget timeline</strong></h4><p>In part 1, the exported Swift function HelloWorldBridge_SayHello simply logged a hello message. Now we will modify it such that when it is called, it will reload the widget data source.</p><p>Open the <strong>HelloWorldBridge.swift</strong> file we created in Part 1, and modify the function to the following:</p><pre>@_cdecl(&quot;HelloWorldBridge_SayHello&quot;)<br>public func HelloWorldBridge_SayHello() {<br>  WidgetCenter.shared.reloadAllTimelines()<br>}</pre><p>This will instruct the singleton WidgetCenter to reload all widget timelines belonging to the containing app. The current timeline will get invalidated, and the system will call the timeline provider to get new data. So the next step is to modify our timeline provider to read the shared data.</p><p>Open the <strong>HelloWidget.swift</strong> file created in Part 2, and modify the getTimeline method in Provider struct generated by Xcode as below:</p><pre>func getTimeline(in context: Context, completion: @escaping (Timeline&lt;Entry&gt;) -&gt; ()) {<br>  let defaults = UserDefaults(suiteName: &quot;group.MyOrg.hello-maui-widget&quot;)<br>  let helloValue = defaults?.string(forKey: &quot;helloValue&quot;) ?? &quot;0&quot;<br>  var entries: [SimpleEntry] = []<br>  let entryDate = Calendar.current.date(byAdding: .minute, value: 1, to: .now)!<br>  let entry = SimpleEntry(date: entryDate, emoji: &quot;😀 Count: \(helloValue)&quot;)<br>  entries.append(entry)<br>  let timeline = Timeline(entries: entries, policy: .atEnd)<br>  completion(timeline)<br>}</pre><p>What we did here is to read the shared NSUserDefaults with the same app group, get the value for key “<strong>helloValue</strong>”, and use it to create a new timeline entry.</p><p>When WidgetCenter.shared.reloadAllTimelines()is called from the MAUI app, getTimeline() will be invoked, updating the widget’s display and schedule next refresh. We set it to 1 minute for demo purposes, but the actual refresh time is managed by iOS and not guaranteed, subject to WidgetKit’s budget and OS heuristics.</p><p>Build the widget extension and copy the updated <strong>HelloWidgetExtension.appex</strong> to the MAUI project’s <strong>Platforms/iOS/PlugIns</strong> folder as we did in Part 2.</p><p>Rebuild and run the MAUI app again.</p><p>Now you should be able to see that when you tap the button in the MAUI app, the counter value is updated in the iOS widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*DToO7GrQzd4Qwxhd3cXl7Q.gif" /><figcaption>MAUI app updating iOS widget content</figcaption></figure><p>🎉 <strong>Congratulations!</strong> You have successfully created a MAUI app that can communicate with an iOS widget. 👏</p><p>After going through this series, you should be able to:</p><ul><li>Create an iOS widget and embed it into a MAUI app.</li><li>Call Swift code from C# in a MAUI app.</li><li>Share data between a MAUI app and its iOS widget using App Groups and NSUserDefaults.</li></ul><p>Hope you find this series helpful. Happy coding!</p><p>The full source code of this demo project can be found at my <a href="https://github.com/ferrywlto/hello-maui-widget"><strong>GitHub repository</strong></a><strong>.</strong></p><p>This post is also available on my <a href="https://ferrywl.to/blogs/2025/11/2025-11-17-creating-ios-widgets-with-maui-part-3-communicating-between-maui-app-and-ios-widget/"><strong>blog</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b177dd0e40a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating iOS Widgets with MAUI — Part 2: Bundling iOS Widget]]></title>
            <link>https://ferrywlto.medium.com/creating-ios-widgets-with-maui-part-2-bundling-ios-widget-a309e890e046?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/a309e890e046</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[dotnet-10]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[maui]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Mon, 17 Nov 2025 09:03:09 GMT</pubDate>
            <atom:updated>2025-11-28T21:45:46.859Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Creating iOS Widgets with MAUI — Part 2: Bundling iOS Widget</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9pkIYNAA8oXMPbFHtRPeRw.png" /></figure><p>This is the second part of the series recording how I managed to create a MAUI app that can interact with an iOS widget. In this post, we will explore how to create a Hello World widget in iOS and have our MAUI app bundle it. I highly recommend reading the first post, <a href="https://ferrywlto.medium.com/creating-ios-widgets-with-maui-part-1-interoperability-d73d6f2c563c?postPublishedType=repub"><strong>Creating iOS Widgets with MAUI — Part 1: Interoperability</strong></a>, if you haven’t read it yet, as the topic in this post will require knowledge from the previous one.</p><p>Disclaimer: I am just sharing my personal experience. I do not guarantee the information in this post is 100% correct and accurate. I am not, by any means, expressing that I am an expert in mobile development.</p><h3>Creating the widget</h3><p>In Xcode, create a new App project. Although we don’t use this App project in our MAUI app development, this App project has its value to us. We will cover this in later sections.</p><p>For <strong>Team</strong>, please choose the personal team Xcode created for you. Carefully choose your <strong>Organization Identifier</strong> and remember the <strong>Bundle Identifier</strong> — we will use them soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*ejU9OZelomPTEUCl1KH8Jg.png" /></figure><p>Your project should looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*6bSmClhe_wwcIGzxXW0mcg.png" /></figure><p>Click <strong>File &gt; New &gt; Target</strong> to create a Widget extension. Note that you cannot create a Widget extension without an App project. Name your widget extension something like “HelloWidgetExtension” and leave everything as default. Make sure both <strong>Project</strong> and <strong>Embed in Application</strong> are set to your App project. When asked to activate the scheme, click <strong>Yes</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*hKszZaPQRtHHSfVHmmcEjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*-8Wifspsy9AVX0jCJX6blQ.png" /></figure><p>Run the App from Xcode to make sure everything works in Simulator. You should be able to create the widget under your App project.</p><p><strong>Note:</strong></p><p>If your App has bundle identifier “<strong>MyOrg.HelloWidget”</strong>, then your widget extension bundle identifier must be prefixed with your app’s bundle identifier, e.g. “<strong>MyOrg.HelloWidget.WidgetExtension”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*oeH87P0azS2fCmeyAD4aeg.png" /></figure><h3>Bundle the widget in our MAUI app</h3><p>Using the same MAUI project we created in the previous post, we are going to replace the identity of the Xcode App project with our MAUI app.</p><p>Edit your MAUI project file and make sure the value in &lt;ApplicationId&gt; is exactly the same as the Xcode App project. You can view and set it under the Xcode top-level project &gt; <strong>Build Settings</strong>.</p><pre>&lt;ApplicationId&gt;MyOrg.HelloWidget&lt;/ApplicationId&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*2fUtrQ4EyD8dFi_aC3EFMA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bY0dyO3kqQfcvhTP8SY5Ag.png" /></figure><p>Create a folder <strong>PlugIns</strong> under Platforms/iOS.</p><p>Back to Xcode:</p><p>At the top, choose the scheme created when the widget extension project was created, then choose <strong>Any iOS Simulator Device (arm64, x86_64)</strong> next to the scheme. Build the widget extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*mjcxwQAp3eni5ry5vFMWHA.png" /></figure><p>Go to <strong>Product &gt; Show Build Folder in Finder</strong>. From <strong>Products &gt; Debug-iphonesimulator</strong>, you should see a file named: <strong>HelloWidgetExtension.appex</strong> . Copy this into your MAUI project’s <strong>Platforms/iOS/PlugIns</strong> folder.</p><p>Your folder structure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*hibrnU01vf6LB9KOrbxcdw.png" /></figure><p>Open your MAUI project file. Remember the section we created to include the static library we exported? Add the following into that same section:</p><pre>&lt;BundleResource Include=&quot;Platforms/iOS/PlugIns/**&quot;&gt;<br>  &lt;LogicalName&gt;PlugIns/%(RecursiveDir)%(Filename)%(Extension)&lt;/LogicalName&gt;<br>&lt;/BundleResource&gt;</pre><p>Delete the <strong>bin</strong> and <strong>obj</strong> folders to ensure we have a clean build.</p><p>Build the project again with this command:</p><pre>dotnet build -f net10.0-ios -r iossimulator-arm64</pre><p>Finally launch our MAUI app with:</p><pre>dotnet run -f net10.0-ios -r iossimulator-arm64 -p:_DeviceName=:v2:udid=[your_simulator_id]]</pre><p>You can also use a single command as below, it is just my personal preference:</p><pre>dotnet build -t:Run -f net10.0-ios -r iossimulator-arm64</pre><p>You will find that our MAUI app now replaces the Xcode app. You can now try creating the widget under our MAUI app’s name. Tapping on the widget will open our MAUI app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*TK_wO0Q7wmRn0kim0M_vEQ.gif" /></figure><p>Note:</p><ol><li>You can configure your MAUI project .csproj file to automate the extension copying work.</li><li>Some suggests the use of &lt;AdditionalAppExtensions&gt; , but I didn’t try it yet.</li></ol><h4>🎉 <strong>Congratulations! You have bundled an iOS widget into your MAUI app.</strong></h4><p>Simply bundling an iOS widget into our MAUI app is not very helpful if we are not able to interact with it. In the next (and final) post of the series, we will go over what we have learned so far to communicate between them.</p><p>The full source code of this post can be found at my <a href="https://github.com/ferrywlto/hello-maui-widget"><strong>GitHub repository</strong></a>.</p><p>This post is also available on my personal <a href="https://ferrywl.to/blogs/2025/11/2025-11-16-creating-ios-widgets-with-maui-part-2-bundling-ios-widget/"><strong>blog</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a309e890e046" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating iOS Widgets with MAUI — Part 1: Interoperability]]></title>
            <link>https://ferrywlto.medium.com/creating-ios-widgets-with-maui-part-1-interoperability-d73d6f2c563c?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/d73d6f2c563c</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[dotnet-10]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[maui]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Thu, 13 Nov 2025 23:19:03 GMT</pubDate>
            <atom:updated>2025-11-28T21:45:23.226Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating iOS Widgets with MAUI — Part 1: Interoperability</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQXT19nJS_pfzjfeM8quMQ.png" /></figure><p><a href="https://dotnet.microsoft.com/en-us/">Microsoft .NET</a> is a great platform that allows you to do many different things with the same tech stack, from game development, machine learning, websites to mobile applications. .NET 10 is the latest version released just a few days ago. Do check it out.</p><p><a href="https://dotnet.microsoft.com/en-us/apps/maui">MAUI (Multi-platform App UI)</a> lets you build native applications across Windows/macOS/Linux/iOS/Android with a reusable codebase. However it has some limitations (e.g. accessing platform specific hardware), depending on what you need to do.</p><p>This is a series of recordings on how I create an iOS widget that works with MAUI. It took me a few days to figure out the tricks and articles about this topic is limited. This is the first post of the series and hope it helps someone working on the MAUI. In this post we will talk about the pre-requisite: <strong>Interoperability</strong>.</p><p>Disclaimer: I am just sharing my personal experience. I do not guarantee the information in this post is 100% correct and accurate. I am not, by any means, expressing that I am an expert in mobile development.</p><p><strong>Why do we need interoperability?</strong></p><p>This is because there are APIs that MAUI SDK doesn’t provide. e.g. <strong>WidgetKit . </strong>You can embed a widget into your app, but it is pointless if you cannot control it. Therefore in order to control something that is not available from the MAUI SDK, you will need some workaround for it. <strong>In short, that means finding a way to call Swift code from C#.</strong></p><p>In this post we will try to call Swift NSLog() from our MAUI C# code, which simply prints “Hello World” in the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*ACQk7threjwBtsyvPuhyjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdDdTgMMTkVoGe1grXXLzA.png" /></figure><p><strong>Pre-requisites</strong></p><ul><li>.NET 10 SDK</li><li>Xcode 26.1</li></ul><ol><li>Create a MAUI project.</li></ol><p>Run<strong> </strong>dotnet new maui , then dotnet restore .</p><p>If this is the first time you build a MAUI project, you will be asked to run dotnet workload restore with elevated privilege.</p><p>Open your new project .csproj file, at the top remove all values from TargetFramework tag except net10.0-ios . This is because we don’t need to support other platforms for this task. Do the same for SupportedOSPlatformVersion and TargetPlatformMinVersion tags.</p><p>Your project file should look like this:</p><pre>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;<br><br> &lt;PropertyGroup&gt;<br>  &lt;TargetFrameworks&gt;net10.0-ios&lt;/TargetFrameworks&gt;<br><br>  &lt;OutputType&gt;Exe&lt;/OutputType&gt;<br>  &lt;RootNamespace&gt;test&lt;/RootNamespace&gt;<br>  &lt;UseMaui&gt;true&lt;/UseMaui&gt;<br>  &lt;SingleProject&gt;true&lt;/SingleProject&gt;<br>  &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;<br>  &lt;Nullable&gt;enable&lt;/Nullable&gt;<br><br>  &lt;!-- Display name --&gt;<br>  &lt;ApplicationTitle&gt;test&lt;/ApplicationTitle&gt;<br><br>  &lt;!-- App Identifier --&gt;<br>  &lt;ApplicationId&gt;com.companyname.test&lt;/ApplicationId&gt;<br><br>  &lt;!-- Versions --&gt;<br>  &lt;ApplicationDisplayVersion&gt;1.0&lt;/ApplicationDisplayVersion&gt;<br>  &lt;ApplicationVersion&gt;1&lt;/ApplicationVersion&gt;<br><br>  &lt;!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged --&gt;<br>  &lt;WindowsPackageType&gt;None&lt;/WindowsPackageType&gt;<br><br>  &lt;SupportedOSPlatformVersion Condition=&quot;$([MSBuild]::GetTargetPlatformIdentifier(&#39;$(TargetFramework)&#39;)) == &#39;ios&#39;&quot;&gt;15.0&lt;/SupportedOSPlatformVersion&gt;<br> &lt;/PropertyGroup&gt;<br><br> &lt;ItemGroup&gt;<br>  &lt;!-- App Icon --&gt;<br>  &lt;MauiIcon Include=&quot;Resources\AppIcon\appicon.svg&quot; ForegroundFile=&quot;Resources\AppIcon\appiconfg.svg&quot; Color=&quot;#512BD4&quot; /&gt;<br><br>  &lt;!-- Splash Screen --&gt;<br>  &lt;MauiSplashScreen Include=&quot;Resources\Splash\splash.svg&quot; Color=&quot;#512BD4&quot; BaseSize=&quot;128,128&quot; /&gt;<br><br>  &lt;!-- Images --&gt;<br>  &lt;MauiImage Include=&quot;Resources\Images\*&quot; /&gt;<br>  &lt;MauiImage Update=&quot;Resources\Images\dotnet_bot.png&quot; Resize=&quot;True&quot; BaseSize=&quot;300,185&quot; /&gt;<br>  <br>  &lt;!-- Custom Fonts --&gt;<br>  &lt;MauiFont Include=&quot;Resources\Fonts\*&quot; /&gt;<br><br>  &lt;!-- Raw Assets (also remove the &quot;Resources\Raw&quot; prefix) --&gt;<br>  &lt;MauiAsset Include=&quot;Resources\Raw\**&quot; LogicalName=&quot;%(RecursiveDir)%(Filename)%(Extension)&quot; /&gt;<br> &lt;/ItemGroup&gt;<br><br> &lt;ItemGroup&gt;<br>  &lt;PackageReference Include=&quot;Microsoft.Maui.Controls&quot; Version=&quot;$(MauiVersion)&quot; /&gt;<br>  &lt;PackageReference Include=&quot;Microsoft.Maui.Essentials&quot; Version=&quot;$(MauiVersion)&quot; /&gt;<br>  &lt;PackageReference Include=&quot;Microsoft.Extensions.Logging.Debug&quot; Version=&quot;10.0.0&quot; /&gt;<br> &lt;/ItemGroup&gt;<br><br>&lt;/Project&gt;</pre><p>2. Create and export a C interface from Xcode.</p><p>Open Xcode. From File → New → Project , choose iOS → Framework &amp; Library → Static Library .</p><p>Name the product HelloWorldBridge , leave everything else as defaults.</p><p>You will have a solution with a single project that having a single file created. The only source file HelloWorldBridge.swift is an empty class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlXj7TB2DQhZ-fDeFu9SvQ.png" /></figure><p>Remove everything existing from the source file and replace with:</p><pre>import Foundation<br><br>@_cdecl(&quot;HelloWorldBridge_SayHello&quot;)<br>public func HelloWorldBridge_SayHello() {<br>  NSLog(&quot;👋 Hello World from Swift (Static Library)!&quot;)<br>} </pre><p>The @_cdecl attribute marks this Swift function to be exported using the C calling convention with a fixed, unmangled symbol name, allowing our MAUI app to import it via P/Invoke (Platform Invocation Services).</p><p>Although different sources often recommend alternative and sometimes conflicting interop methods, this is the approach I have personally found to be the most stable. <strong>This has also been verified with very recent MAUI samples repo update by Microsoft folks </strong><a href="https://github.com/dotnet/maui-samples/blob/main/10.0/PlatformIntegration/LiveActivityDemo/native/LiveActivityBridge/Sources/LiveActivityBridge/Bridge.swift"><strong>here</strong></a><strong>.</strong></p><p>From the top of Xcode, select “Any iOS Simulator Device (arm64, x86_64)” as build target. Select Product→Build or pressing (Cmd+B) to build it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S3dC99-tNMEJl10pSMUavQ.png" /></figure><p>Select from menu Product→Show Build Folder in Finder , finder will show your project Build folder, which is the built artefacts will be placed.</p><p>The build folder path will usually be: $(Home)/Library/Developer/Xcode/DerivedData/{YourProjectName}-{RandomProjectId}/Build .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*kDwHDHenk2K1Re1giH2OWA.png" /></figure><p>Inside Products &gt; Debug-iphonesimulator , you should be able to see your built static library archive libHelloWorldBridge.a.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uRj5lLm9vwef5lMqBu78CA.png" /></figure><p>3. Integration</p><p>Copy libHelloWorldBridge.a to your MAUI project’s Platforms/iOS/Frameworks folder (You can place it to Platforms/iOS as well, just my preference).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*jaTCT2wQ8jKUqocvz0zn9w.png" /></figure><p>Create a file named HelloWorldBridge.cs inside Platforms/iOS with content below:</p><pre>#if IOS<br>using System.Runtime.InteropServices;<br><br>public static class HelloWorldBridge<br>{<br>    [DllImport(&quot;__Internal&quot;, EntryPoint = &quot;HelloWorldBridge_SayHello&quot;)]<br>    private static extern void _SayHelloStaticLib();<br><br>    public static void SayHelloStaticLib() =&gt; _SayHelloStaticLib();<br>}<br>#endif</pre><p>The #if and #endif directives limited the code within it will be included only when build target is iOS, you can omit them for now as we only target iOS for this demo. What this bridge code does is to link the exported C interface with .NET. Note that no matter you exported a xcframework or static library (.a ), &quot;__Internal&quot; is the only valid name, using any name other than this will probably throw DllNotFoundException during run time. You will see the EntryPoint parameter need to match the name we defined with @_cdecl in our Swift file.</p><p>The idea of the bridge is to map a public static method in C# to an exposed Objective-C interface, which eventually calls some Swift code.</p><p>Now go to MainPage.xaml.cs generated by MAUI project template and edit OnCounterClicked event handler, add these to the bottom of the method:</p><pre>HelloWorldBridge.SayHelloStaticLib();</pre><p>The final piece of the puzzle is to tell MSBuild to include your copied static library. Open your project .csproj file, place the following at the bottom of the file, right above the closing tag &lt;/Project&gt; :</p><pre>&lt;ItemGroup&gt;<br> &lt;NativeReference Include=&quot;Platform/iOS/Framework/libHelloWorldBridge.a&quot;&gt;<br>  &lt;Kind&gt;Static&lt;/Kind&gt;<br>  &lt;ForceLoad&gt;true&lt;/ForceLoad&gt;<br> &lt;/NativeReference&gt;   <br>&lt;/ItemGroup&gt;</pre><p>Build and launch your MAUI app with:</p><pre>dotnet build -t:Run -f net10.0-ios -r iossimulator-arm64 </pre><p>Tap on the “Click me” button and you should see the Hello World message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdDdTgMMTkVoGe1grXXLzA.png" /><figcaption>Yay!</figcaption></figure><p>🎉 Congratulations! You have just successfully calling Swift code from C#! 👏</p><p>In next post we will create the widget and embed into a MAUI app.</p><p>Complete code sample can be found here: <a href="https://github.com/ferrywlto/maui-interop-demo">https://github.com/ferrywlto/maui-interop-demo</a></p><p>This post is also available on my <a href="https://ferrywl.to/blogs/2025/11/2025-11-13-creating-ios-widgets-with-maui-part-1-interoperability/">blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d73d6f2c563c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Local DeepSeek-R1 with .NET]]></title>
            <link>https://ferrywlto.medium.com/local-deepseek-r1-with-net-5e9cd8ab7780?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e9cd8ab7780</guid>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 20:21:40 GMT</pubDate>
            <atom:updated>2025-11-28T21:44:53.901Z</atom:updated>
            <content:encoded><![CDATA[<h3>Local DeepSeek-R1 with .NET</h3><p>The journey of chatting with a local LLM on my MacBook Pro, using .NET.</p><figure><img alt="AI generated banner image representing abstract ideas of when DeepSeek meet .NET C#" src="https://cdn-images-1.medium.com/max/1024/1*0K4nC8BPRYj5mivTgu_47g.jpeg" /></figure><p>It is easy to use ChatGPT or other genAI nowadays with just your browser. As a developer we can do more sophisticated things by directly integrating like OpenAI API. What if we want to run a LLM on our machine, just for having someone to chat with or developing something funny?</p><p><a href="https://www.deepseek.com/">DeepSeek</a> recent models release causing ripples in the software and tech industry. Thanks to the <a href="https://github.com/deepseek-ai/DeepSeek-R1/blob/main/DeepSeek_R1.pdf">distillation</a> technique, the much smaller, resource affordable models can now similarly powerful on specific tasks. No matter in genAI or ML world, Python is the dominant stack. Although I know Python personally, as a tradition of #EverythingInCSharp series. In this post I am documenting how did I have the deepseek-ai/DeekSeek-R1-Distill-Llama-8B model run in a C# program.</p><ol><li>Pre-requisites</li></ol><ul><li><a href="https://www.python.org/downloads/">Python 3</a>+</li><li><a href="https://dotnet.microsoft.com/en-us/download">.NET8+</a></li><li><a href="https://git-scm.com/">Git</a> with lfs support</li></ul><p>Since .NET cannot make use of hugging face models directly in .safetensorsformat, you will either need to convert the .safetensors format into .gguf(GPT-Generated Unified Format) or download one converted and uploaded to <a href="https://huggingface.co/">Hugging Face</a> by other people (e.g. <a href="https://huggingface.co/lmstudio-community/DeepSeek-R1-Distill-Llama-8B-GGUF">this</a>). Skip to point 5 if you don’t want to convert it by your own.</p><p>2. Download the model</p><p>Clone the model repository with the following git commands, beware that the model files are 15GB large:</p><pre>git clone https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-8B</pre><p>3. Clone the Llama.cpp repo</p><p>You will need the conversion script inside to transform HuggingFace format in to GGUF format.</p><pre>git clone https://github.com/ggerganov/llama.cpp.git</pre><p>4. Convert the model</p><p>Before I can successfully run conversion script, I have to:</p><p>4.1 Setup a virtual environment:</p><pre>cd llama.cpp<br>python3 -m venv .<br>source bin/activate</pre><p>4.2 Install the following packages:</p><pre>python3 -m pip install numpy torch sentencepiece gguf safetensors transformers</pre><pre>python3 convert_hf_to_gguf.py  --outfile your_filename.gguf ../DeepSeek-R1-Distill-Llama-8B</pre><p>You will see the following when done:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRKup9fq4X1_4_hdfHO3cA.png" /></figure><p>5. Create a new C# console program:</p><pre>dotnet new console</pre><p>6. Install required packages:</p><p>Since the model is llama based, we will need LlamaSharp</p><pre>dotnet add package LLamaSharp </pre><p>I am using Macbook Pro therefore I will need to install a specific backends too:</p><pre>dotnet add package LLamaSharp.Backend.Cpu</pre><p>If you are not using Mac please refer to the official list of backends available <a href="https://github.com/SciSharp/LLamaSharp/tree/master?tab=readme-ov-file#integrations--examples">here</a>.</p><p>7. Code to create a chat session:</p><p>I will copy the sample code from LlamaSharp readme to replicate the minimal chat session setup:</p><pre>using LLama;<br>using LLama.Common;<br>using LLama.Sampling;<br><br>string modelPath = @&quot;DeepSeek-R1-Distill-Llama-8B.gguf&quot;; // change it to your own model path.<br><br>var parameters = new ModelParams(modelPath)<br>{<br>    ContextSize = 1024, // The longest length of chat as memory.<br>    GpuLayerCount = 5 // How many layers to offload to GPU. Please adjust it according to your GPU memory.<br>};<br>using var model = LLamaWeights.LoadFromFile(parameters);<br>using var context = model.CreateContext(parameters);<br>var executor = new InteractiveExecutor(context);<br><br>// Add chat histories as prompt to tell AI how to act.<br>var chatHistory = new ChatHistory();<br>chatHistory.AddMessage(AuthorRole.System, &quot;Transcript of a dialog, where the User interacts with an Assistant named Bob. Bob is helpful, kind, honest, good at writing, and never fails to answer the User&#39;s requests immediately and with precision.&quot;);<br>chatHistory.AddMessage(AuthorRole.User, &quot;Hello, Bob.&quot;);<br>chatHistory.AddMessage(AuthorRole.Assistant, &quot;Hello. How may I help you today?&quot;);<br><br>ChatSession session = new(executor, chatHistory);<br><br>InferenceParams inferenceParams = new InferenceParams()<br>{<br>    MaxTokens = 256, // No more than 256 tokens should appear in answer. Remove it if antiprompt is enough for control.<br>    AntiPrompts = new List&lt;string&gt; { &quot;User:&quot; }, // Stop generation once antiprompts appear.<br><br>    SamplingPipeline = new DefaultSamplingPipeline(),<br>};<br><br>Console.ForegroundColor = ConsoleColor.Yellow;<br>Console.Write(&quot;The chat session has started.\nUser: &quot;);<br>Console.ForegroundColor = ConsoleColor.Green;<br>string userInput = Console.ReadLine() ?? &quot;&quot;;<br><br>while (userInput != &quot;exit&quot;)<br>{<br>    await foreach ( // Generate the response streamingly.<br>        var text<br>        in session.ChatAsync(<br>            new ChatHistory.Message(AuthorRole.User, userInput),<br>            inferenceParams))<br>    {<br>        Console.ForegroundColor = ConsoleColor.White;<br>        Console.Write(text);<br>    }<br>    Console.ForegroundColor = ConsoleColor.Green;<br>    userInput = Console.ReadLine() ?? &quot;&quot;;<br>}</pre><p>8. Run and try:</p><pre>dotnet run</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQGVar6Q_T56LYiNFH0OGg.png" /></figure><p>On my M3 Pro 12-cores CPU Macbook, the token generations used 45% CPU time, while it use around 16GB memory. The memory usage pretty much the same as the size of the model itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQ7pNu5_18NlK_p3z_3-Ew.png" /><figcaption>CPU usage while generating tokens</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W5xCf-_uMp6Ljc_9VhObRQ.png" /><figcaption>Memory usage while generating tokens</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZU8pcPr68Z-WDWU53uI-rA.png" /><figcaption>Memory usage while not generating tokens</figcaption></figure><p>Enjoy! 🎉 I can’t wait to see what your C# code can do with your local LLM! 😀</p><p>This post is also available on my personal <a href="https://ferrywl.to/blogs/2025/02/2025-02-02-local-deepseek-r1-with-net/">blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e9cd8ab7780" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The missing piece in Blazor client-side authentication tutorial.]]></title>
            <link>https://ferrywlto.medium.com/the-missing-piece-in-blazor-client-side-authentication-tutorial-a94b297b30a6?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/a94b297b30a6</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[blazor]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[blazor-webassembly]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Sat, 02 Apr 2022 11:36:14 GMT</pubDate>
            <atom:updated>2025-11-28T21:44:20.658Z</atom:updated>
            <content:encoded><![CDATA[<p>We just want a dummy login screen for demo purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dck_6MWIilE_8CUB" /><figcaption>Photo by <a href="https://unsplash.com/@bamin?utm_source=medium&amp;utm_medium=referral">Pierre Bamin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Back in time when I start learning authentication in Blazor, I feel frustrated as almost every tutorial are talking about creating a Blazor Server project, using Identity framework, and some CURD operations on SERVER side. Hey I know how to do authentication on server side as people learning Blazor are most likely C# developers, we learn Blazor for full-stack C# opportunities so we have additional choice for creating frontend code other than React/Vue/Angular.</p><p>This is the missing piece of Blazor client-side authentication tutorial and answers the following questions:</p><ul><li>How to create a login screen that every user will go to this page by default?</li><li>How to hide other screens from user access when they are not logged in?</li></ul><p><strong>Note</strong>: Client side authentication is fragile, don’t depends on it. The aim of this article is not about security, it’s all about UI. There are lots of tips and tricks you can find on the Internet on security hardening for both client and server side.</p><h4>Steps</h4><ol><li><strong>Required dependencies:</strong></li></ol><ul><li>Microsoft.AspNetCore.Authorization</li><li>Microsoft.AspNetCore.Components.Authorization</li><li>Microsoft.AspNetCore.Components.WebAssembly.Authentication</li></ul><p>Let’s create a Blazor wasm project. We are using .NET 6 in this project.</p><pre>dotnet new blazorwasm<br>dotnet add package Microsoft.AspNetCore.Authorization<br>dotnet add package Microsoft.AspNetCore.Components.Authorization<br>dotnet add package AspNetCore.Components.WebAssembly.Authentication</pre><p><strong>2. Create MyCustomAuthenticationStateProvider</strong></p><ul><li>It must extends from AuthenticationStateProvider</li><li>Override GetAuthenticationStateAsync() and set default user to an anonymous user with no claims.</li><li>Prepare faked sign-in and fake users.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a2fe3f54a098c9ddad52ef2ca64253e/href">https://medium.com/media/1a2fe3f54a098c9ddad52ef2ca64253e/href</a></iframe><p>This class is where all the magic happens. We will return to this later in this article.</p><p><strong>3. Config Program.cs</strong></p><p>We need to add these lines to Program.cs :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0aa7f61c67be4c5c869399700d588594/href">https://medium.com/media/0aa7f61c67be4c5c869399700d588594/href</a></iframe><p>Caution on how we instantiate an MyAuthenticationStateProvider object and provide it to service container as AuthenticationStateProvider.</p><p>Otherwise a default AuthenticationStateProvider object will be used by Blazor instead of our implementation.</p><p><strong>4. Setup _Imports.razor</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4b8977c9e4e73a37d9d3476872cbb28/href">https://medium.com/media/b4b8977c9e4e73a37d9d3476872cbb28/href</a></iframe><p>Note we placed @attribute[Authorized] here to make all pages requires authorization by default.</p><p><strong>5. Create login screen</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21fb55ff1d4a2ce0d028a3aa8d38cdc6/href">https://medium.com/media/21fb55ff1d4a2ce0d028a3aa8d38cdc6/href</a></iframe><p>Note that we need to place [AllowAnonymous] attribute here to allow user access without sign-in.</p><p>Then we have two buttons to simulate sign-in for normal user and admin user:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b5b94b8179802d4507e1ba325c480f4/href">https://medium.com/media/3b5b94b8179802d4507e1ba325c480f4/href</a></iframe><p><strong>6. Create RedirectToLogin component</strong></p><p>This is a dummy component to simply redirect user back to /login page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99386f9a028ae47906a24b236cf3343b/href">https://medium.com/media/99386f9a028ae47906a24b236cf3343b/href</a></iframe><p><strong>7. Wrap MainLayout with </strong><strong>&lt;AuthorizeView&gt;</strong></p><p>We wrap the original content in `MainLayout.razor` with `Authorized` tag:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3aa8ff27f1866e82fef873662738a10/href">https://medium.com/media/d3aa8ff27f1866e82fef873662738a10/href</a></iframe><p><strong>8. Include admin only content in </strong><strong>NavMenu</strong></p><p>In Shared/NavMenu.razor, we will wrap the original link to fetchData screen with &lt;AuthorizeView&gt; tag and set the role required to see this link to “<strong>admin</strong>”. We also add a button for user to logout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc3d705207f8b2d5a669a9cbdff29a97/href">https://medium.com/media/fc3d705207f8b2d5a669a9cbdff29a97/href</a></iframe><p><strong>9. Wrap routing with </strong><strong>&lt;AuthorizeRouteView&gt;</strong></p><p>In App.razor, replace &lt;RouteView&gt; tag with &lt;AuthorizeRouteView&gt; tag. Then place our RedirectToLogin component inside &lt;NotAuthorized&gt; tag. So whenever a user access a route that exists but not authorized yet, Blazor will redirect them back to login screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6dec5104f147a85c8c2d4414fc9f46f/href">https://medium.com/media/a6dec5104f147a85c8c2d4414fc9f46f/href</a></iframe><p><strong>10. Config action for unmatched routes.</strong></p><p>In App.razor, make sure to fill the NotFound tag, this is what Blazor will do when a user try to access a route that doesn’t exist. If user try to access /something-not-exist, which is not in [‘/&#39;,&#39;/counter’,&#39;/fetchData&#39;,&#39;/login&#39;] will just shows what you have put inside the &lt;NotFound&gt; tag. In our case, it displays “<strong>Page not found</strong>”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d0ae0e34606a10461ce23544e346396/href">https://medium.com/media/2d0ae0e34606a10461ce23544e346396/href</a></iframe><p><strong>11. Run and test yourself</strong></p><ol><li>Run and test our project by dotnet run.</li><li>Open browser and go to the root of our Blazor app.</li><li>Notice that although you are requesting /, but you are now redirected to /login page.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*Y4djl_ws3rqlhxIVo23DCQ.png" /></figure><p>This is because we have these code in App.razor :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e0199d08a9cd1dc11a76fe8623e047b/href">https://medium.com/media/6e0199d08a9cd1dc11a76fe8623e047b/href</a></iframe><p>The / route was defined in Index.razor, so it fall-into &lt;Found&gt; tag. And then since we are not logged in, therefore it further fall into &lt;NotAuthorized&gt; tag and finally we landed to &lt;RedirectToLogin /&gt;component. When the component initialize, it calls _navigationManager.NavigateTo(&quot;/login&quot;). That’s why we see the login screen.</p><p>Now go to the address bar of our browser, type in a route that’s not defined in any page. (e.g. “https://localhost:5000/something-not-exist&quot;).</p><p>Since no route matched, App.razor fall into &lt;NotFound&gt; tag and we will only see a message stating page is not found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*8XFO58Pefo5XYqmsLrnwWQ.png" /></figure><p>About MyAuthenticationStateProvider :</p><p>This class extends AuthenticationStateProvider and override a method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b28f461639221515585b39c91e877d50/href">https://medium.com/media/b28f461639221515585b39c91e877d50/href</a></iframe><p>This method will be called when user trying to access authorized page. Blazor will look for an AuthenticationState object to determine what claims the current user has and whether allow the user access specific pages.</p><p>The AuthenticationState object expect an ClaimsPrincipal object with claims like username, roles, etc.</p><p>If an ClaimsPrincipal object has no claims, it is considered an anonymous user. This is the trick we used in MyAuthenticationStateProvider:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbdfff7ba03c96ee12dd0c3e1a4b04d4/href">https://medium.com/media/fbdfff7ba03c96ee12dd0c3e1a4b04d4/href</a></iframe><p>Finally, return to our login screen and try the different login button.</p><p>When you click on the normal sign-in button, you will not see the fetch data link on the navigation menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*SvHDVyovNwOR6f1KcMkSiw.png" /></figure><p>Click the logout button and we will return to login page.</p><p>Now click on the admin login button. This time we will see the fetch data link on the navigation menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*t-pP-EE7sa7CqCow8gZR0w.png" /></figure><p>This is because our faked ClaimPrinciple object has the ClaimTypes.Role set to “<strong>admin</strong>” and we have set the roles required to render the fetch data link to “admin”: &lt;AuthorizViews Roles=&quot;admin&quot;&gt;</p><h3>Summary</h3><p>Today we learned how to create a login page and redirect all unauthorized access back to that page in Blazor. It is completely on client-side for quick UI prototyping purpose, when building your web app you should combine server-side authentication and token management logic in your MyAuthenticationStateProvider. That’s it for now and stay tuned for my next #EverythingInCSharp article. As always you can take a look in the source code <a href="https://github.com/ferrywlto/blazor-wasm-client-auth">[here]</a> if you encounter difficulties. Have a nice day! 😀</p><p>This post is also available on my personal <a href="https://ferrywl.to/blogs/2022/04/2022-04-02-the-missing-piece-in-blazor-client-side-authentication-tutorial/"><strong>blog</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a94b297b30a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your automation buddies in C#]]></title>
            <link>https://ferrywlto.medium.com/your-automation-buddies-in-c-cbfbe77c29cb?source=rss-f5ada568f082------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbfbe77c29cb</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[cronjob]]></category>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Ferry To]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 11:13:25 GMT</pubDate>
            <atom:updated>2025-11-25T14:55:26.463Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/254/0*pAzO-cChcxzLG3JL.png" /></figure><p>Hello everyone! Welcome to my #Everything in CSharp series. This time we write fewer code than before because we want our computer work for us. One of the programmers’ task is to automate things and to reduce human workload. Let’s say you want to monitor some website data, but implementing a useful scheduler is not an easy task. Unix/Linux power users may probably know cron jobs, today we will learn how to do it in C#.</p><p>Let’s start create a C# project and a simulated job:</p><pre>dotnet new console<br>touch SimulatedJob.cs</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac88086a5a6a9dea0b9fdbac9ae797ef/href">https://medium.com/media/ac88086a5a6a9dea0b9fdbac9ae797ef/href</a></iframe><p>The job simply return an integer on every 5th call. Otherwise it will throw an exception. This simulate some remote lengthy process under poor network connection.</p><p>Handling retry and recovery of calling such service could be a tedious work. Luckily we have our first buddy today: <strong>Polly</strong></p><p><a href="http://www.thepollyproject.org/">The Polly Project</a></p><p>From the project’s <a href="https://github.com/App-vNext/Polly">GitHub repository site</a>:</p><blockquote>Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.</blockquote><p>Polly is open-source, under active development and popular (more than 10K stars) among .NET developers. Let’s add Polly into our project.</p><pre>dotnet add package polly</pre><p>Now we can write the code to consume our not that reliable job:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/696942724615eaf9f20a32a87414ebee/href">https://medium.com/media/696942724615eaf9f20a32a87414ebee/href</a></iframe><p>First we need to create a retry policy to handle when the service we call throws exceptions. In our example we simply print the exception message and then continue. We also set how many times we will retry and how long to wait before next retry in the chaining method WaitAndRetry() .</p><p>Now we make our call become resilient and able to recover from transient errors. To build a simple automation system, we need not only a scheduler, more ideally it should also able to manage multiple scheduled tasks. If you want to implement these by your own it will take a long period of time I guess. The good news is the second buddy I introduce today have you all covered!</p><p><a href="https://www.hangfire.io/">Hangfire - Background Jobs for .NET and .NET Core</a></p><p>Hangfire is free, open-source, lightweight library not only can run schedule jobs for you, it also handles queuing. It can even resume your queued jobs in persistent storage. Form their <a href="https://github.com/HangfireIO/Hangfire">GitHub repository page</a>:</p><blockquote>An easy way to perform background job processing in your .NET and .NET Core applications. No Windows Service or separate process required.</blockquote><p>To add Hangfire in our project:</p><pre>dotnet add package HangFire</pre><p>We also use in memory storage instead of real database for demo purpose:</p><pre>dotnet add package HangFire.InMemory</pre><p>To demonstrate how simple you can integrate with Hangfire, open Program.cs and edit like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3e0e3668f61fc3ba56a7c77f06821c4/href">https://medium.com/media/f3e0e3668f61fc3ba56a7c77f06821c4/href</a></iframe><p>Note that at line 5 we config Hangfire with in memory storage instead of persistent datastore like SQL Server. Then we setup a recurring job to execute once per minute at line 7. If you are familiar with <a href="https://crontab.guru/">cron job syntax</a>, you can pass “* * * * *” instead of Cron.Minutely .</p><p>Then we need to instantiate a BackgroundJobServer object. This object is required to kick start all our scheduled jobs.</p><p>Finally since this is a console program, we need a way to keep the program up and running in order to wait and see the job executions. The line Console.ReadLine() at the end is for this purpose. In project like ASP.NET it is not needed.</p><p>Let’s see our minimal automation program in action:</p><pre>dotnet run</pre><p>Wait 2 minutes and you will see the job is running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*qUrCGR6J3mNamuUzdTCqsw.png" /></figure><p>On every minute <strong>Hangfire</strong> execute the job we wrapped in <strong>Polly</strong>, it will fail four times and then return multiple of 5 on the 5th attempt.</p><p>Today we learned how to combine <strong>Hangfire</strong> and <strong>Polly </strong>to create a minimal automated system. By mixing various job type, scheduling options, queuing and recovery policy you can build a very complex system to fit your automation needs. The sky’s the limit.</p><p>That’s it for today and hope you enjoy it. As always, you can access the source code in my <a href="https://github.com/ferrywlto/PollyHangFire">GitHub repository</a>. Stay tuned for my next #Everything in CSharp series! Have a good day and see you next time. 😃</p><p>This post also available on my <a href="https://ferrywl.to/blogs/2022/03/2022-03-19-your-automation-buddies-in-c/">personal blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbfbe77c29cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>