Using assembly.load to load system.data

D

Dan

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
 
D

Daniel Moth

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
 
D

Dan

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
 
D

Daniel Moth

Thank you for sharing some code. What we really need is something that runs
(your snippet is not enough).

You also ignored the one liner I gave you to test with. Did that change
things?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Dan said:
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
 
D

Dan

Hi Daniel

I will have to knock something up that can run the code as it is that
function is part of a large parsing library, a bit like xaml, So I will have
to create a little app.

I will also test your line now

Dan

Daniel Moth said:
Thank you for sharing some code. What we really need is something that
runs (your snippet is not enough).

You also ignored the one liner I gave you to test with. Did that change
things?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Dan said:
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
Daniel Moth said:
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
 
S

Sergey Bogdanov

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

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
 
D

Dan

Hi Sergey

The code in the catch block trys to load with the fullname, but looking at
what you said I had a different publickeytoken, that might have been the
problem.

Thanks
Dan
Sergey Bogdanov said:
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

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
 
D

Daniel Moth

If you had the one beginning with B that is the desktop assembly. This would
tie in with what I was saying about the other two not failing because they
were already loaded.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Dan said:
Hi Sergey

The code in the catch block trys to load with the fullname, but looking at
what you said I had a different publickeytoken, that might have been the
problem.

Thanks
Dan
Sergey Bogdanov said:
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

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
 
D

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

Sergey Bogdanov said:
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

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
 
D

Dan

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

Dan said:
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

Sergey Bogdanov said:
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

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
 
D

Daniel Moth

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/


Dan said:
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

Dan said:
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

Sergey Bogdanov said:
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
 
D

Dan

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
Daniel Moth said:
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/


Dan said:
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

Dan said:
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
 
D

Daniel Moth

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/


Dan said:
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
Daniel Moth said:
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/


Dan said:
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
 
D

Dan

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

Daniel Moth said:
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/


Dan said:
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
Daniel Moth said:
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
 
D

Daniel Moth

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/


Dan said:
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

Daniel Moth said:
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/


Dan said:
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
 
D

Dan

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/


Dan said:
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

Daniel Moth said:
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
 
S

Sergey Bogdanov

Dan, actually RuntimeType.InvokeMethod(...) not supported by Compact
Framework 1.0... please, follow Daniel's suggestion, it works correctly.


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

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
 
D

Daniel Moth

I'm not denying the line you gave me may work, all I am saying is that the
May? So you haven't tried it yet; when you do if you have problems post back
like I said.
If something doesn't work that should then I like to try and find the
reason why, not just work around it!
Don't disagree with that. So you tried it and it failed. You posted asking
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/


Dan said:
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
 
D

Dan

Hi Sergey

If it is not supported then I apologise I was only going by what the .net
framework help said
http://msdn.microsoft.com/library/d...tml/frlrfsystemtypeclassinvokemembertopic.asp,
this says that the call is supported by the CF, and that the code compiles.

Dan

Sergey Bogdanov said:
Dan, actually RuntimeType.InvokeMethod(...) not supported by Compact
Framework 1.0... please, follow Daniel's suggestion, it works correctly.


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

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
 
P

Paul G. Tobey [eMVP]

There are *TONS* of things that show in the help as supported, or at least
not as unsupported, but don't work or have only stub implementations.
Although the documentation is substantially better as time goes on, there
are bound to be many errors of this type in 1.0.

Paul T.

Dan said:
Hi Sergey

If it is not supported then I apologise I was only going by what the .net
framework help said
http://msdn.microsoft.com/library/d...tml/frlrfsystemtypeclassinvokemembertopic.asp,
this says that the call is supported by the CF, and that the code
compiles.

Dan

Sergey Bogdanov said:
Dan, actually RuntimeType.InvokeMethod(...) not supported by Compact
Framework 1.0... please, follow Daniel's suggestion, it works correctly.


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top