Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 程序集::GetExecutionGassembly()->;位置现在抛出ArgumentException:路径中的非法字符_.net_Node.js_Visual Studio 2015_C++ Cli - Fatal编程技术网

.net 程序集::GetExecutionGassembly()->;位置现在抛出ArgumentException:路径中的非法字符

.net 程序集::GetExecutionGassembly()->;位置现在抛出ArgumentException:路径中的非法字符,.net,node.js,visual-studio-2015,c++-cli,.net,Node.js,Visual Studio 2015,C++ Cli,在Visual Studio 2010(和.Net 4)中的node.js本机插件中,我可以使用 System::Reflection::Assembly::GetExecutingAssembly()->Location 要获取正在运行的C++/CLI程序集的路径,但在Visual Studio 2015项目(和.Net 4.6)中的node.js加载项中,我遇到一个异常: System.ArgumentException: Illegal characters in path.

在Visual Studio 2010(和.Net 4)中的node.js本机插件中,我可以使用

System::Reflection::Assembly::GetExecutingAssembly()->Location
要获取正在运行的C++/CLI程序集的路径,但在Visual Studio 2015项目(和.Net 4.6)中的node.js加载项中,我遇到一个异常:

System.ArgumentException: Illegal characters in path.
   at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
   at System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(
      String[] str)
   at System.Security.Permissions.FileIOPermission.AddPathList(
      FileIOPermissionAccess access, AccessControlActions control,
      String[] pathListOrig, Boolean checkForDuplicates,
      Boolean needFullPath, Boolean copyPathList)
   at System.Security.Permissions.FileIOPermission..ctor(
      FileIOPermissionAccess access, String path)
   at System.Reflection.RuntimeAssembly.get_Location()
知道如何获取正在运行的程序集的路径吗

编辑2018-01-25
Visual Studio 2017仍未解决这一问题,这次尝试.Net 4.5.2

虽然
Location
属性抛出,但仍然可以使用
CodeBase
,返回类似以下内容:

file://?/C:/.../my-addon.node
这就解释了非法字符“?”

一个
新Uri(Application.CodeBase).LocalPath将返回

/?/C:/.../my-addon.node
C:\...\my-addon.node
因此,
getExecutionGassembly()->Location
的解决方法可以是:

String^ GetExecutingAssemblyLocation()
{
  try
  {
    return Path::GetDirectoryName(Assembly::GetExecutingAssembly()->Location);
  }
  catch (Exception^ e)
  {
    String^ codeBase = Assembly::GetExecutingAssembly()->CodeBase;
    if (codeBase->StartsWith("file://?/"))
    {
      Uri^ codeBaseUri = gcnew Uri("file://" + codeBase->Substring(8));
      return codeBaseUri->LocalPath;
    }
    else
      throw;
  }
}
哪个会回来

/?/C:/.../my-addon.node
C:\...\my-addon.node