473,545 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Assembly].GetExecutingAs sembly().GetNam e().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].GetExecutingAs sembly().GetNam e().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].GetExecutingAs sembly()

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

' Reads the contents of the embedded file.
Dim reader As StreamReader = New StreamReader(st rm)
Return reader.ReadToEn d()
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.text file.txt, the resource is actually stored at
MyCompany_Datab ase_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 4330
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.reso urce.ext but it instead uses the default namespace for the
path of MyCompany_Datab ase_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
GetExecutingAss embly.GetName.N ame.String.Repl ace(" "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.res ource.ext but it instead uses the default namespace for the
path of MyCompany_Datab ase_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
GetExecutingAs sembly.GetName. Name.String.Rep lace(" "c,"_"c). Thanks.


Change the root namespace to contain periods instead of underscores
(MyCompany.Data base.Translator for example). Then just get the
namespace of a class at the root level, for example using
GetType(YourMai nClass).Namespa ce.

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

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
2017
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 app on a file server. Various workstations then load the app and run it. Some workstations are Win98, some are XP. To enable users to access the...
1
1494
by: Robbie from Philippines | last post by:
how do i read the assembly version (not the file version) of ? tnx..
1
1662
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' denotes a 'field' where a 'class' was expected. Also it will not compile 'this' with the error Keyword this is not available in the current context Any...
2
1801
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 DEVPATH is involved. My problem is that this way doesnot seem to work when I need to locate an assembly in my ASP.NET application. Does the DEVPATH...
1
17789
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 asm=System.Reflection.Assembly.GetExecutingAssembly(); appVer = asm.GetName().Version.ToString(); // get the location of our executing assembly System.IO.FileInfo inf = new...
1
2058
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 After migrating to ASP.NET 2.0 this line of code always return 0.0.0.0. How do I retreive the assembly version of ASP.NET application? Thanks
1
1159
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 net it would seem that assembly.info is no more and that .net handles all of the version itself.... Is there anyway to override these settings? If...
4
7413
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 net it would seem that assembly.info is no more and that .net handles all of the version itself.... Is there anyway to override these settings? If...
1
2360
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
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7446
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5349
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
731
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.