Tag: C#

  • Work with Google Integrity verdicts on .NET C#

    There are no clear examples of how an Attestation statement can be verified on C# locally.
    Spent sometime to get it working.

    var decryptionKey = Convert.FromBase64String("<DECRYPTION KEY");
    var verificationKey = Convert.FromBase64String("<VERIFICATION KEY");
    var signedAttestationStatement = "<ATTESTATION STATEMENT";
    
    var ecDsa = ECDsa.Create();
    ecDsa.ImportSubjectPublicKeyInfo(new ReadOnlySpan<byte(verificationKey), out _);
    
    var decrypted = Jose.JWT.Decode(signedAttestationStatement, decryptionKey);
    var payload = Jose.JWT.Decode(decrypted, ecDsa);

  • Protobuf-net Generics on Unity3D IL2CPP.

    When using Protobuf-net in Unity3D, if your Proto-Contracts include generics you might run into a few issues like Unable to resolve MapDecorator constructor.

    I had to work with the following contract. It was s custom collection class which had a functionality of caching removed elements in the collection.

    [ProtoContract]
    public class CustomCollectionBase<TCollection, TElement, TKey{
    	[ProtoMember(1)]
    	protected TCollection _collection;
    
    	[ProtoMember(2)]
    	protected SortedDictionary<TKey, bool_removed;
    
    	public CustomCollectionBase(TCollection collection)
    	{
    		_collection = collection;
    	}
    }
    
    [ProtoContract]
    public class CustomList<TElement: CustomCollectionBase<List<TElement, TElement, int{
    	public CustomList() : base( new List<TElement())
    	{
    	}
    }
    
    [ProtoContract]
    public class CustomIntDictionary<TElement: CustomCollectionBase<Dictionary<int, 

  • Redis .net Tips and Tricks.

    1. Create a Singleton of the Redis connection multiplexer and use it everywhere.
    2. When establishing the connection to the Redis cluster, use a lock on to ensure that multiple threads don’t create the connection concurrently.
    3. Under load of you see that Redis is timing out set ThreadPool.SetMinThreads(…) to around 250 depending on your application. More here – https://docs.microsoft.com/en-us/dotnet/api/system.threading.threadpool.setminthreads?view=netcore-2.0#System_Threading_ThreadPool_SetMinThreads_System_Int32_System_Int32_
    4. If you are executing Lua scripts, ensure that they are performing well using the Redis slow.
    5. If you are running a Redis cluster, ensure that the BGSAVE of each node in the cluster runs at different times. If they run at once, there

  • C# Dynamic Object Creation Performance

    Recently I had to task to create a dynamic object creation factory in C#. So I thought I test all the options I have to check what performs best.

    I also wanted to check the performance implications these options have with the number of parameters in the constructor.

    The Options

    1. new T() – Using the new/constructor method to
      instantiate objects
    2. Activator.CreateInstance(typeof(T)) – Using the Activator class to instantiate objects
    3. ConstructorInfo.Invoke() – Using the constructor info reflection class to instantiate objects
    4. Func<T>() – Using compiled lambda expressions to instantiate objects

    The Test

    I ran some tests to see calculate how each …

  • C# .net Core MapRoute Not Working?

    Recently I faced a challenge while trying to programatically register routes on a .net core MVC application. The following was my code.

    app.UseMvc(routeBuilder =
    {
    routeBuilder.MapRoute(
    name: "example-route",
    template: "example",
    defaults: new { controller = "ExampleController", action = "ExampleAction" }
    );
    });

    Once the route was registered, I tried navigating to it and I kept getting a 404. Was breaking my head as to why this was happening. Finally found the issue.

    The controller name cannot have the post-fix Controller, the following change made the trick.

    app.UseMvc(routeBuilder =
    {
    routeBuilder.MapRoute(
    name: "example-route",
    template: "example",
    defaults: new { controller = "Example

  • Native IOS Plugins for Unity 3D Tutorial from A-Z

    Following my tutorial on how you can create Android Plugins for Unity 3D, I decided to write a tutorial on how to create IOS plugins for Unity 3D with Objective C. I will be following the same incremental approach used in creating the Android plugin. This tutorial will cover the most basic aspects of writing a custom plugin for IOS. It covers the aspects of creating the XCode static library. Generating the Unity Project and running the project using Unity. To understand the tutorial you should have a basic understanding of Objective C, C, C# and XCode.

    Setup Directory Structure

  • Native Android Plugins for Unity 3D Tutorial from A-Z

    Recently, I was trying to write some native Android plugins for Unity 3D and I was looking for a tutorial but I couldn’t find a complete one so I decided to write one. This tutorial will explain how to write a native Android plugin for Unity 3D from scratch, A to Z. We will be using Java as our native language and creating a JAR file which we will later be referred from Unity 3D using a C# script. First of all the thing you have to understand is that it s very easy to write this kind of plugin. …