Skip to main content

Posts

.NET 6–How to use arguments in your Console app?

In .NET 6 (and newer) when you create a new Console application , the result is really minimal: That is a big difference if you compare this with what you had before: This is possible thanks to some new C# features like Top Level Statements and Implicit Using Directives . But what if you want to use arguments inside your Console app? Before the arguments where available through the ‘args’ parameter that was available as an argument of the ‘Main’ method. But now there is no method, so what should you do? Turns out that you can just use the args parameter although it isn’t defined anywhere: Behind the scenes the compiler will generate a Main method for your and provide the args parameter. From the documentation : The entry point method always has one formal parameter, string[] args . The execution environment creates and passes a string[] argument containing the command-line arguments that were specified when the application was started. The string[] argument i...

SQL Server - Change the column size without needing a DROP / RECREATE

While monitoring a production system, I noticed a lot of "String or binary data would be truncated" exceptions. This is an indication that the string data that would be persisted is larger than the database column allows. That’s an easy one to fix! So I opened up SQL Server Management Studio , right click on the table that was causing the problem and choose Design from the context menu. I altered the column size and hit Save . However this resulted in the following message: SQL Server Management Studio tries to handle the resize operation by executing a ‘DROP’ and re‘CREATE’ of the table. As this would result in a loss of all the data, the operation is prevented. But I’m making an existing column larger. I would except that this is a safe operation that can be executed without any risk of data loss? Instead of using the designer I switched to a small SQL snippet: Remark: Don’t forget to include the ‘NOT NULL’  modifier otherwise you end up with a NULL...

Azure Application Insights – Set cloud role name in your Javascript frontend

One of the nice features of Application Insights, is the Application Map. This gives you a visual clue of all the parts of your application and their dependencies. I blogged before on how you could tweak this application map through a custom TelemetryInitializer: In your C# backend In your Angular SPA Today I want to share another option when you are using the Javascript snippet inside your web frontend. Inside the snippet you should use the onInit callback to inject a TelemetryInitializer: Here is the full snippet as well:

Blazor - Failed to find a valid digest in the 'integrity' attribute

After making a small change to a Blazor application, I redeployed it to an Azure App service. When I tried to open the updated Blazor application nothing happened. When I opened up the browser console, I noticed a list of errors: There are 2 errors important to explain what is going wrong: Failed to find a valid digest in the 'integrity' attribute for resource 'https://cloudbreweshopweb.azurewebsites.net/_framework/dotnet.timezones.blat' with computed SHA-256 integrity '2NJf++ql6UnbRRdYWEir6MxH58bYGWDEqofII/z+Xmo='. The resource has been blocked. Failed to find a valid digest in the 'integrity' attribute for resource 'https://cloudbreweshopweb.azurewebsites.net/_framework/dotnet.wasm' with computed SHA-256 integrity 'y0gwhQ7a6FTinj6R6HEA3SlRDb/iL70a56PEGpKbt/8='. The resource has been blocked. This is related to the integrity checks executed by the browser. Integrity checks When Blazor WebAssembly downloads an app's st...

Visual Studio 2022 17.4 - Error MSB4024

Last week the latest Visual Studio 2022 update was announced; v17.4. This is not a post about all the new features but about an issue I encountered after doing the update. In the previous release Live Unit Testing was announced as a preview. At that time I enabled this preview feature to check what was possible and help me in my test driven development lifecycle. After installing the 17.4 update, this caused an unexpected side-effect. I no longer succeeded in compiling any of my projects and all of them failed with exceptions like this: Build started... 1>------ Build started: Project: BlazorShared, Configuration: Debug Any CPU ------ 1>D:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Microsoft.Common.props(73,3): error MSB4024: The imported project file "D:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Imports\Microsoft.Common.props\ImportBefore\Microsoft.LiveUnitTesting.props" could not be loaded. Root elemen...

Visug XL 2022 - Microservices The last mile

Last Friday I did a presentation at Visug XL . If you missed my presentation or are interested in the slides, I've made them available for download here . No idea what my talk was about? Here is the abstract: There it is! After months of struggling your well decomposed microservices architecture finally sees the light. Nicely separated services with their own datastore, well defined service boundaries, clear API contracts, … . A software architect dream is coming true. But now you need to start working on the frontend and gone is all your clean separation! In this session we’ll walk the last mile and evaluate multiple ways on how to bring information from multiple (micro) services together so that they can be consumed by the frontend. ViewModel composition, gateway aggregation, Backend for Frontends, GraphQL Federation and other options are compared and pro’s and con’s of each technique will be discussed.  

Help! My IFormFile collection remains empty

Thanks to the built-in model binder feature in ASP.NET Core, uploading files is easy. You only need to specify an IFormFile as an action method parameter and the framework does all the hard work for you. All very handy and easy, until it doesn't work... Today I had an issue when I tried to upload multiple files at once. This is certainly supported and should work with any of the following collections that represent several files: IFormFileCollection IEnumerable < IFormFile > List < IFormFile > Here is a code example: Nothing wrong with the code above I would think. But unfortunately it didn’t work… To make it even stranger, although the List<IFormFile> remained empty, the uploaded files where available when I directly accessed the HttpContext and took a look at the Request.Forms.Files property. The problem turned out to be related in the way I uploaded the files. I had created a small helper library to construct the MultipartFormDataCon...