Hi
The thing is the invokeMethod is supported by the compact framework and
so is the NewRow function of the datatable, as I said I have used that
function before when testing, and it was completley written to target
the CF.
Thanks
Dan
Like the exception says, it is not supported. It is not clear on what
but it applies to InvokeMember.
If you replace you line with something like this it should work:
obj = dataType.GetMethod(method, BindingFlags.Instance Or
BindingFlags.Public).Invoke(target, args)
Note that you should change the flags variable accordingly if you want
to keep your function generic for static methods as well...
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
Hi
Sorry for the delay, Yes my previous post was a question and yes I did
forget to put in the question mark, sorry.
This is function I use for invoking the method through reflection again
this is part of a framework here is some code that uses the function in
my
parser.
Imports System.Reflection
Public Class testForm
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 16)
Me.Button1.Size = New System.Drawing.Size(224, 20)
Me.Button1.Text = "Click Me"
'
'testForm
'
Me.Controls.Add(Me.Button1)
Me.Text = "testForm"
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As Object
Dim dt As New Data.DataTable
Dim args() As Object
obj = invokeMethod(GetType(Data.DataTable), dt, "NewRow", args)
End Sub
Public Shared Function invokeMethod(ByVal dataType As Type, ByVal
target
As Object, ByVal method As String, ByVal args() As Object) As Object
Try
Dim obj As Object
Dim flags As BindingFlags = BindingFlags.InvokeMethod Or
BindingFlags.Instance
If target Is Nothing Then
flags = flags Or BindingFlags.Public Or BindingFlags.Static
End If
obj = dataType.InvokeMember(method, flags, Nothing, target, args)
Return obj
Catch ex As Exception
End Try
End Function
End Class
I have also tried this function with other types and for some reason it
doesn't work with them either, this code has worked in the past and so
I
really don't know what has changed and it runs on the full framework.
Cheers
Dan
If that was a question (it is phrased as one but there is no question
mark) then yes the same public key token is used. For your other
question
show some code so we can look at it further.
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
Hi Daniel
Yeah I had the one startng with B, is the same also true for the
other
assemblys like system.windows.forms and system.drawing
Dan
Ok now I have got it to load the assembly but for some reason I
don't
seem to be able to invoke the newrow method through reflection I get
a
notsupported exception, also if I just try to use the getmethods
reflection call on the datatable I get System error &H80070057&.
Could this be because I do not have the service packs on the
emulator?
Thanks
Dan
How do you invoke it? Try something like this:
loadAssembly("System.Data", "System.Data, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=969db8053d3322ac")
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Dan wrote:
Hi Daniel
The code I use is this:
Public Shared Sub loadAssembly(ByVal ns As String, ByVal
assemblyName
As String)
Dim ass As [Assembly]
If Not assemblyMappings.ContainsKey(ns) Then
Try
ass = [Assembly].Load(ns)
assemblyMappings(ns) = ass
Catch ex As Exception
If ass Is Nothing Then
'try load from fullname
ass = [Assembly].Load(assemblyName)
assemblyMappings(ns) = ass
End If
End Try
End If
End Sub
So if I call this to load system.data, ns would be system.data and
assembly name is the full name, version, public key etc. But even
when
trying to load it with the fullname fails.
Thanks
Dan
Can you show some code?
Chances are that you are not passing the full name to
Assembly.Load.
If
that is the case, the only reason winforms & drawing loaded was
because
they were loaded already. To test this theory insert this line
just
before your Assembly.load of system.data. If it works with and
doesn't
without, it is as I suspected so share some code. If it continues
to
throw then... ...still show us the code
// c#
System.Data.Column b = new System.Data.Column("test")
' vb
Dim b As New System.Data.DataColumn("test")
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
Hi everyone
I'm having trouble trying to load the system.data assembly.
If I do assembly.load() and pass in system.windows.forms or
system.drawing
it loads the assembly but if I use system.data it throws an
ioexception.
has anyone else come across this
thanks
Dan