1

This week I started developing with the InfluxDB.Client.Core package in one of my .net core 3.1 applications. Everything works fine following tutorials and reading docs like those of the package: https://github.com/influxdata/influxdb-client-csharp.

The problem is that I can't get the value from the influx Measurement attribute.

Model:

[Measurement("temperature")]
private class TemperatureDataModel
{
    [Column("location", IsTag = true)] public string Location { get; set; }
    [Column("value")] public double Value { get; set; }
    [Column(IsTimestamp = true)] public DateTime Time;
}

Following the microsoft docs on https://learn.microsoft.com/en-us/dotnet/standard/attributes/retrieving-information-stored-in-attributes I wrote this

method:

internal static string GetMeasurementAttributeName(Type t)
{
    var testingNameOfT = t.Name;
    var MyAttribute = (Measurement)Attribute.GetCustomAttribute(t, typeof(Measurement));
    return MyAttribute?.Name;
}
  • testingNameOfT returns (as expected) TemperatureDataModel.
  • MyAttribute returns null

So how is it possible that I can't get the attribute of my TemperatureDataModel.

The code of the InfluxDB.Client.Core package is:

using System;

namespace InfluxDB.Client.Core
{
  public sealed class Measurement : Attribute
  {
    public string Name { get; }

    public Measurement(string name)
    {
      this.Name = name;
    }
  }
}

We created a workaround by rewriting the model to:

private class TemperatureDataModel
{
    [Column("location", IsTag = true)] public string Location { get; set; }
    [Column("value")] public double Value { get; set; }
    [Column(IsTimestamp = true)] public DateTime Time;
    [Measurement] public string Measurement{ get; set; } //=> will use the value of the property instead of [Measurement("temperature")]
}

So long story short: How is it possible I can't read the attribute with Microsofts sample code?: var attribute = (Measurement)Attribute.GetCustomAttribute(t, typeof(Measurement)) //=> null :(

E. Verdi
  • 310
  • 2
  • 19

0 Answers0