|
Hi there,
I am currently creating a windows service that calls a class. the class access a file in a certain folder to create a instance of this file(dll). When I call the dll from a console application it works very well with no problems.
When I do call it from a windows service it gives me an invocation exception error. What I did find was that the class has a problem with the file in the specific directory. I have checked user rights and ran the service as an administrator but it cannot access the file.
A friend of mine has precisely the same problem but on totally different sets of code. The only thing the same between his code and mine is that it is both services calling a dll trying to open a file in a specific location.
Can anyone please help me out here.
regards
Nic Scheepers
|
|
|
|
|
In the Service snap in, bring up the properties for the service you have started. There is a log on tab, which identifies who the service logs in as. Check to see what this value is. Then, assign read/write privileges to that user to the directory that the file is present in.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi there
Thank you for the reply.
This is one of the first things I did and I used both an administrators username and my username to start the service with in the log-on tab. I also made sure they had the priveleges to read and write to the specific directory.
Another question relating to this : Can you use the "Assembly.Loadfrom" method in a service. Tis is basically where it originates from.
Regards
Nic Scheepers
|
|
|
|
|
Hi Guys,
Does anyone know how to deal with leagcy binary .dat files in .Net i have a few systems in C that write to .dat files 1 example is the following structure:
typedef struct AccountIndexData {
char Account[12];
long Record;
} AccountIndex;
typedef struct AccountDataFormat{
char Account[12];
char Company[32];
char Address[4][32];
char TelFax[2][18];
char Contact[22];
int PriceLevel;
int Stop;
int Cash;
long First;
long Last;
long Limit;
long Balance[5];
int Lock;
} AccountData;
My question is how do i handle these files in & retrieve information from a .Net application
Thanks
Keith
|
|
|
|
|
Try looking at the System.IO.BinaryReader class.
|
|
|
|
|
If the file is a flat file (like old C days), just create a class, similar to structure above.
Then use a streamReader to read the info, and fill the object:
Something like:
while ((line = sr.ReadLine()) != null)
{
myClass.myProperty1 = line.Substring(0,5);
myClass.myProperty2 = line.Substring(5,2);
//etc..etc..
}
|
|
|
|
|
ednrgc wrote: If the file is a flat file (like old C days), just create a class, similar to structure above.
Yes it is a flat file.
Thanks for the help i'll give that a go
Keith
|
|
|
|
|
Use BinaryReader and its specialized methods such as ReadInt16 as appropriate.
Do not assume you can read everything using strings, that will fail due to terminating nulls,
and the difference between ASCII and Unicode.
Also be careful when reading characters:
if the file got created by a C/C++ program using char (8 bit each), you should read each char
with ReadByte and convert to Char (which takes 16-bit).
Luc Pattyn
|
|
|
|
|
|
Does anybody know why is taking 4 seconds for a call to Connect(host, port) to complete?
If I try the same from a command prompt the connect is instantaneous.
The instance of the TcpClient class is created in 14-18 milliseconds but the Connect
is annoying ....
|
|
|
|
|
i have a windows application. which contents a button and a list box when i click the button the list box is filled with the name of file. then i again copy some more file to directory when i click the button again then the name of same file and new file is displayed again which is obviuos.but what i want is in the secnd click it display only the files whic are copied on second instance i.e all the file in directory with out repetation.
well my problem is quiet complex if you have any idea regarding seacrhing in array where getfiles returns would be more appreciable.
|
|
|
|
|
After the 1st process of the files, clear the listbox.
|
|
|
|
|
As Ed Said Just clear the list box but do this before any processsing. So the first line of code in your button event would be:
ListBox.Items.Clear();
Keith
|
|
|
|
|
hi
i want to use iframe tag and set src to one htm file that have picture, but when i use this tag,pictures is not appeare in my webpage,but when i use htm file in browser, it show pictures. where is the problem and how to full my htm file(with images) in ?
note : the images folder already exist in my project.
|
|
|
|
|
Post your code, so we can see where the problem is.
|
|
|
|
|
I do an electronic project, and I would like to know how can I communicate to usb port with c# (in visual studio program).
I only know that I need a dll file and I don't know where can I find it.
tankes,guy.
|
|
|
|
|
|
Hi,
I have a class A that creates subclasses B and those classes have an event OnChanged that is assigned to a procedure in the mainclass A.
Subclass B can be serialized to XML using SOAP so i can send it by TCP to another location / application.
Class B is marked [Serializable] (and ofcours class A not because i don't need to send it.)
Strange thing is when the event OnChanged in class B is not assigned it delivers no problem.
when the event is assigned SOAP needs Class A to serialize also and ofcours it gives an error because that class A is not serializable..
So this is my problem...
I tried to use [nonserializable] for the public event in class B but this isn't allowed..
Anyone any idea how i can solve this problem ?
settings the event to null and assign it again after serialization could be possible but ofcours that is not a very good proper way to do it.
thx for your time
Kurt
|
|
|
|
|
K,
meanwhile we've found it.
i placed this before my event declaration...
[field:NonSerialized]
greetz
Kurt
Thx to dimi.
|
|
|
|
|
I have a array of string .How can I place the array to byte
String[] mm = {"A","B","C"};
byte[] by = new byte[3];
by = mm; This one make error
How can solve this problem.
Continue...
|
|
|
|
|
Hi
YOu are assigning string values to byte, thats why its giving error. You can use following code
String[] mm = {"A","B","C"};
byte[] by = new byte[3];
for (int i = 0; i < mm.Length; i++)
{
by[i] = Convert.ToByte(mm[i]);
}
|
|
|
|
|
Generally you can't convert a string to a byte. For example a string like "Hello world!" does not fit into a single byte.
If you have a special case where all strings always are exactly one character long, you can get that character and get the character code for it.
The character code is still 16 bits, though, while a byte only is 8 bits. To store a character code in a byte only works if the characters are all only ASCII characters, so that you can safely discard the top 8 bits of the character code.
---
Year happy = new Year(2007);
|
|
|
|
|
Hi all,
I'm wondering whether any of you people can help me out with this problem that I have with a user control that I have been trying to get working.
The first part of the user control is a flat circular button ( called SampleButton) that toggles colour when clicked. This control has an OnClick method as follows
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
(code to change colour and call invalidate....)
}
Then, from this I am creating a matrix of these buttons in another user control that inherits from SampleButton (which in turn inherits from UserControl), e.g. a 3 x 3 matrix, like so:
O O O
O O O
O O O
I do this using a couple of for loops (the number of SampleButtons has to be dynamic), a bit like:
for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 2; j++)
{
SampleButton samBtn = new SampleButton();
samBtn.Location = new Point(i, j);
this.Controls.Add(samBtn);
}
}
}
In this control I have an OnClick method:
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
MessageBox.Show("The Sample Button Array has been clicked");
}
The problem is that although when I click on the array of sample buttons, their colour changes (so the first OnClick method is running ok), the messagebox never appears (the method is never entered).
Why does this second OnClick method never get called?
Thanks,
Rob
|
|
|
|
|
When you click a SampleButton its OnClick fires, and it causes its base.OnClick to fire
since that is what you requested; but its base is Button, not your 3x3UserControl.
If your 3x3UserControl wants events for its buttons, it should include the line
samBtn.Click+=new EventHandler(...);
where it creates the buttons.
Luc Pattyn
|
|
|
|
|
Hi,
Thanks for your reply Luc. I added the code to add event handlers for each button and tested the event within the User Control designer and all seems fine there. However, when I add a Button Array to a windows form, and create a Click event for the whole array:
private void buttonArray1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button array has been clicked");
}
(and this.buttonArray1.Click += new System.EventHandler(this.buttonArray1_Click) in the initialiseComponent method)
This event does not trigger. This was one reason why I added the OnClick method to the ButtonArray control as I thought that by doing this it would allow clicks on the ButtonArray to be handled within my form (my logic is probably completely wrong here)
Thanks again,
Rob
|
|
|
|