System.MissingMemberException Was Unhandled

2019-08-20 07:23发布

I don't know why this error keeps popping up, but my code never used to do this.

Here is the code:

Dim proc = Process.GetProcessesByName("chrome")
For i As Integer = 0 To proc.Count - 1
  proc(i).CloseMainWindow()
Next i

On the second line, the error occurs. Here is the error:
Public member 'Count' on type 'Process()' not found.

This code never did this until yesterday, I don't know what is causing it either. The code has no errors, so I am not sure that is causing it.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-20 08:05

GetProcessesByName() returns an array. It has a Length property to indicate the number of elements.

You might have accidentally used the Linq Enumerable.Count() extension method. An edit that removed the Imports statement for System.Linq would be an explanation. It is certainly best to use Length instead.

查看更多
登录 后发表回答