vendredi 10 septembre 2021

How can a .NET assembly detect its own version within an IIS ASP.NET context?

I have a c# function that works great in a winforms app to detect its container DLL's version as stamped in AssemblyInfo.cs:

private string getVersion() {
  System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
  FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
  string tempFileVersion = fvi.FileVersion;

  if (tempFileVersion.EndsWith(".0")) {
    return tempFileVersion.Substring(0, tempFileVersion.Length - 2);
  } else {
    return tempFileVersion;
  }
}

The problem is, this function throws exceptions when it's called as part of an ASP.NET webapp in IIS. I'm assuming it comes down to permissions problems, but is there a way for a function to ask the DLL it lives in "what is your version" inside an IIS context?





Aucun commentaire:

Enregistrer un commentaire