namespace DLLProj
{
struct DLLProjCore2
{
public const string dll = Environment.GetEnvironmentVariable("DLLProj_HOME", EnvironmentVariableTarget.Machine).ToString();
}
[DllImport(DLLProjCore2.dll)]
public static extern void met1_method1(string prefix, string version);
[DllImport(DLLProjCore2.dll, CharSet = CharSet.Ansi)]
public static extern long met1_method2(IntPtr error, string licenseFile);
}
DLLProjectCore2 is referencing the path to be stored in dll variable.
dll assigning code throws the below error message
The expression is being assigned to DLLProjCore2 must be a constant.
[DllImport(DLLProjCore2.dll)] throw the below error.
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
Once hardcode the value to be assigned to the dll, the project compiles properly.
public const string dll = "PathToBeReferenced";
Is there a way to access the dll variable value in [DllImport(DLLProjCore2.dll)] dynamically? (Without hardcoding, need to refer it from an outside location after publishing the solution)