D
Dan
Hi Daniel
As I say I apologise if it is not supported and really doesn't work,
according to all the documentation I read it should work.
I really do appreciate the time and help you have given believe me. I had
given this post up as a lost cause at the start week when no one had
replied. I haven't had chance to try the code you posted as I am working on
something different at the minute but I promise I will.
I to have had a long day and am full of cold and feeling grotty, so I'm
sorry if I have come across as an arse.
I hope you will accept my apology, and that in the future when I inevitably
become stuck again that you will not be deterred from offering your advice
to me.
Thanks
Dan
As I say I apologise if it is not supported and really doesn't work,
according to all the documentation I read it should work.
I really do appreciate the time and help you have given believe me. I had
given this post up as a lost cause at the start week when no one had
replied. I haven't had chance to try the code you posted as I am working on
something different at the minute but I promise I will.
I to have had a long day and am full of cold and feeling grotty, so I'm
sorry if I have come across as an arse.
I hope you will accept my apology, and that in the future when I inevitably
become stuck again that you will not be deterred from offering your advice
to me.
Thanks
Dan
Daniel Moth said:May? So you haven't tried it yet; when you do if you have problems postI'm not denying the line you gave me may work, all I am saying is that
the
back like I said.
Don't disagree with that. So you tried it and it failed. You posted askingIf something doesn't work that should then I like to try and find the
reason why, not just work around it!
for help. Somebody gave up their time to try it for you. They tried it and
it failed for them too. They looked at the method with ildasm and don't
find any meaningful implementation. So they look at what you are really
trying to achieve and come with a workaround. They post it to help you. At
this stage you have a number of options:
a) If it works use it
b) As above plus thank the person for helping you
c) If it doesn't work post back
d) Use the workaround and try to find out why
e) Ignore the workaround and insist it should work
It could be that I had a long day but I'd say that any of the first 4
options is reasonable. You are taking the 5th.
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
Dan said:Daniel
I'm not denying the line you gave me may work, all I am saying is that
the invokMember call that I am making is supported by the compact
framework and therefore should work.
If something doesn't work that should then I like to try and find the
reason why, not just work around it!
Dan
Daniel Moth said:Dan, what do you expect me to say? I gave you my interpretation/opinion
and you are plainly stating that it is wrong and that Type.InvokeMember
is supported (yet you cannot get it to work). I offered you an
alternative one line of code to substitute your one line of code and
this works. If the line of code I offered does not work for you please
post back with the details.
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
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