Assembly problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 ideas?
Thanks

Assembly thisAsm = this.GetType().Assembly;
string messageHeader = ((AssemblyProductAttribute)thisAsm.GetCustomAttributes
(typeof(AssemblyProductAttribute), false)[0]).Product +
((AssemblyTitleAttribute)thisAsm.GetCustomAttributes
(typeof(AssemblyTitleAttribute), false)[0]).Title + " V" +
Assembly.GetExecutingAssembly().GetName ().Version.Major.ToString() + "." +
Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString();
 
Hi Jez,

Try moving your code to a method (such as the constructor). Code should be
created inide a property or method, not in the main body of a class.

HTH,

Telmo Sampaio
MCT
 
Tried moving the code to the public FrmMain() method but I then get the
compile error: The name 'memessageHeader' does not exist in the class or
namespace 'HRUtils.FrmMain'.

I also get the same error if I move the code to a test method like
public string test()
{
Assembly thisAsm = this.GetType().Assembly;
string messageHeader = ((AssemblyProductAttribute)thisAsm.GetCustomAttributes
(typeof(AssemblyProductAttribute), false)[0]).Product +
((AssemblyTitleAttribute)thisAsm.GetCustomAttributes
(typeof(AssemblyTitleAttribute), false)[0]).Title + " V" +
Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." +
Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString();
return messageHeader;
}

This is really very odd as all I want to do is have a string messageHeader
that I can call to show in the main form and also display in some message
boxes. Is it better to store the product name and version etc. in a resources
file or another class?







Telmo Sampaio said:
Hi Jez,

Try moving your code to a method (such as the constructor). Code should be
created inide a property or method, not in the main body of a class.

HTH,

Telmo Sampaio
MCT

jez123456 said:
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 ideas?
Thanks

Assembly thisAsm = this.GetType().Assembly;
string messageHeader =
((AssemblyProductAttribute)thisAsm.GetCustomAttributes
(typeof(AssemblyProductAttribute), false)[0]).Product +
((AssemblyTitleAttribute)thisAsm.GetCustomAttributes
(typeof(AssemblyTitleAttribute), false)[0]).Title + " V" +
Assembly.GetExecutingAssembly().GetName ().Version.Major.ToString() + "."
+
Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString();
 
Back
Top