Searching for .dll directory on different OS and languages

Hi,

The code below searches for .dll directory and tries to find Tools.txt file.
This worked for windows, but did not work for French and Japanese windows and Mac.

   string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
    string assemblyPath = System.IO.Path.GetDirectoryName(assemblyLocation);
    assemblyPath += @"\Tools.txt";

    string[] lines = System.IO.File.ReadAllLines(assemblyPath);

Is there any workaround?
I need to reference text file that is always placed in the same folder where the .dll is-

I added this code for GH_Component base class so that each component would run it, but other OS spits this error before grasshopper is loaded:

Object: ComponentOpenPolyline (level 1)
{
  Exception has been thrown by the target of an invocation.
  TargetInvocationException
}



Object: ComponentOpenPolyline (level 2)
{
  The path is not of a legal form.
  ArgumentException
}

This happens in this error tab below:

The issue is that a user sometimes edit that .txt file that is directly read in a component.
So I cannot just copy paste data inside a visual project as a string and constantly have acces to it.

Try using System.Io.Path.DirectorySeparator (or something very similar) instead of hardcoding a back slash.

Thank you for reply, but I still have an error.
The french is saying that there is smth wrong with the path.
I tested on Mac it works, on my windows pc also. But not on this student computer.
Any ideas how to get access to this txt file?

Have you tried Path.Combine ?

Yes I tried. Still the same one on french pc. Rhino 6.

I would probably MessageBox the combined path and see what happened.

What do you mean by MessageBox?

Output assemblyPath before ReadAllLines. Let your user send you the result and if anything goes wrong.

But I doubt maybe string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location returns an empty string.

It fails at the first line of code:

string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;

Then the question: why the assembly is not found on other pc and how to find it?

If your assembly is COFF loaded, the Location will be empty.

That was the COFF causing the problems, och that sneaky bastard.

In that case, is it possible to force somehow to find it the location when COFF is enabled @DavidRutten, @gankeyu ?

Or is it somehow possible to get directory of this folder for all computers
C:\Users\petra\AppData\Roaming\Grasshopper\Libraries\IBOIS

when this part is always changing
C:\Users\petra\AppData\Roaming\Grasshopper

and this one stays the same
Libraries\IBOIS