Skip to main content

Posts

Showing posts from March, 2020

ElasticSearch - Error when using latest OpenJRE

While migration from ElasticSearch 5 to 7.6.1 I had to take an extra step and first migrate to ElasticSearch 6.8. When I tried to run the 6.8 version, it failed with the following error message: 2020-03-30 10:18:32 Commons Daemon procrun stderr initialized OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. Exception in thread "main" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.jdk.internal.vm.annotation")                at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)                at java.base/java.security.AccessController.checkPermission(AccessController.java:1036)                at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:408)                at java.base/java.lang.SecurityManager.checkPackageAccess(S

ElasticSearch–Failed to run ElasticSearch 7.6.1 after upgrade

After upgrading ElasticSearch to 7.6.1, it failed to start when I tried to run ElasticSearch as a windows service. In the logs I found the following error message: [2020-03-30 10:04:11] [info]  [ 4516] Service 'elasticsearch-service-x64' installed [2020-03-30 10:04:11] [info]  [ 4516] Commons Daemon procrun finished [2020-03-30 10:04:23] [info]  [ 4336] Commons Daemon procrun (1.1.0.0 64-bit) started [2020-03-30 10:04:23] [info]  [ 4336] Running 'elasticsearch-service-x64' Service... [2020-03-30 10:04:23] [info]  [ 4992] Starting service... [2020-03-30 10:04:23] [error] [ 2432] CreateJavaVM Failed [2020-03-30 10:04:23] [error] [ 2432] The system cannot find the file specified. [2020-03-30 10:04:23] [error] [ 4992] Failed to start Java [2020-03-30 10:04:23] [error] [ 4992] ServiceStart returned 4 [2020-03-30 10:04:23] [info]  [ 4336] Run service finished. [2020-03-30 10:04:23] [info]  [ 4336] Commons Daemon procrun finished

C#–Discards

Have a look at the code below: Did you notice the underscore character ‘_’? This is the discard character. From the documentation : Starting with C# 7.0, C# supports discards, which are temporary, dummy variables that are intentionally unused in application code. Discards are equivalent to unassigned variables; they do not have a value. Because there is only a single discard variable, and that variable may not even be allocated storage, discards can reduce memory allocations. Because they make the intent of your code clear, they enhance its readability and maintainability. This is more than just a placeholder variable. If you try to use the assigned _ value later on in your code, this will fail:

Microsoft Orleans - Multi silo deployment behind a load balancer

In one of my projects we are using Orleans , the virtual actor framework from Microsoft. Your Orleans backend(the cluster) can span out over multiple servers(silos). In a cluster there are 2 types of communication  happening: silo-to-silo communication(through the silo port) client-to-silo communication(through the gateway port) As a result on every server 2 ports should be opened to enable this traffic. Load balancing The Orleans runtime does all the load balancing for you. More important it is one of the pillars of the Orleans runtime. The runtime tries to make everything balanced, since balancing allows to maximize resource usage and avoid hotspots, which leads to better performance, as well as helps with elasticity. More information: https://dotnet.github.io/orleans/Documentation/implementation/load_balancing.html This means that it doesn’t make sense to put a load balancer between the clients and the cluster as this would defy one of the core purposes of t

Autofac - Decorators

One of the nice features of Autofac is the support for decorators. A decorator class implements the same interface as the class it “wraps”.  With a decorator you can add functionality to a class without changing it’s signature. Let’s walk through an example step by step: Here is the class and it’s corresponding interface I want to decorate: Nothing special at the Autofac level yet: Let’s now extend the behavior of this class through a decorator. What if we want to benchmark the execution time of the LogMessage() method? The decorator class should implement the same interface AND inject the interface at the same time: Now we need to register the decorator in Autofac: Remark: When using generics, it is also possible to register an open generic  decorator. Therefore you need to use the RegisterGenericDecorator() overload More information: https://autofaccn.readthedocs.io/en/latest/advanced/adapters-decorators.html

C#–is null or == null that’s the question

While reviewing some code I noticed the following code construct: So far I’ve always written my null checks using the following syntax: I wasn’t aware that this was even possible. Turns out this was introduced in C# 7. Why would you use the ‘is’ keyword instead of ‘==’ ? The ‘is’ keyword ignores any operator overloads so you don’t end up with unexpected behavior when you are using operator overloading. Learned something today? Check!

Free SQL Server training during the quarantines

Brent Ozar did a nice gesture in these difficult times and gave away part of his training course for free. So if you really need to spice up your SQL server skills, this is really the training for you. Start with the ‘How to Think Like the Engine’: The Clustered Index Adding Non-Clustered Indexes Key Lookups and Cardinality Estimation Then continue with the ‘Fundamentals of Index tuning’: Indexing for the WHERE Clause Indexing for ORDER BY Indexing for JOINs Clippy's Index Recommendations Recap and Next Steps And if you want to go even deeper, take it to the next level with ‘Fundamentals of Query tuning’: Building a Query Plan How to Find the Right Queries to Tune How Parameters Influence Cached Plans Improving Cardinality Estimation Accuracy Common T-SQL Anti-Patterns Thanks Brent for all the great (free) content!

Autofac–Open Generics

After registering an open generic type in Autofac, I got the following error when running the application: Here is the code I was using to register my MediatR behavior in Autofac: Turns out that if you are using open generics you have to use a different method on the Autofac container builder: More information in the Autofac documentation: https://autofaccn.readthedocs.io/en/latest/register/registration.html#open-generic-components

Pluralsight–Free conference content

Yesterday Pluralsight announced a new platform experience: Conferences . Through conferences breakout sessions from some of the world’s best technology conferences are made accessible anytime, anywhere. As a gesture to the world Pluralsight made all Conference content free to everyone through July 1, 2020—even if you don’t have a current Pluralsight subscription.

WinRM - Testing your WinRM connection

While configuring a new server, I had to activate WinRM(Windows Remote Management). This is quite easy thanks to the winrm quickconfig command. This command will do the following: Starts the WinRM service, and sets the service startup type to auto-start. Configures a listener for the ports that send and receive WS-Management protocol messages using either HTTP or HTTPS on any IP address. Defines ICF exceptions for the WinRM service, and opens the ports for HTTP and HTTPS. To test the WinRM connection from another server, you can use the test-wsman command : PS C:\Users\bawu> test-wsman -computername tstsrv30 If everything is OK, you’ll get the following answer back: wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd ProductVendor   : Microsoft Corporation ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 3.0

ASP.NET Core–Use Dependency Injection in Authentication middleware events

Most of the authentication middleware in ASP.NET Core follows the same pattern; it exposes an options object where you can register for multiple events: But what if you want to use dependency injection inside an event handler? The moment the middleware is configured the IoC container is still in construction and is not accessible yet. What you can do is, instead of directly registering an event handler for a specific event is to specify an event class using the EventsType property :

Orleans - System.TypeAccessException: Named type "Messages.Example" is invalid: Type string "Message.Example" cannot be resolved.

While debugging an Orleans application, the following exception was thrown: System.TypeAccessException: Named type "Messages.Example" is invalid: Type string "Messages.Example" cannot be resolved. at Orleans.Serialization.BinaryTokenStreamReader.ReadSpecifiedTypeHeader() at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, BinaryTokenStreamReader stream) at Orleans.Serialization.BuiltInTypes.DeserializeOrleansResponse(Type expected, BinaryTokenStreamReader stream) at Orleans.Serialization.SerializationManager.DeserializeInner(Type expected, BinaryTokenStreamReader stream) at Orleans.Serialization.SerializationManager.Deserialize(Type t, BinaryTokenStreamReader stream) at Orleans.Serialization.SerializationManager.Deserialize(BinaryTokenStreamReader stream) at Orleans.Runtime.Message.DeserializeBody(List`1 bytes) at Orleans.Runtime.Message.get_BodyObject() at Orleans.Runtime.GrainReference.ResponseCallback(Message message, TaskCompletion

Building careers with empathy

Let’s end the week with an inspirational video. Scott Hanselman shares tips how to be successful as programmer and program manager. If there is one thing I remember from this video; “Knowing one layer deeper in the stack than your neighbors.”

Multiple inheritance in C#

One of my interview questions I dare to ask is “Can you do multiple inheritance in C#?”. So far, the correct answer always was ‘No’, but with the release of C# 8 the answer became more nuanced. Although a C# class can implement multiple interfaces it can inherit from only one base class.  Until C# 8, only the base class could provide code that is usable by the derived class. With C# 8, interfaces can also provide code to their implementing classes. This allows us to share code without a common base class. Finally we can do a (kind of) multiple inheritance…

ASP.NET Core–Tempdata Peek() and Keep()

Last week I blogged about the usage of TempData in ASP.NET Core . By default the data is stored until it's read in another request. After you have read the data through the indexer the data will be removed from the TempData dictionary: But what if you want to keep(no pun intended) the data around longer? This is possible through the usage of the Peek() and Keep() methods. With the Peek() method you can read the data without deleting it. With the Keep() method you can mark the data for retention. Nice trick!

Identity Server 4 - Angular–Chrome’s samesite cookie changes

Today I got into trouble when I tried to run an Ionic(Angular) application we had build. After being redirect to IdentityServer and returned to my application after  a successful login, a few seconds later I got the message that my session was expired and that I had to login again(and again, and again, …). Inside our application we are using the great angular-oauth2-oidc library . One of it’s nice features is that it keeps our identity and access tokens up-to-date thanks to a built-in silent refresh mechanism . This mechanism uses a hidden iframe to call IdentityServer to renew our tokens. Remark: we need this hidden iframe hack as we are still using an Implicit Flow. The plan is to switch to Code Flow which allows us to use refresh tokens. Inside the developer console I see the following warnings: A cookie associated with a cross-site resource at https://ids.development/ was set without the `SameSite` attribute. It has been blocked, as Chrome now only delivers cookies wit

XUnit - Assert.Collection

A colleague asked me to take a look at the following code inside a test project: My first guess would be that this code checks that the specified condition(the contains) is true for every element in the list.  This turns out not to be the case. The Assert.Collection expects a list of element inspectors, one for every item in the list. The first inspector is used to check the first item, the second inspector the second item and so on. The number of inspectors should match the number of elements in the list. An example: The behavior I expected could be achieved using the Assert.All method:

ASP.NET Core MVC - Use of partial may result in deadlocks

I’m currently migrating an existing ASP.NET MVC application to ASP.NET Core. When copying over a view with a Partial view in it, I got the following warning: Although the Partial method still exists, it is recommended to switch to the asynchronous version as the synchronous version can result in deadlocks in certain scenarios. The solution is simple; replace calls to @Html.Partial with @await Html.PartialAsync or the Partial Tag Helper .

ASP.NET Core–Using TempData results in a 500 error

I’m currently migrating an existing ASP.NET MVC application to ASP.NET Core. To share data between multiple page requests I’m trying to use the TempData . TempData stores your data until it's read in another request. This is how my code looked like: Unfortunately this resulted in a 500 error without any further explanation 😒. What am I doing wrong? The thing is that you cannot store a complex object inside the TempData directly. Instead of returning a meaningful error you get only a 500 message. To fix it, I added some serialization logic before storing the object in the TempData dictionary:

Application Insights Agent

The Application Insights Agent replaces the old Status Monitor tool . It allows you to monitor .NET web applications hosted in IIS without the need to change your code. You can install the agent from the Powershell gallery: https://www.powershellgallery.com/packages/Az.ApplicationMonitor Installation steps First you need to install/update PowershellGet. Therefore open an elevated Powershell prompt and execute the following commands: Install-PackageProvider -Name NuGet –Force Install-Module -Name PowerShellGet –Force Update-Module -Name PowerShellGet Next, close and re-open the elevated Powershell prompt. If you forget to do that you’ll probably get the following error when you try to install the Az.ApplicationMonitor module: WARNING: The specified module 'Az.ApplicationMonitor' with PowerShellGetFormatVersion '2.0' is not supported by the current version of PowerShellGet. Get the latest version of the PowerShellGet module to

ASP.NET Core - Kendo UI–Grid remains empty

I’m currently migrating an existing ASP.NET MVC application to ASP.NET Core. After 3 years of working on Single Page Applications through Angular returning to MVC was as straightforward as I hoped. As long as you stay in the full page refresh cycle, everything is quite easy but the moment you want to sprinkle some AJAX magic on top of your code, it turns into a mess quite fast. But not all is bad. Thanks to control libraries like Kendo UI you get a lot of functionality with almost no code. For example the Kendo Grid control is pure magic! Unfortunately it didn’t work out-of-the-box. There is 1 important extra configuration step required. You need to tell ASP.NET Core to maintain the property name casing:

Shape Up: Stop Running in Circles and Ship Work that Matters

I’m always looking at ways to broader my horizon and find new ways to build and ship software. An interesting approach is the one used by Basecamp . They have bundled their way of working in a free ebook : Shape Up: Stop Running in Circles and Ship Work that Matters Shape Up is for product development teams who struggle to ship. Full of eye-opening insights, Shape Up will help you break free of "best practices" that aren't working, think deeper about the right problems, and start shipping meaningful projects.