Я пытаюсь установить атрибут интервала сканирования подсистемы развертывания-сканера в моем файле wildfly standalone.xml с помощью Powershell.Всякий раз, когда я пытаюсь выполнить какой-либо метод для элемента (System.Xml.XmlElement), я получаю «Вы не можете вызвать метод для выражения с нулевым значением.», Но объект, для которого я вызываю метод, не выглядит какnull.
> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 17134 407
> $Standalone="C:\Users\I10674\wildfly-9.0.2.Final\standalone\configuration\standalone.xml"
> $Standalone | Get-Member
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone(), System.Object ICloneable.Clone()
CompareTo Method int CompareTo(System.Object value), int CompareTo(string strB), int IComparab...
Contains Method bool Contains(string value)
CopyTo Method void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int co...
EndsWith Method bool EndsWith(string value), bool EndsWith(string value, System.StringCompari...
Equals Method bool Equals(System.Object obj), bool Equals(string value), bool Equals(string...
GetEnumerator Method System.CharEnumerator GetEnumerator(), System.Collections.IEnumerator IEnumer...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
GetTypeCode Method System.TypeCode GetTypeCode(), System.TypeCode IConvertible.GetTypeCode()
IndexOf Method int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf...
IndexOfAny Method int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), i...
Insert Method string Insert(int startIndex, string value)
IsNormalized Method bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normaliz...
LastIndexOf Method int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int...
LastIndexOfAny Method int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startI...
Normalize Method string Normalize(), string Normalize(System.Text.NormalizationForm normalizat...
PadLeft Method string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)
PadRight Method string PadRight(int totalWidth), string PadRight(int totalWidth, char padding...
Remove Method string Remove(int startIndex, int count), string Remove(int startIndex)
Replace Method string Replace(char oldChar, char newChar), string Replace(string oldValue, s...
Split Method string[] Split(Params char[] separator), string[] Split(char[] separator, int...
StartsWith Method bool StartsWith(string value), bool StartsWith(string value, System.StringCom...
Substring Method string Substring(int startIndex), string Substring(int startIndex, int length)
ToBoolean Method bool IConvertible.ToBoolean(System.IFormatProvider provider)
ToByte Method byte IConvertible.ToByte(System.IFormatProvider provider)
ToChar Method char IConvertible.ToChar(System.IFormatProvider provider)
ToCharArray Method char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)
ToDateTime Method datetime IConvertible.ToDateTime(System.IFormatProvider provider)
ToDecimal Method decimal IConvertible.ToDecimal(System.IFormatProvider provider)
ToDouble Method double IConvertible.ToDouble(System.IFormatProvider provider)
ToInt16 Method int16 IConvertible.ToInt16(System.IFormatProvider provider)
ToInt32 Method int IConvertible.ToInt32(System.IFormatProvider provider)
ToInt64 Method long IConvertible.ToInt64(System.IFormatProvider provider)
ToLower Method string ToLower(), string ToLower(cultureinfo culture)
ToLowerInvariant Method string ToLowerInvariant()
ToSByte Method sbyte IConvertible.ToSByte(System.IFormatProvider provider)
ToSingle Method float IConvertible.ToSingle(System.IFormatProvider provider)
ToString Method string ToString(), string ToString(System.IFormatProvider provider), string I...
ToType Method System.Object IConvertible.ToType(type conversionType, System.IFormatProvider...
ToUInt16 Method uint16 IConvertible.ToUInt16(System.IFormatProvider provider)
ToUInt32 Method uint32 IConvertible.ToUInt32(System.IFormatProvider provider)
ToUInt64 Method uint64 IConvertible.ToUInt64(System.IFormatProvider provider)
ToUpper Method string ToUpper(), string ToUpper(cultureinfo culture)
ToUpperInvariant Method string ToUpperInvariant()
Trim Method string Trim(Params char[] trimChars), string Trim()
TrimEnd Method string TrimEnd(Params char[] trimChars)
TrimStart Method string TrimStart(Params char[] trimChars)
Chars ParameterizedProperty char Chars(int index) {get;}
Length Property int Length {get;}
> [xml]$XmlContent=$(Get-Content "$Standalone")
> $XmlContent
xml server
--- ------
version="1.0" server
> $DeploymentScanner=$XmlContent.server.profile.subsystem.'deployment-scanner'
> $DeploymentScanner
name : default
path : deployments
scan-enabled : true
scan-interval : 0
relative-to : jboss.server.base.dir
runtime-failure-causes-rollback : ${jboss.deployment.scanner.rollback.on.failure:false}
> $DeploymentScanner | Get-Member
TypeName: System.Xml.XmlElement#urn:jboss:domain:deployment-scanner:2.0#deployment-scanner
Name MemberType Definition
---- ---------- ----------
ToString CodeMethod static string XmlNode(psobject instance)
AppendChild Method System.Xml.XmlNode AppendChild(System.Xml.XmlNode newChild)
Clone Method System.Xml.XmlNode Clone(), System.Object ICloneable.Clone()
CloneNode Method System.Xml.XmlNode CloneNode(bool deep)
CreateNavigator Method System.Xml.XPath.XPathNavigator CreateNavigator(), System.Xml....
Equals Method bool Equals(System.Object obj)
GetAttribute Method string GetAttribute(string name), string GetAttribute(string l...
GetAttributeNode Method System.Xml.XmlAttribute GetAttributeNode(string name), System....
GetElementsByTagName Method System.Xml.XmlNodeList GetElementsByTagName(string name), Syst...
GetEnumerator Method System.Collections.IEnumerator GetEnumerator(), System.Collect...
GetHashCode Method int GetHashCode()
GetNamespaceOfPrefix Method string GetNamespaceOfPrefix(string prefix)
GetPrefixOfNamespace Method string GetPrefixOfNamespace(string namespaceURI)
GetType Method type GetType()
HasAttribute Method bool HasAttribute(string name), bool HasAttribute(string local...
InsertAfter Method System.Xml.XmlNode InsertAfter(System.Xml.XmlNode newChild, Sy...
InsertBefore Method System.Xml.XmlNode InsertBefore(System.Xml.XmlNode newChild, S...
Normalize Method void Normalize()
PrependChild Method System.Xml.XmlNode PrependChild(System.Xml.XmlNode newChild)
RemoveAll Method void RemoveAll()
RemoveAllAttributes Method void RemoveAllAttributes()
RemoveAttribute Method void RemoveAttribute(string name), void RemoveAttribute(string...
RemoveAttributeAt Method System.Xml.XmlNode RemoveAttributeAt(int i)
RemoveAttributeNode Method System.Xml.XmlAttribute RemoveAttributeNode(System.Xml.XmlAttr...
RemoveChild Method System.Xml.XmlNode RemoveChild(System.Xml.XmlNode oldChild)
ReplaceChild Method System.Xml.XmlNode ReplaceChild(System.Xml.XmlNode newChild, S...
SelectNodes Method System.Xml.XmlNodeList SelectNodes(string xpath), System.Xml.X...
SelectSingleNode Method System.Xml.XmlNode SelectSingleNode(string xpath), System.Xml....
SetAttribute Method void SetAttribute(string name, string value), string SetAttrib...
SetAttributeNode Method System.Xml.XmlAttribute SetAttributeNode(System.Xml.XmlAttribu...
Supports Method bool Supports(string feature, string version)
WriteContentTo Method void WriteContentTo(System.Xml.XmlWriter w)
WriteTo Method void WriteTo(System.Xml.XmlWriter w)
Item ParameterizedProperty System.Xml.XmlElement Item(string name) {get;}, System.Xml.Xml...
name Property string name {get;set;}
path Property string path {get;set;}
relative-to Property string relative-to {get;set;}
runtime-failure-causes-rollback Property string runtime-failure-causes-rollback {get;set;}
scan-enabled Property string scan-enabled {get;set;}
scan-interval Property string scan-interval {get;set;}
> # Can access properties just fine
> $DeploymentScanner.'scan-interval'
0
> $DeploymentScanner.path
deployments
> # Method fails
> $DeploymentScanner.SetAttribute("scan-interval", "1000")
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $DeploymentScanner.SetAttribute("scan-interval", "1000")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
> if ($DeploymentScanner) { Write-Host "not null" } else { Write-Host "is null" }
not null
Я действительно не понимаю, как, когда я регистрирую $ DeploymentScanner и передаю его в Get-Member, он может идентифицировать класс и отображать все доступные методы.Это даже показывает, что интервал сканирования является одним из свойств.Согласно моей проверке if в конце, она не равна нулю - почему я получаю эту ошибку?