Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. InvokeMember "Member Not Found" when attempting to set a property

InvokeMember "Member Not Found" when attempting to set a property

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharphelpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Senkwe Chanda
    wrote on last edited by
    #1

    I’m dabbling with some of .Nets reflection features and am running into the following problem… I have the following code, Assembly myAssembly = AppDomain.CurrentDomain.Load("MyAssembly"); Type myType = localDataAssm.GetType("MyNameSpace.MyType”, true, true); Object myObjectInstance = Activator.CreateInstance(myType); myType.InvokeMember("MyProperty", System.Reflection.BindingFlags.SetProperty , null, myObjectInstance, new object[] {"blah"}); The InvokeMember step fails with “Member Not Found”, even though the said property does indeed exist. This seems to be straight forward to me so what am I missing?? Woke up this morning...and got myself a blog

    S 1 Reply Last reply
    0
    • S Senkwe Chanda

      I’m dabbling with some of .Nets reflection features and am running into the following problem… I have the following code, Assembly myAssembly = AppDomain.CurrentDomain.Load("MyAssembly"); Type myType = localDataAssm.GetType("MyNameSpace.MyType”, true, true); Object myObjectInstance = Activator.CreateInstance(myType); myType.InvokeMember("MyProperty", System.Reflection.BindingFlags.SetProperty , null, myObjectInstance, new object[] {"blah"}); The InvokeMember step fails with “Member Not Found”, even though the said property does indeed exist. This seems to be straight forward to me so what am I missing?? Woke up this morning...and got myself a blog

      S Offline
      S Offline
      Serge Lobko Lobanovsky
      wrote on last edited by
      #2

      Some things to check: 1) Is your property ReadOnly? 2) Is is private? 3) What does the QuckWatch window say when you open it for "myObjectInstance" ? Regards, Serge (Logic Software, Easy Projects .NET site)

      S 1 Reply Last reply
      0
      • S Serge Lobko Lobanovsky

        Some things to check: 1) Is your property ReadOnly? 2) Is is private? 3) What does the QuckWatch window say when you open it for "myObjectInstance" ? Regards, Serge (Logic Software, Easy Projects .NET site)

        S Offline
        S Offline
        Senkwe Chanda
        wrote on last edited by
        #3

        Hi Serge, thanks for replying. The property is not readonly or private, it looks like this... public string MyProperty { get { return _myPropertyValue; } set { _myPropertyValue = value; } } However, the quickwatch window gives me what I expect to see. All the fields and properties are initialized to null or 0 (strings and ints) Woke up this morning...and got myself a blog

        S 1 Reply Last reply
        0
        • S Senkwe Chanda

          Hi Serge, thanks for replying. The property is not readonly or private, it looks like this... public string MyProperty { get { return _myPropertyValue; } set { _myPropertyValue = value; } } However, the quickwatch window gives me what I expect to see. All the fields and properties are initialized to null or 0 (strings and ints) Woke up this morning...and got myself a blog

          S Offline
          S Offline
          Serge Lobko Lobanovsky
          wrote on last edited by
          #4

          Hi again, Noticed one thing - you get a reference to the assembly to the var called "myAssembly" but you get a particular type with the following line (localDataAssm): Type myType = localDataAssm.GetType("MyNameSpace.MyType”, true, true); Object myObjectInstance = Activator.CreateInstance(myType); I'll give an example on how I instantiate objects via Reflection: ' persistedType should be a full type name, e.g. "MyNamespace.MyClass" function myCreateObject(persistedType as string) return AppDomain.CurrentDomain.CreateInstanceAndUnwrap("HereGoesAssemblyFriendlyName", persistedType) end function Regards, Serge (Logic Software, Easy Projects .NET site)

          S 1 Reply Last reply
          0
          • S Serge Lobko Lobanovsky

            Hi again, Noticed one thing - you get a reference to the assembly to the var called "myAssembly" but you get a particular type with the following line (localDataAssm): Type myType = localDataAssm.GetType("MyNameSpace.MyType”, true, true); Object myObjectInstance = Activator.CreateInstance(myType); I'll give an example on how I instantiate objects via Reflection: ' persistedType should be a full type name, e.g. "MyNamespace.MyClass" function myCreateObject(persistedType as string) return AppDomain.CurrentDomain.CreateInstanceAndUnwrap("HereGoesAssemblyFriendlyName", persistedType) end function Regards, Serge (Logic Software, Easy Projects .NET site)

            S Offline
            S Offline
            Senkwe Chanda
            wrote on last edited by
            #5

            Thanks Serge, I didn't know about that particular method. In any case, it turns out I wasn't casting my parameter to the correct type and that was the problem. Thanks for your help Serge, I appreciate it :-) Woke up this morning...and got myself a blog

            S 1 Reply Last reply
            0
            • S Senkwe Chanda

              Thanks Serge, I didn't know about that particular method. In any case, it turns out I wasn't casting my parameter to the correct type and that was the problem. Thanks for your help Serge, I appreciate it :-) Woke up this morning...and got myself a blog

              S Offline
              S Offline
              Serge Lobko Lobanovsky
              wrote on last edited by
              #6

              No problem :) Regards, Serge (Logic Software, Easy Projects .NET site)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups