_sendMethod.Invoke时发生错误。 你知道怎么解决这个问题吗?这有C#代码。它似乎工作正常。但它在vb.net中无法正常工作。我需要为此编写VB.NET。
这是关于例外情况的通知。
StackTrace:at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化) 在System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化) 在PIPEmail.MailMessageExt.Save(MailMessage消息,字符串FileName)
消息:“参数计数不匹配。”
数据:{System.Collections.ListDictionaryInternal}
TragetSite:{System.Object [] InvokeArgumentsCheck(System.Object,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object [],System.Globalization.CultureInfo)}
Public Sub Save(ByVal Message As MailMessage, ByVal FileName As String)
Dim assembly As Assembly = GetType(SmtpClient).Assembly
Dim _mailWriterType As Type = assembly.[GetType]("System.Net.Mail.MailWriter")
Try
Using _fileStream As New FileStream(FileName, FileMode.Create)
' Get reflection info for MailWriter contructor
Dim _mailWriterContructor As ConstructorInfo = _mailWriterType.GetConstructor(BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Type() {GetType(Stream)}, Nothing)
' Construct MailWriter object with our FileStream
Dim _mailWriter As Object = _mailWriterContructor.Invoke(New Object() {_fileStream})
' Get reflection info for Send() method on MailMessage
Dim _sendMethod As MethodInfo = GetType(MailMessage).GetMethod("Send", BindingFlags.Instance Or BindingFlags.NonPublic)
' Call method passing in MailWriter
**_sendMethod.Invoke(Message,
BindingFlags.Instance Or BindingFlags.NonPublic,
Nothing,
New Object() {_mailWriter, True},
Nothing
)**
'_sendMethod.Invoke(Message, BindingFlags.Instance Or BindingFlags.NonPublic, Nothing,
' Finally get reflection info for Close() method on our MailWriter
Dim _closeMethod As MethodInfo = _mailWriter.[GetType]().GetMethod("Close", BindingFlags.Instance Or BindingFlags.NonPublic)
' Call close method
_closeMethod.Invoke(_mailWriter, BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Object() {}, Nothing)
End Using
Catch ex As Exception
End Try
End Sub
结束模块
答案 0 :(得分:1)
我在下面的代码中添加了“ True ”,然后就可以了。
_sendMethod.Invoke(消息, BindingFlags.Instance或BindingFlags.NonPublic, 没有, 新对象(){_ mailWriter,True, True }, 没有 )