fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Help with some Reflection issues (syntax etc. ?) ...........

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4105

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi guys, Team and all,

I could do with some help please - regarding the correct X# syntax to make 'GetType()' work with suitable text string input. I have it working for some input, but not others / all.

Here is a working example - where simply the Class is provided as a Namespace.Class string :-



Even the fuller two parameter string input works as well (line 211) :-



However, my problems come when I try another assembly altogether, outside that of the common two of 'System.dll' and 'mscorlib.dll' - see below :-



Remember, I wish to have a string input to the 'Type.GetType()' method and not be told to reach for the operator 'typeof()' which is working the in the last image shown below :-



I am well aware that the input text needs to be case sensitive.

Could it be that 'System.Drawing' is closed in some way - strong naming or whatever ?

HELP would be most appreciated.
TIA & Best regards,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4106

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Sorry guys,

I seem to have posted the wrong image regarding the second input of 'Drawing.dll', I did do it right in one of my tests supplying 'System.Drawing.dll'.

I got a bit confused when I could not attach the images yesterday when I had all the stuff prepared for a posting. Doing it again 'cold' today is my excuse ;-0)

Help still needed,
Phil.

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4107

  Chris's Avatar Chris Offline Posts: 1137
Hi Phil,

First of all, the name of the dll is not Drawing.dll, but it's System.Drawing.dll. Also, with this method (Type.GetType()), for extrnal types (not defined in mscorlib.dll) you need to specify the fully qualified name of the type, which includes full assembly (ll) name information, so you'd need something like:

Type.GetType("System.Drawing.Color, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

Probably too much trouble doing it like that, so I think it's better to get first an Assembly object of the dll that contains the type, then do a simple oAssembly:GetType(), where you can specify the type simply by its name.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4108

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Thanks Chris,

I will give it a go - both ways, so I can at least then explain 'stuff' in my eNotes, and publish some code that does work and produce results.

Have you any idea why there is such a change required ? Is it because there is no way they (MS) are going to change the core assemblies, but reserve the right etc. to change assemblies more on the 'fringe' of things ?

Any ideas ?
Cheers,
Phil.

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4109

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742

Chris Pyrgas wrote: Hi Phil,

Type.GetType("System.Drawing.Color, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

Chris


Chris, I can find the details of most of this in the Properties Pane - BUT - where do I get the 'PublicKeyToken' from ?

Regards,
Phil.

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4110

  Chris's Avatar Chris Offline Posts: 1137
Hi Phil,

One easy way is to add a reference to System.Drawing in a project, then type this in Start()r somewhere else:

? System.Drawing.Point{}:GetType():AssemblyQualifiedName

this will give you the complete name of the type that you need, together with the full assembly name.

But I think there's no point at all to go that route, I don't think anybody is ever using Type.GetType() this way. Normal way is to get an Assembly object (either by directly loading from disk with Assembly.LoadFrom() or LoadFile()), or get it through other means, for example Assembly.GetEntryAssembly():GetReferencedAssemblies() gives the referenced assemblies of your main app).

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4111

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Thanks again Chris,

I realise the general ideas and comments you make, and the advice too, AND, I will reflect this in what I write in the eNotes.

I am going to look deep into GetAssemblies() etc. tomorrow.

It seems like the 'good' idea I had for interactively inputting Class 'string' names and getting back the members list etc., is probably NOT such a good idea as it first seemed ;-0((

Don't worry, I will sort it all out tomorrow, and make it sensible. Fingers crossed.

Best regards,
Phil.

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4112

  Chris's Avatar Chris Offline Posts: 1137
Hi Phil,

The problem with the first method you used, is that the type you ask for maybe declared in one of the thousands of .Net dlls that are included in every PC (unless it's one of the standard types, defined in mscorlib.dll). So in order to avoid loading and examining (after finding!) every single dll in the disk in order to find the type you are asking for, Type.GetType() requires to specify and describe completely the dll file where the type is located in, so it can load it at runtime and get the type defined in it. And still AFAIK it will not find types in dlls located just in some folder in the PC, but only if the dll is also registered in the GAC.

For this reason, I think using Type.GetType(string) is completely impractical and you need to use one of the more straightforward methods of loading the assembly manually first and then locate the type inside the assembly.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Help with some Reflection issues (syntax etc. ?) ........... 1 year 3 months ago #4117

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Thanks Chris,

I agree, and see what its all about.

I will adjust my researching and the way I attack the problem, and the way I write the eNotes. This is not a topic that I have given much attention to over the years - hence I came at it in the wrong way / direction.

Regards &
Have a nice day,
Phil.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1