I am attempting to extract an embedded resource from the currently executing assembly in C#.
My fully-qualified assembly name is of the form Alpha.Beta.Gamma.Delta.MyTaskLibrary
(obviously, this isn't actually the name; but the number of parts exactly corresponds to the name I have. The default namespace of the project is Alpha.Beta.Gamma.Delta.MyTaskLibrary
.
When I execute System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
, instead of showing me the above name, it shows me Gamma.Delta.MyTaskLibrary
.
On the other hand, when I do typeof(ClassName).AssemblyQualifiedName
, I get the fully-qualified name as above along with the version, culture and public key token.
Why is 开发者_JAVA百科there this difference in behavior?
EDIT: My ultimate goal is to get an embedded resource from within this assembly by using
Assembly.GetExecutingAssembly().GetManifestResourceStream(assemblyName + "." + fileName)
It's precisely this assemblyName
that I'm trying to retrieve. I tried this method call with both "Alpha.Beta.Gamma.Delta.MyTaskLibrary.ResourceFile.ext"
and "Gamma.Delta.MyTaskLibrary.ResourceFile.ext"
, and only the former worked.
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
gives you a name of the assembly. Usually it is the name of the file where assembly is located.
In other words, you could have assembly named Abcde.dll
and have namespace My.Namespace.Name.Inside.Of.Abcde.Assembly
. They are not related. And project's default namespace is... hm, it is a default. It doesn't get compiled into resulting assembly. It is just a Hint for Visual Studio which namespace it should place a class/interface/whatever to if you adding new item to this concrete project.
How are you going to get name of the class that is not even mentioned in your request?
You get call GetModules() on the assembly and iterate over the collection of modules and access the FullyQualifiedName property on each module.
精彩评论