Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem downgrading TypeDescriptor.GetProperties from .NET 2.0 to 1.1

Posted on 2007-08-20
8
Medium Priority
?
1,242 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:cmhunty
  • 5
  • 3
8 Comments
 
LVL 14

Accepted Solution

by:
jake072 earned 2000 total points
ID: 19733605
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
 
LVL 11

Author Comment

by:cmhunty
ID: 19735829
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
 
LVL 11

Author Comment

by:cmhunty
ID: 19736159
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:cmhunty
ID: 19736476
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
 
LVL 14

Expert Comment

by:jake072
ID: 19737411
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
 
LVL 11

Author Comment

by:cmhunty
ID: 19737535
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
 
LVL 14

Expert Comment

by:jake072
ID: 19738639
My Extended Browser:

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

Jake
0
 
LVL 11

Author Comment

by:cmhunty
ID: 20129622
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question