|
Sorry forgot to mention that I am using C# and VS.NET Beta 2 (still waiting for my retail version to arrive in the UK).
I have the package installer that comes with VS 6.0 but it doesn't accept my C# project as a project?
Thanks,
|
|
|
|
|
Within VS.NET go to File -> Add Project -> New Project then select the Setup and Deployment option and choose Setup Project or the Setup Wizard. Follow the steps and it will create a MSI install package for you.
|
|
|
|
|
There we go, I knew there had to be a simple smart way ...
You have made my day..
Cheers
|
|
|
|
|
Just wondering how to inherit 2 classes in c#?
Anyone there could provide some example code?
|
|
|
|
|
If you're referring to multiple inheritence (mi), it is not supported in C#. However, in addition to inheriting from a single class you can also inherit from as many interfaces as you like.
Cheers,
Tom Archer
Author, Inside C#
|
|
|
|
|
Hi, I've created a C# dll using the Class library project and have a method in there that just returns a string. I'd like to import this dll in my code dynamically instead of doing the "Add reference". How would I do that? Any help would be greatly appreciated.
|
|
|
|
|
I personally have not tried this, but this might point you in the right direction:
Try assem = System.Reflection.Assembly.Load(...) to load your assembly (C# dll).
Then t = assem.GetType(...) to get your type (class, etc.)
Then use t.InvokeMember(...) to call a method
You can also get a ConstructorInfo object through the Type object and create an instance of your class through ConstructorInfo.Invoke(...)
--
Peter Stephens
|
|
|
|
|
*sigh* I should have reloaded the forum before I started typing my post :-P
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Yes, but yours has better examples
--
Peter Stephens
|
|
|
|
|
First you use Assembly myAssembly = Assembly.LoadFrom(myDllPath); passing in the location of your dll.
Next you use the returned Assembly and search it for the Type you want to use (Type is the overlying type for all classes, enums, structs, delegates, and events). Type myType = myAssembly.GetType("myNamespace.myType"); .
Now with your type you can create an instance of it. object myInstance = Activator.CreateInstance(myType);
Now comes the fun part, invoking your method!
string retVal = (string) myType.InvokeMember("MyMethodName", BindingFlags.Public | BindingFlags.InvokeMethod, null, myInstance, new object { /* any parameters here, leave empty if there are none */ } );
There you have it! You've not successfully run a method and retreived the return value.
To sum it up again,
Assembly myAssembly = Assembly.LoadFrom( myDllFilename);
Type myType = myAssembly.GetType( myTypeName);
object myInstance = Activator.CreateInstance( myType);
string retVal = (string) myType.InvokeMember(
"myMethodName",
BindingFlags.Public | BindingFlags.InvokeMethod,
null,
myInstance,
new object { }
); HTH,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Thanks guys. Great help
|
|
|
|
|
hello
is there any way to determine what exception has been thrown ?
i have a try and catch block catching Exception all the time, but id like to know what type of Exception is thrown for an object that throws one, so i know what to catch.
|
|
|
|
|
The documentation should tell you what exceptions to expect, but you can get the name by doing the following
catch(Exception e) {
string name = e.GetType().Name;
Console.WriteLine("Exception: {0}", name);
}
Or just take the catch out altogether and the framework will catch it, in the description it should give the name of the exception.
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
public const byte[] FOO = {0x00FF, 0x00FF, 0x00FF,
0x00FF, 0x00FF,0x0074,
0x0001, 0x0003,0x0075,
0x0003, 0x0000};
I get a complie error
Array initializers can only be used in a variable or field initializer. Try using a new expression instead.
And yes i have tried using new, i cant get that either, someone help me plz ?
|
|
|
|
|
hmmm, seems like a stupid problem; the compiler should be able to take care of that or so I would think.
This does the trick though, hope it helps.
public static readonly byte [] FOO = new byte[] {
0x00FF, 0x00FF, 0x00FF,
0x00FF, 0x00FF,0x0074,
0x0001, 0x0003,0x0075,
0x0003, 0x0000
}; James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
You can only use 'const' on simple values that can be computed at compile time. For example, assigning a fixed value.
Your code wants to do something more complex which involves creating a new object. Just because we can see it is fixed does not mean the compiler can.
Therefore you need to use 'readonly' instead of 'const' to get the same effect.
Phil Wright
uk_phil_wright@hotmail.com
|
|
|
|
|
What is the difference between the 'bin' and 'obj' directories in which your source files are located for VS.Net ?? It seems the contents are very similar (ie. an .exe file located in both locations after a build)
thanks in advance
Soliant
|
|
|
|
|
I believe the bin directory contains the final output, while the obj directory contains any temporary files (compiled .resources), vs.net temp files, and the like.
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
I am having quite a time trying to add a resource file to my project in
VS.NET. I've been scouring the help docs and I can't for the life of me figure out
what I'm doing wrong. Ideally, I'd like to find a link somewhere that walks me through, step by step, in creating a resource file (and explaining the advantage/disadvantages & difference in using a .resource or .resx file), adding it to your project and finally accessing the resources within that resource file.
Here's my issue... I have a resource file called Icons.resources (created with a freeware app I found... saves the resource as a .resource/resx file).
I have added it to my project and set it's properties to "Embedded
Resource"... but everytime I compile it, I get the following error:
Additional information: Could not find any resources appropriate for the
specified culture (or the neutral culture) in the given assembly. Make sure
"Icons.resources" was correctly embedded or linked into assembly "Picture
Utility".
baseName: Icons locationInfo: <null> resource file name: Icons.resources
assembly: Picture Utility, Version=1.0.783.28733, Culture=neutral,
PublicKeyToken=null
I have also been going through a program that does
the exact same thing I'm doing and can't seem to find the difference between
his and mine and what I'm doing wrong.
Thanks in advance
Andrew Connell
IM on MSN
andrew@aconnell.com
|
|
|
|
|
I got it... for those of you that have the same problems...
When I created my resource file ("Icons.resource") and added it to my project ("PictureUtility") as an embedded resource, I needed to access it by the name the project would understand... which is "PictureUtility.Icons".
Just posted by success story in case others have the same problem.
-AC
Andrew Connell
IM on MSN
andrew@aconnell.com
|
|
|
|
|
BTW, the prefix to access the file is actually the default namespace for the project. If you blank out your default namespace, you will then access the icon by just "Icons".
--
Peter Stephens
|
|
|
|
|
s = new Socket(
AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp );
s.Bind(localEndPoint);
s.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.ReceiveTimeout,1000);
This code produces a runtime error:
An unknown, invalid, or unsupported option or level was specified in a getsockop
t or setsockopt call
Any help anyone ? I just want to set a timeout on recive of a UDP packet.
|
|
|
|
|
I believe it is because UDP doesn't support Timeouts, or so this thread on the Advanced DOTNET list seems to suggest.
Yes just when you thought I couldn't push the DOTNET mailing list anymore they make a new one!
Hope that thread gives you some ideas,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
You are right, UDP is "connectionless", and because of that you can't set a timeout.
When you send UDP packets, you just send them, but you never know if the reciever get the packets or not...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Thanks, James, for the link to those two DotNet mailing lists. I'm already signed up!
--
Peter Stephens
|
|
|
|