方法调用失败,因为[System.String]不包含名为“ AppendChild”的方法

时间:2018-08-01 09:26:24

标签: xml powershell

突然,此代码不再起作用。我正在尝试使用Google进行搜索,但似乎找不到解决此问题的任何解决方案。

我不能做

    C:\OpenCV>mingw32-make
[  0%] Built target gen-pkgconfig
[  2%] Built target zlib
[  5%] Built target libjpeg-turbo
[  8%] Built target libtiff
[ 16%] Built target libwebp
[ 19%] Built target libjasper
[ 20%] Built target libpng
[ 25%] Built target IlmImf
[ 25%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/goog
le/protobuf/stubs/io_win32.cc.obj
C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc:94:3: warning: identifier 'nullptr' is a keyword in C++11 [-W
    c++0x-compat]
       return s == nullptr || *s == 0;
       ^

    C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc: In function 'bool google::protobuf::internal::win32::{anonym
    ous}::null_or_empty(const char_type*)':
    C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc:94:15: error: 'nullptr' was not declared in this scope
       return s == nullptr || *s == 0;
                   ^
    C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc: In function 'bool google::protobuf::internal::win32::{anonym
    ous}::null_or_empty(const char_type*) [with char_type = char]':
    C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc:95:1: error: control reaches end of non-void function [-Werro
    r=return-type]
     }
     ^
    C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc: In function 'bool google::protobuf::internal::win32::{anonym
    ous}::null_or_empty(const char_type*) [with char_type = wchar_t]':
    C:\Users\xxx\Downloads\opencv\sources\3rdparty\protobuf\src\google\protobuf
    \stubs\io_win32.cc:95:1: error: control reaches end of non-void function [-Werro
    r=return-type]
     }
     ^
    cc1plus.exe: some warnings being treated as errors
    3rdparty\protobuf\CMakeFiles\libprotobuf.dir\build.make:258: recipe for target '
    3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.
    cc.obj' failed
    mingw32-make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/pr
    otobuf/stubs/io_win32.cc.obj] Error 1
    CMakeFiles\Makefile2:715: recipe for target '3rdparty/protobuf/CMakeFiles/libpro
    tobuf.dir/all' failed
    mingw32-make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
    Makefile:161: recipe for target 'all' failed
    mingw32-make: *** [all] Error 2

[xml]($deploymentXml.configuration.services).AppendChild($newService)

有人知道这是怎么回事,为什么它不再起作用了?


deployment.xml

$deploymentServicesNode = [xml]$deploymentXml.configuration.services
$deploymentServicesNode.AppendChild($newService)
  

方法调用失败,因为[System.String]不包含名为“ AppendChild”的方法。   在F:\ USB \ host.ps1:153 char:9   + $ deploymentXml.configuration.services.AppendChild($ service ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [],RuntimeException       + FullyQualifiedErrorId:MethodNotFound

host.ps1的一部分

<?xml version="1.0" encoding="utf-8"?>
<configuration description="Services deployment server">
    <services>
    </services>
</configuration>

1 个答案:

答案 0 :(得分:0)

在获取XML内容之前,请尝试添加以下内容:

$deploymentFile = $PSScriptRoot + "\USB\Configuration\Deployment.xml";
[System.Xml.XmlDocument]$deploymentXml = New-Object System.Xml.XmlDocument
$deploymentXml = [xml](Get-Content $deploymentFile);

我遇到了一些问题,该类型在某些环境中未设置,即-SQL作业PowerShell步骤。