Querying namespace where there are subfolders and "Namespace Provider=true" within a project

C

Claire

Hi,

I've been querying the current namespace using
Assembly.GetExecutingAssembly().GetName().Name to generate the file names
for my reports.
Example
string nameSpace = Assembly.GetExecutingAssembly().GetName().Name + ".";
RptCvDailyFileName = nameSpace + "rptUserSimpleDaily.rdlc";

I had problems when i decided to use folders within my reporting project to
split my report factory classes into groups to help manage the growing
number of files. I set the property "Namespace Provider" to true so that the
name of the folder would be appended to the root namespace.
So if the root folder namespace is "company.program.reporting", and I have
sub-folders "member" and "admin", the namespace for the factory classes in
one would be "company.program.reporting.member" and the other is
"company.program.reporting.admin"

When I query the namespace, in my member factory class, it's returning
"company.program.reporting" and not "company.program.reporting.member"
When I access my factory class from other projects, "using
company.program.reporting.member;" works correctly.

What do I call to get the correct/full namespace please?
 
B

Ben Voigt [C++ MVP]

Claire said:
Hi,

I've been querying the current namespace using
Assembly.GetExecutingAssembly().GetName().Name to generate the file names
for my reports.
Example
string nameSpace = Assembly.GetExecutingAssembly().GetName().Name + ".";
RptCvDailyFileName = nameSpace + "rptUserSimpleDaily.rdlc";

I had problems when i decided to use folders within my reporting project
to split my report factory classes into groups to help manage the growing
number of files. I set the property "Namespace Provider" to true so that
the name of the folder would be appended to the root namespace.
So if the root folder namespace is "company.program.reporting", and I have
sub-folders "member" and "admin", the namespace for the factory classes in
one would be "company.program.reporting.member" and the other is
"company.program.reporting.admin"

When I query the namespace, in my member factory class, it's returning
"company.program.reporting" and not "company.program.reporting.member"
When I access my factory class from other projects, "using
company.program.reporting.member;" works correctly.

What do I call to get the correct/full namespace please?

The "namespace" of an assembly is used by the compiler for the resources and
settings features, it isn't related to the namespace of any of the classes
you define.

Maybe you want to use GetCurrentMethod().DeclaringType instead of
GetExecutingAssembly() ?
 
C

Claire

Ben Voigt said:
The "namespace" of an assembly is used by the compiler for the resources
and settings features, it isn't related to the namespace of any of the
classes you define.

Maybe you want to use GetCurrentMethod().DeclaringType instead of
GetExecutingAssembly() ?

Hi Ben
Thank you for trying to help.

No, GetCurrentMethod().DeclaringType just returns the name of the class.
I'm extracting rdlc resources at run time from the assembly, so I need the
namespace for the resource manager to find them.
The factory class for member reports, plus all its related reports, is
stored in its own sub-directory. NamespaceProvider is set to true.
I assume that Assembly.GetExecutingAssembly().GetName().Name is returning
the namespace of the assembly itself ie "company.program.reporting".
But the Assembly also contains sub-namespaces eg
"company.program.reporting.members" and this 2nd namespace is the one that
the resources are compiled into and that's their file path.
I can fudge it of course by hard coding the path into a set of consts, but
it doesn't feel as elegant as querying the namespace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top