Problem downgrading TypeDescriptor.GetProperties from .NET 2.0 to 1.1

Hi

I have this function in VB.NET 2.0 and it works fine.

    Public Function GetObjectProperty(ByVal obj As Object, ByVal strPropertyName As String) As Object

        Dim props As PropertyDescriptorCollection = TypeDescriptor.GetProperties(obj)
        Dim objtype As String = obj.GetType.ToString
        Dim blFoundProperty As Boolean = False
        Dim objOut As New Object

        ' Iterate properties, try and find the one we're looking for. If found, set it.
        For Each prop As PropertyDescriptor In props
            If prop.Name = strPropertyName Then
                objOut = prop.GetValue(obj)
                blFoundProperty = True
                Exit For
            End If
        Next

        ' If the property hasn't been found, throw an exception
        If blFoundProperty = False Then
            Throw New Exception("Property " & strPropertyName & " not found in object type " & objType.ToString)
        End If

        Return objOut
    End Function

The function simply sets a specific property of an object to value.

I've had to downgrade the class to .NET 1.1 and I've hit problems when I supply a custom object. TypeDescriptor.GetProperties(obj) returns no properties. All still works fine with System objects.

Does anyone have any thoughts on this?

If not, can anyone think of another way to return a property of an object when the property name is held in a string?

Thanks in advance for any help.
LVL 11
cmhuntyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jake072Commented:
Here is a link:

http://www.c-sharpcorner.com/UploadFile/dsandor/SettingClassPropsFromDb11302005064002AM/SettingClassPropsFromDb.aspx

However, it says to use Reflection, as suggested in your other Question (http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22774468.html?cid=237#a19731690) by Bob...  I'm assuming that the reflection doesn't work in 1.1?

Let me know,

Jake
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmhuntyAuthor Commented:
I put together a test script just before leaving work yesterday and it didn't unfortunately. If it's ok, I'll post on here when I get back to work today so I can confirm it's not my system setup that's causing the problem 'cos this seems really strange. I've checked the books online and there doesn't seem to be anything in version 2.0 that suggests that these methods have been reworked.

Cheers for your help.

Chris
0
cmhuntyAuthor Commented:
Gets stranger and stranger. The problem only seems to be with classes from a web reference. Put together the code below.
User defined classes work fine in both 1.1 and 2.0.
Classes from separate dll assembly work fine in both 1.1 and 2.0.
Web referenced classes only work in 2.0.

As mentioned there's nothing in MS documentation that ComponentModel or Reflection shouldn't work in 1.1 so I'm going to take this up with them.

Thank you again for your help.

Chris
--------------------------------------------------------------

Imports System.ComponentModel
Imports System.Reflection
Imports Test2.cmrws

Module Module1

    Sub Main()

        Dim test As New Customer
        'Dim test As New TestClass
        'Dim test As New Data.DataTable
        Console.WriteLine("Web service class, type descriptor count: " & GetPropertyCount_TypeDescriptor(test))
        Console.WriteLine("Web service class, reflection - exists: " & DoesPropertyExist_Reflection(test, "name"))
        'Console.WriteLine("Web service class, reflection - exists: " & DoesPropertyExist_Reflection(test, "TestProp1"))
        'Console.WriteLine("Web service class, reflection - exists: " & DoesPropertyExist_Reflection(test, "rows"))
        Console.Read()
    End Sub

    Public Function GetPropertyCount_TypeDescriptor(ByVal obj As Object) As Int32
        Dim props As PropertyDescriptorCollection = TypeDescriptor.GetProperties(obj)
        Return props.Count
    End Function

    Public Function DoesPropertyExist_Reflection(ByVal obj As Object, ByVal strPropertyName As String) As Boolean

        Dim blFound As Boolean = False
        Dim info As PropertyInfo = obj.GetType().GetProperty(strPropertyName)

        If info Is Nothing = False Then
            blFound = True
        End If

        Return blFound
    End Function

    Public Class TestClass
        Private strProp1 As String
        Private strProp2 As String
        Public Property TestProp1()
            Get
                Return strProp1
            End Get
            Set(ByVal value)
                strProp1 = value
            End Set
        End Property
        Public Property TestProp2()
            Get
                Return strProp2
            End Get
            Set(ByVal value)
                strProp2 = value
            End Set
        End Property
    End Class

End Module
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

cmhuntyAuthor Commented:
Have run on another machine and can confirm that this isn't an environment issue. Have raised an issue with MS. Will post their response. Thanks for your help.

Chris
0
jake072Commented:
Chris,

When you say this is only for web interfaces, I may have some insight...

Personally, I have a .NET 1.1 project that I've been working on for the past 3 years...  Once MS came out with IE 7, I noticed that all my web browsers that are embedded in my project stopped working properly.

I have a custom inherited browser that I've made, I'm just trying to figure out how to post it somewhere to share with others...  Anyways, the long and the short is that I've found that IE 7 completely broke most AxSchdocvw browsers; perhaps that has something to do with it?

I'd love to hear MS's response...

P.S.  Where do you contact MS regarding these types of issues?  Do you need an MSDN?

Thanks,

Jake
0
cmhuntyAuthor Commented:
Cheers for that! I'll have a little bit of a further look.

Our company is a MS Partner so we have a support account with them. Still waiting to hear from them. Turnaround is usually 1-2 days. Will keep you posted.

Cheers

Chris
0
jake072Commented:
My Extended Browser:

http://www.nymtec.com/?q=node/97

Jake
0
cmhuntyAuthor Commented:
Jake - fyi, I raised the issue with Microsoft and eventually got the answer back. The wsdl.exe on 1.1 differs from 2.0. 1.1 treats properties as public fields and therefore none of the above solutions work. I had a reasonable arguement with MS when they charged my for the support as my arguement was that it wasn't documented anywhere. They dug out this article: http://msdn.microsoft.com/msdnmag/issues/05/04/NETMatters/ 

Just thought you may be interested!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.