Skip to main content

Posts

How to embed PowerFX in NET app

How to embed PowerFX in a .NET Application PowerFX is a language from Microsoft aimed at power users. Writing PowerFX feels like Excel formulas, and one of the building blocks of PowerFX is actually “formulas” that are reactive to other formulas. Microsoft uses PowerFX mainly as the low code language for the PowerApps offering. A few years ago, Microsoft open sourced PowerFX with the goal of letting others take advantage of the power and simplicity of the language. The main repo is located at https://github.com/microsoft/Power-Fx . The repo contains a link nice introductory video about the what, why and how of PowerFX ( https://www.youtube-nocookie.com/embed/ik6k89WNjuk ). If you are a .NET developer, you too can take advantage of the power and simplicity of PowerFX by embedding a .NET PowerFX Interpreter created by Microsoft. One use case for embedding PowerFX in a .NET app is to allow Business Users to define Business Rules in PowerFX and then integrate them into your app. This all...

How to read build variables in Source Generators

How to read build variables in Source Generators I used GitHub copilot to help me create a source generator that reads the schema of a database and generates C# ADO.net code that can call SQL Stored Procedures, Views and Functions in that database ( https://github.com/TheJuanitoLearnsShow/Puppy.Ado.SourceGenerator ). The connection string to the database is set on a build variable in the consuming csproj file. The problem is that copilot missed the step described in Microsoft’s Source Generator Cookbook . The missing step is to add a CompilerVisibleProperty element to an ItemGroup for each of the build variables you want the source generator to use. For example, my source generator uses two build variables: DbGen_EnableLiveSchema and DbGen_ConnectionString, so they are defined in the PropertyGroup element in the consuming csproj file: <DbGen_EnableLiveSchema>true</DbGen_EnableLiveSchema> <DbGen_ConnectionString>Data Source=.\sqlExpress;Database=AutomatedTESTS_AdoGen...

APIM requests not showing downstream requests in application

APIM requests not showing downstream requests in application insights In Application Insights, if you are not seeing the telemetry for the backend service being called by APIM, it could be you have the wrong type of correlation type option set under that API’s settings in APIM. The correct setting, for newer web apps that use the latest open telemetry or application insights nugets should be W3C . The default value is Legacy so you will need to change it to W3C. Without that correlation, the appropriate headers will not be included in the request to the backend service from APIM and the two parts of the request would appear as separate flows inside Application Insights.

Expose SQL Logic as APIs - Domain Driven Design in SQL

Most Domain Driven Design articles and books teach you to develop your business logic in such a way that there is no trace of a database or other dependency that would make your business logic (also known as Core code or Domain Logic) impure. That is great advice if you are developing your core business logic in a programming language that is not SQL . But what if all you know if SQL or SQL is your strong skill? The answer is yes, you can develop your domain logic in SQL in a domain driven way, if you try to adhere to the spirit of the DDD concepts. Objects or Tables? One of the main arguments for developing Domain Logic in Object-Oriented languages is that “real” world things are objects and thus is easier to model those real-world things in classes. But if you are in an organization and you start talking to Business Units about the logic they need, you would find that the concept of “spread sheets” are actually very familiar to them. It is so familiar, that countless of Business Unit...

Expose SQL Logic as APIs

HTTP-based APIs have become a very popular way of exposing functionality to external entities outside an organization. For example, in order to support certain features of their products, some Vendors require integrating with your data real-time by calling HTTP APIs to get the information they need. Or maybe you have a very tech-savy customer that would like to get their data via APIs your organization exposes. Typically, a Development Team spins up those APIs using programming languages and platforms such as .NET and Java. But what if your organization only has Microsoft SQL developers? In this series of posts, I would like to propose that they are able to encapsulate the needed logic into T-SQL stored procedures and/or views without the need of the work of a typical development team. This is great for those “multiple hats” DBAs who might not be strong enough in regular languages, but with good enough skills to do some basic managing in Azure. Here is an overview of the process: Desig...
How can you allow a Business User to maintain the business logic of your application? If your business users are Excel-savvy (as much business users are), then you could use Microsoft’s Graph API to access and run the logic within those Excel workbooks ( workbook resource type - Microsoft Graph v1.0 | Microsoft Learn ). This is not the OLE Automation of years past. We are talking about calling an HTTP based API. The approach is simple, from the business user side: Have the business users create the workbook and adjust it so that it performs the business rules it needs. They can designate some of the cells to be used as the “parameters” for the business logic. For example, given the values of cells A2 and B2 , run a series of formula calculations whose final result is in cell B30 . Save the excel workbook in a folder in your business’ OneDrive. Then, from your application code, make a series of HTTP calls to the MS Graph API: Get the Auth Token Call the createSession endpoint to creat...

Sql Server Projects (sqlproj) deployment via CLI

Sql Server Database projects are a great way to define your database structure and keep in in source control. Instead of maintaining a large list of migration scripts, you can instead define your database declaratively in the Sql Project as if you were creating a .net solution. This project style also facilitates the publishing of changes to Sql Servers. The publish process automatically detects what needs to change and creates the necessary Sql code to perform those changes. One of the challenges of using Sql Server Database projects is to include the Sql Project in your CI/CD pipeline so that it can automatically publish the changes to a Sql Server. Microsoft has migrated the Sql Server Database project format to the new “SDK style” project (introduced by .NET core). A generic way to integrate it is to call the commands from the command line as most CI/CD pipelines support some sort of command line invocation. The steps to run from the pipeline are: Build the project so that it gener...

Can use Integrated Security via .net but not via JDBC

I encountered an obscure issue when trying to connect to a SQL Server database using Windows Integrated Authentication from Java. My JDBC URL was correct but I kept getting the following error: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. And the SQL logs in the SQL server were showing the following: SSPI handshake failed with error code 0x80090346, state 46 while establishing a connection with integrated security; the connection has been closed. Reason: The Channel Bindings from this client are missing or do not match the established Transport Layer Security (TLS) Channel. The service might be under attack, or the data provider or client operating system might need to be upgraded to support Extended Protection. The puzzling thing was that I was able to connect fine suing the system.data.sqlclient from .net and from SQL Server Management Studio from the same machine and doma...

First Twitch Stream

Inspired by what Jeff Fritz ( https://www.twitch.tv/csharpfritz ) said on .net rocks ( https://www.dotnetrocks.com/?show=1575 ), I decided to try doing a very small F# tutorial using Twitch: https://www.twitch.tv/videos/716521139

How to debug workflow console projects in Visual Studio 2019 using Designer Breakpoints

I ran into an issue with debugging a Workflow Foundation workflow by using breakpoints in the designer in Visual Studio 2019. The breakpoints in the designer were not being hit when running the console workflow program in debug mode.  A question posted by another member of the community at https://developercommunity.visualstudio.com/content/problem/846593/not-able-to-debug-windows-workflow-designer.html led me to another link at https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/retargeting/4.7.2-4.8#windows-workflow-foundation-wf .  In that last page, at the bottom, under the "Workflow XAML checksums for symbols changed from SHA1 to SHA256", I found the piece of configuration code to add to my app.config file in the console workflow VS project. The following is the full configuration of my project that allowed VS to pause at the designer breakpoints: <?xml version="1.0" encoding="utf-8" ?> <configuration>     <startup>   ...

Previously trusted client certificate not longer trusted by IIS

I was getting the following error from iSS when testing locally a web api that requires ssl client certificates: 403.16  The client certificate used for this request is not trusted by the Web server One way to troubleshoot is to use the certutil tool that comes with Windows. There is a verify switch that you can use to verify the public portion of the client certificate: certutil -f -urlfetch -verify "public client cert.cer" The tool will show any errors encountered when validating the cert, such as a failure to lookup the revocation list (CRL) of the issuer. You can also capture the details of the client certificate, like the subject name, issuer and serial number, by adding custom fields to your IIS log. Instructions are here and the fields are under "Server Variables".  The specific issue I was having, however, is described in the answer to  https://stackoverflow.com/questions/26247462/http-error-403-16-client-certificate-trust-issue  . I had a Trusted Root cert...

Power Automate: SFTP action "Test connection failed"

When I added an SFTP create file action to my Power Automate flow ( https://flow.microsoft.com ) , I got the following error in the action step, within the designer: "Test connection failed" To troubleshoot the Power Automate connection, I had to: go the Power Automate portal then "Data"->"Connections"  the sftp connection was there, I clicked on the ellipsis, and entered the connection info It turns out, that screen provides more details about the connection error. In my case, it was complaining that "SSH host key finger-print xxx format is not supported. It must be in 'MD5' format". I had provided the sha fingerprint that WinScp shows. Instead, I needed to use the MD5 version of the fingerprint. To get that, I had to run in command line (I was in a folder that had openssh in it): ssh -o FingerprintHash=md5 mysftpsite.com To get the fingerprint in MD5 format. I took the string (without the "MD5:" part of the string) and put ...

Windows Workflows Foundation in Azure Functions

Unfortunately, I have not been able to make the CoreWf library ( https://github.com/UiPath-Open/corewf ) run on an Azure v2 or v3 functions. Something about the Azure function runtime not able to fins the dependencies like System.Xaml or System.CodeDom. However, Azure v1 functions (which run on .net 4.6.1) have no problems running a Workflow created using the Workflow Designer in Visual Studio. A sample of such function is in  https://github.com/jptarqu/WorkflowForCorePlayground/tree/master/src/AzureSamples  .  I did run into an issue creating from Visual Studio the Function App Service with runtime version of "1". I was seeing "runtime: error" in the portal's overview page for the app service. To work around that issue, I created the function app service inside the Azure Portal and then changed it to version 1 inside the portal (the default is v3 and you cannot change it until the App Service is created).

Workflows using CoreWF in .net core

Workflow Foundation is a great tool when designing workflows for .net. Unfortunately, just like WCF, that technology is not going to be ported to .net core. However, a company named UI Path ( https://www.uipath.com/ )  that heavily relies on Windows Workflow Foundation, has started an unofficial port to .net ( https://github.com/UiPath-Open/corewf ). In order to see how compatible would be the the new port with the current Windows Workflow for simple workflows, I created a playground project at   https://github.com/jptarqu/WorkflowForCorePlayground  . The Visual Studio solution contains two projects: WorkflowForCorePlayground  : a VB.net Windows Workflow project created using the VS template for .net 4.8.  CoreWfSample  : a .net core console app that runs a cleaned version of the same xaml that project #1 has. The idea is to explore the possibility of still having business users design the workflow using the regular .net framework 4.8 beautif...

Inexpensive, Non-realtime Sites using Queues

A lot of the sites for small and medium businesses rely on dynamic engines (such as ASP.NET, PHP, etc) to generate most of the content at run-time. This kind of typical setup requires expensive hosting (relative to a small and medium size company) and (if not designed properly) may not perform very well. I would like to argue that most of those sites could be served with static HTML pages generated offline at different time intervals (either fixed or on-demand intervals, discussed later) and a Javascript Client front end that communicates with a slim server side service whose only job is to store commands from visitors into a queue. The queue can then be read and processed by non-hosted computers, freeing the business from having to pay extra hosting fees for application server. The costs are reduced by the following: Static HTML sites mean less power required. Queue storages are usually cheaper services than full SQL Databases. A slim service that just relays the commands fr...

R Cookbook

The R Cookbook by  Paul Teetor ( O'Reilly Media) aims and succeeds in introducing programmers to the technical aspects of the R language. R is a programming language designed for Statistical work, therefore it might not share too much ground with other typical languages like Python or C. The R Cookbook gives a tour to programmers to this wonderful language, from the very screen output beginnings, through ploting, to the creation of statistical models and Time Series. The author does a great job exposing the differences and similarities of R to other languages. For example, the author, explains how in R the single brackets applied to a vector (myvector[1]) mean "give me a vector of one item from myvector", he then explains that the correct way to get a single item is myvector[1]. Comparisons to other languages like SQL are dispersed through the chapters. Mr. Teetor provides a throughout explanation of other aspects of R that might not be common in other computer lang...

List to ICollection AutoMapper and WebAPI problem

I was getting an exception from Automapper when it tried to map a List to an ICollection . The problem was that WebApi was building the MyClass from the xml sent by the client and instead of using a List for the ICollection property, it used a plain array. When Automapper tried to map the List to the Array, it failed because even though Arrays are ICollections, they do not support some of the ICollection operations, such as Add.  To solve the problem, I used Json in the client side when posting. After that, webapi chose to use List instead of an Array when the data came as Json.

Cryptic message when serializing Computed Observable to JSON

If you have an error in one of your computed observable in Knockout.js, the toJson function will set the value of that property to a cryptic script snipped when serializing it to JSON. For example: var SortField = function (expression) { this .FieldDef = ko.observable( null ); this .SortOrder = ko.observable( "" ); this .ExpressionType = "SortField" ; this .Label = ko.computed( function () { return this . FieldDef () == null ? "" : this . FieldDef ().Label + ' ' + this .SortOrder(); }, this ); } var FieldDefinition = function (table_name, field_name, table_alias) { this .TableName = table_name; this .TableAlias = ko.observable(table_alias); this .FieldName = field_name; this .Label = ko.computed( function () { return this .TableAlias() + '⇨' + field_name; }, this ); In this example SortField’s Label function ...

Compile Postgres in Windows with GSSAPI

Configuration Phase Install the 64 bit versions of OpenSSL and MIT Kerberos Get the professional version of Visual Studio 2010 or 2012. Open the 64Bit of the Visual Studio Command Prompt (not the 32 bit version) cd to src\tools\msvc in the folder that contains Postgres’ source code Change the config_default.pl: add these lines: includes => 'C:\\Program Files\\MIT\\Kerberos\\include:C:\\OpenSSL-Win64\\include', libraries => 'C:\\Program Files\\MIT\\Kerberos\\lib\\amd64:C:\\OpenSSL-Win64\\lib', after  “iconv   => undef,” change the krb5 and ssl lines to: krb5    => 'C:\\Program Files (x86)\\MIT\\Kerberos',    # --with-krb5= openssl => 'C:\\OpenSSL-Win64',    # --with-ssl= Build Phase in the vs command prompt, type Build When done, if no errors, then type Install C:\PathWhereYouWanToInstallPostgres Go to the folder where OpenSSL is installed Search in the folder and subfolders for libeay32 and ssleay.dll a...

How to use Windows SSO with OpenXava

One of the nice things about the .NET web environment is the dead easy way to implement Single Sign On in your web apps through Active Directory authentication. In the Java world there are multiple alternatives to use Windows’ Single Sign On with Java based web apps. One of those alternatives is Waffle . Waffle allows your Java web app to authenticate against Active Directory groups (and users). The only caveat is that your web server needs to be running in Windows, which kind of makes sense. In this article, you will learn the steps required to have your OpenXava web application use Waffle to authenticate your Windows users. The first step is to download Waffle from their site and then copy the JAR files outlined in https://github.com/dblock/waffle/blob/master/Docs/tomcat/TomcatSingleSignOnValve.md to the OpenXava’s tomcat server. In your OpenXava project, create servlets.xml in the Web-inf, containing the following: <!-- the role name (the domain gorup) must be e...