473,480 Members | 5,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

[Assembly].GetExecutingAssembly().GetName().Name Missing Underscor

I am attempting to embed a text resource in my assembly and following MSDN
article
http://msdn.microsoft.com/library/de...stallation.asp
using reflection to access the full path of the embedded resource. The
assembly name is MyCompany Database Translator which is correctly reported
using [Assembly].GetExecutingAssembly().GetName().Name. Here is the code
supplied to get access to the embedded resource:

Private Function GetSql(ByVal Name As String) As String
Try

' Gets the current assembly.
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()

' Resources are named using a fully qualified name.
Dim strm As Stream = Asm.GetManifestResourceStream(Asm.GetName().Name
+ "." + Name)

' Reads the contents of the embedded file.
Dim reader As StreamReader = New StreamReader(strm)
Return reader.ReadToEnd()
Catch ex As Exception
MsgBox("In GetSQL: " & ex.Message)
Throw ex
End Try

End Function

Using the method above fails because it tried to load MyCompany Database
Translator.textfile.txt, the resource is actually stored at
MyCompany_Database_Translator.textfile.txt with underscores in place of the
spaces. Is there another property I can access to get the correctly formatted
assembly path or is a string.replace the only way to address this? Thank you.
Nov 21 '05 #1
3 4317
Is there another property I can access to get the correctly formatted
assembly path or is a string.replace the only way to address this? Thank you.


Why do you have to name the resource the same as the assembly name?
Can't you just give the text file a name without spaces?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
"Mattias Sjögren" wrote:
Is there another property I can access to get the correctly formatted
assembly path or is a string.replace the only way to address this? Thank you.


Why do you have to name the resource the same as the assembly name?
Can't you just give the text file a name without spaces?


The project, executable and assembly name are the same automatically. The
Project name is MyCompany Database Translator, the executable is MyCompany
Database Translator.exe and therefore, the assembly is MyCompany Database
Translator. Any resource I embed should be at the path MyComany Database
Translator.resource.ext but it instead uses the default namespace for the
path of MyCompany_Database_Translator.resource.ext. There are no spaces in
the name of my resource file, just the actual project and executable itself.
The question therefore being, how do I use reflection to access the correct
root path name for my assembly instead of using
GetExecutingAssembly.GetName.Name.String.Replace(" "c,"_"c). Thanks.
Nov 21 '05 #3
The project, executable and assembly name are the same automatically.
Unless you change them.

Any resource I embed should be at the path MyComany Database
Translator.resource.ext but it instead uses the default namespace for the
path of MyCompany_Database_Translator.resource.ext. There are no spaces in
the name of my resource file, just the actual project and executable itself.
Right, it's the default namespace that matters, not the assembly name.
Since namespaces can't contain spaces they are replaced by
underscores.

The question therefore being, how do I use reflection to access the correct
root path name for my assembly instead of using
GetExecutingAssembly.GetName.Name.String.Replace( " "c,"_"c). Thanks.


Change the root namespace to contain periods instead of underscores
(MyCompany.Database.Translator for example). Then just get the
namespace of a class at the root level, for example using
GetType(YourMainClass).Namespace.

Or even better, remove the root namespace so that the resource name
becomes simply "resource.txt".

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2004
by: Russell Stevens | last post by:
Should be trivial - I want to detect the program version so that I can take steps to update things to the current version. Pretty simple - just use Application.ProductVersion So I install the...
1
1486
by: Robbie from Philippines | last post by:
how do i read the assembly version (not the file version) of ? tnx..
1
1651
by: jez123456 | last post by:
Hi, I'm trying to add the product, title and version number to my main form with the following code. I've tried using this code in the public class FrmMain section but I get the error thisAsm'...
2
1795
by: e_zverev | last post by:
Hi The question concerns the ways ASP.NET loads required assemblies into it's app domain. I know of a deprecated feature of clr assembly detection in which the use of environment variable...
1
17768
by: Patrick | last post by:
Has been trying to get an ASP.NET DLL's modification date/time for the "release date/time" to be displayed on the page's footer Using: System.Reflection.Assembly...
1
2048
by: Andrew | last post by:
In ASP.NET 1.1 I used to retreive the version of my code-behind assembly using following syntax: Assembly.GetExecutingAssembly().GetName().Version The version was defined in AssemblyInfo.cs using...
1
1156
by: Rob Meade | last post by:
Hi all, Having used to be able to specify the version numbers for my applications I am a bit of a loss with regards to what to do now...from what I've read (skimmed through to be honest) on the...
4
7411
by: Rob Meade | last post by:
Hi all, Having used to be able to specify the version numbers for my applications I am a bit of a loss with regards to what to do now...from what I've read (skimmed through to be honest) on the...
1
2354
by: Sylvie | last post by:
How can I get my Dotnet application and my class library DLL's Assembly version infos in my app ? Thanks
0
6905
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.