Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Why we got exception when number of properties is big?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 22 Oct 2007 20:51 GMT
Hello, friends,

The following function works fine if the classSource has relatively smaller
number of properties. However, it would give an exception when its number of
properties gets bigger, say about 100.

Any ideas?
If this does not work, then, what is the better way to copy data from one
class to another one (they have part of properties the same)?

Thanks a lot !

------------------------------
The exception is:

Exception has been thrown by the target of an invocation.
Source: mscorlib
StackTrace:
  at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
  at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
skipVisibilityChecks)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object
value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo
culture)
  at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object
value, Object[] index)
  at Utility.CopyClassData(Object classSource, Object classTarget) in
C:\UtilityFactory\Utility.cs:line 431

And here are the source code.

       internal static void CopyClassData(object classSource, object
classTarget)
       {
           Type typeInfoSource = classSource.GetType();
           PropertyInfo[] propertiesSource = typeInfoSource.GetProperties();

           Type typeInfoTarget = classTarget.GetType();
           PropertyInfo[] propertiesTarget = typeInfoTarget.GetProperties();

           foreach (PropertyInfo propertySource in propertiesSource)
           {
               foreach (PropertyInfo propertyTarget in propertiesTarget)
               {
                   if (String.Compare(propertySource.Name,
propertyTarget.Name, true) == 0)
                   {
                       System.Object propertyValue =
propertySource.GetValue(classSource, null);
                       propertyTarget.SetValue(classTarget, propertyValue,
null);
                   }
               }
           }
       }
sloan - 22 Oct 2007 22:28 GMT
I think there is a

IsWriteable

or

IsReadonly

property as well,  make sure you check that before using the GetValue,
SetValue thing.

I know there is some property to check, I just can't remember the name
offhand.

> Hello, friends,
>
[quoted text clipped - 64 lines]
>            }
>        }
nobugz - 23 Oct 2007 19:34 GMT
Check the InnerException property of the exception for the real error.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.