Tuesday, October 11, 2022

VC redistributable is a critical piece of functionality

Just spent several hours trying to figure out why the freshly-installed ODP.NET 19c fails to load on most of our production servers.

The immediate error that I got in the logs was

Unable to load DLL 'OraOps19.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Googling for it did not really bring anything that helped: the permissions were ok and the path of the .dll was in the PATH environment variable.

In order to diagnose the problem I turned to the great SysInternals' tool called Process Monitor. After filtering out the extra stuff (a lot of extra stuff :) ) I ended up with a very clear error message:


Going to the Microsoft site, downloading the latest (or the relevant) VC Redistributable quickly fixed the issue.

Tuesday, May 10, 2022

Fix the issue with incorrect BigInteger serialization of MVC

When I wrote an webAPI method that returns a structure with BigInteger in it (used a lot in blockchain development) it turned out that the output looks as follows:



It looks like the default serializer of BigInteger used by the MVC works in a bit strange way.

There was a way of course to add decorators to the BigInteger data members of the structure that I wanted to serialize, but I use Nethereum and the structure was automatically generated by a Nethereum tool (which is quite handy, by the way). So I wanted to find a way to override the default behavior of the JSON serializer for the BigInteger type.

Took me some time to understand how to do it, but in the end it all makes sense and is quite simple:

1. Created a class that inherits from JsonConverter<BigInteger> as follows:

using System.Numerics;

using System.Text.Json;
using System.Text.Json.Serialization;

namespace AkwaWeb
{
    public class BigIntegerJsonConverter : JsonConverter<BigInteger>
    {
        public override BigInteger Read(
                   ref Utf8JsonReader reader,
                   Type typeToConvert,
                   JsonSerializerOptions options) =>
                       BigInteger.Parse(reader.GetString()!);
        public override void Write(
            Utf8JsonWriter writer,
            BigInteger val,
            JsonSerializerOptions options) =>
                writer.WriteStringValue(val.ToString());
    }
}

2. Registered it during the system initialization as follows:

builder.Services.AddMvc().AddJsonOptions(options =>
{
   options.JsonSerializerOptions.Converters.Add(new AkwaWeb.BigIntegerJsonConverter());
});

3. Et voila



Sunday, January 2, 2022

Using WSL for Solana development

Why? Solana tooling for Windows does not allow for BPF builds.

How?

  • Run WSL on Windows
  • If you are behind a company firewall:
    • make sure you have a .pem file of your root certificate. Talk your sysadmin for that. If you have a .cer file - make sure you convert it to .pem
    • Make sure you have an environment variable SSL_CERT_FILE to point at your .pem certificate (use "export SSL_CERT_FILE=" for that from inside your wsl command shell) or event better - add it to your ~/bashrc file
  • sudo apt install build-essential
  • curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • sudo apt install pkg-config
  • sudo apt install libudev-dev
  • sudo apt install llvm-dev
  • sudo apt install clang

Build and run solana-bpf-program-template on Windows

It turns out that compiling a very basic solana-bpf-program-template on Windows is not a very easy task to do.

First, it panicked with the following error:

error: failed to run custom build command for `openssl-sys ...

In order to solve this an install of the OpenSSL package is needed. Compiling it may have more tricks in it so I decided to install a pre-built package from here. I went to the "Win64 OpenSSL v1.1.1m" option. either .EXE or .MSI. It's important to select the OpenSSL 1.1.1 and not another version. When installing make sure the environment variable of OPENSSL_DIR is set. If not - please set it manually to the root directory of the installation.

Once this issue was resolved the "cargo build" phase progressed further to halt this time with the following error:

   Compiling soketto v0.7.1
error: failed to run custom build command for `librocksdb-sys v6.20.3`

Caused by:
  process didn't exit successfully: `D:\Projects\solana\solana-bpf-program-template\target\debug\build\librocksdb-sys-67f01990a368d2b7\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"'

In order to resolve this I had to google the LIBCLANG_PATH to discover that I need the LLVM compiler. It can be downloaded from here  Please make sure that you select registering the environment variables as a part of the installation.