non-static method requires a target

Started by stanl, September 20, 2020, 05:25:50 AM

Previous topic - Next topic

stanl

I've googled the error the script below generates, at a basic level it seems to arise due to a null value somewhere. I tried to specify a specific set of classes for Assembly.... got really confused. I'd like to get more than just a count for ExportedTypes.
Code (WINBATCH) Select


;Winbatch 2020A - Exported Types
ObjectClrOption('useany', 'System')
ObjectClrOption('useany', 'System.Reflection')
oTypes = ObjectClrNew('System.Reflection.Assembly','PublicNestedClass')
eTypes = oTypes.GetExportedTypes()
ct = eTypes.Count
oTypes =0
Message("Exported Types",ct)
Exit

td

You're getting the error because you don't have a target. The assembly class needs an assembly to be able to return information about one and it does not have a constructor that takes parameters. If fact, it is surprising that the CLR didn't throw an exception.  Type classes are generic so translating C# to WIL CLR is tricky but check out the CreatInstance methods.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Still confused over 'target'... snippet below gets same error


Code (WINBATCH) Select


ObjectClrOption('useany', 'System.Reflection')
oTypes = ObjectClrNew('System.Reflection.Assembly')
oAssembly = oTypes.CreateInstance('System.Drawing')
etypes=""
ForEach t in oAssembly.GetExportedTypes()
   etypes := t   
Next

td

Not sure what you are trying to accomplish but perhaps a refresher would help.  Here is a link to a script Diana wrote many moons ago.

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/dotNet/System_Reflection+Get~Assembly~Properties.txt
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

I found what I was looking for with another route.