❔ Why I need to specify the assembly while I was reflecting DataTable?
Why do I have to code like
but
18 Replies
By the way, I have referenced relevant assemblies not excluding System.Data.Common
how about using
typeof(System.Data.DataTable)
instead?Just have a try and I don't want a alternative.
Well, in the docs it says
If the type is in the currently executing assembly or in mscorlib.dll/System.Private.CoreLib.dll, it is sufficient to supply the type name qualified by its namespace.
which DataTable is not
but regardless, I really don't think
Type.GetType
is what you should be usingThat's a piece of helpful advice.
Are you being funny?
Kouhai just explained why it needs a fully qualified assembly, and I pointed out that DataTable doesnt meet the requirements for the short one
regardless, string-based runtime reflection is... not recommended, ever, if avoidable
use
typeof
if you just need the Type
for DataTableyeah
The "currently executing assembly" means my project?
more or less, yes.
So only for some assemblies I don't need to specify the assembly.
why are you using GetType in the first place?
this gives of XY problem vibes
I agree with Pobiega, it's better to use typeof, not reason to use GetType
I just want to figure it out.
okay, then its because I can make a type called
System.Data.DataTable
myself
its very easy
done.
so because this is possible, you need to fully qualify WHAT assembly you mean
and as you've noticied, this is annoying and error prone and needs to be updated if you ever update the nuget... its just terrible. this is why we avoid GetType, if possible
typeof
gets the Type
at compile time, so you dont need to mess with thisSurely annoying in package management
So better to use typeof()
yep
thank u
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.