|
Can't compile with a static constructor?! Not sure they'd be much use in the language if that were the case. Sorry, you're wrong too.
Regards,
Rob Philpott.
|
|
|
|
|
hmmm... well as the TestStatic class is not static it can have a constructor, i just didnt know it could be static. but either way any static methods (i.e. SaySomething) can be called without the need to create an instance of your class, which you are not doing in your code. So both calls to the SaySomething method should be successful, can you explain why either would fail? i think not.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Any class can have a static constructor, but it is highly recommended to make sure they never throw exceptions.
|
|
|
|
|
musefan wrote: i think not
Really, what is wrong with you people? I think so as described below.
Regards,
Rob Philpott.
|
|
|
|
|
what about...
Afternoon Exception
HI
Hi 2
edit: no, that wouldnt happen if an exception is thrown when the program runs then surely it would just crash with the unhandled exception in the static constructor, no?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Ok, well, you have a static ctor which will throw an exception the first time the type is used, so it would be:
Afternoon Exception
Hi 2
Correct?
|
|
|
|
|
Nope!
Regards,
Rob Philpott.
|
|
|
|
|
Ok, I rethought.
The ctor fails, and that is bad.
How about
Afternoon Exception
Afternoon Exception
?
|
|
|
|
|
Good man! And we have a winner. Yep, the type initialiser fails both times - in short an exception in a static constructor is very bad news.
Well done.
Regards,
Rob Philpott.
|
|
|
|
|
I ran your code for the fun of it, and although the exception message is output twice, the type initializer only fails once, as far as the debugger can tell.
|
|
|
|
|
Congratz! =)
(Shame on me, SHAME ON ME!)
|
|
|
|
|
Hey guys, I have a simple question to with I haven't been able to find a clear answer !
I want to to get ID of a row that I select ! (not row ID, the value of ID column)!
Could u help me out please !
Mr.K
|
|
|
|
|
Event: DataGrid1_MouseDown or DataGrid1_MouseUp
method: Grid1.Rows[0].Columns[0].Value.ToString()==""
ok,understand? so easy ,my english is not very good ,so i can only do my best to help u
|
|
|
|
|
Firstly you need to make it clear if it is a DataGrid or a DataGridView that you are using. They are two different controls, and which one you are using will make a difference to the answer.
I am going to give you an answer based on two assumptions, that it is in fact a DataGridView , and the Column is called 'ID'.
Assuming that you can identify the row selected, hint - research DataGridView.CurrentRow , and have it assigned to a field:DataGridViewRow selectedRow = dataGridView1.CurrentRow .
string idString = selectedRow.Cells["ID"].Value.ToString();
The Point about the two types of grid is important, otherwise you get no answers, or worse you spend ages following a totally wrong answer.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanx all the guys who helped me out !!!
finally with ur help found it out !
DataGridViewRow SelectedRow = new DataGridViewRow();
SelectedRow = GrammarGrid.CurrentRow;
SelectedGrammarID = Convert.ToInt32(SelectedRow.Cells["GrammarID"].Value);
|
|
|
|
|
Hello all,
I have written a simple application that allows me to encrypt / decrypt files using AES256 encryption. This part works. However, when using wildcards for decryption such as *.doc if you attempt to decrypt a file that was not previously encrypted a Crypto exception is thrown regarding invalid data length.
Is there a way to detect if a file is encrypted or not? I have searched and all I can find is the option of setting the encrypted attribute but this requires using the windows api and I wanted to avoid this.
Thanks for your help.
Russell
|
|
|
|
|
Every encryption has an identifier, once you know the identifier and its offset(oftenly at 0x0) you can know what type of encryption it is then you need to decryt it using its format.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I don't think so. AFAIK, the .net framework doesn't support this apart from the method you didn't want to do. Something you could try though - try to decrypt it. If it throws an exception, you know it wasn't encrypted to start with. Something like this
bool IsEncrypted(string file)
{
try
{
return true;
}
catch
{
return false
}
finally
{
}
}
|
|
|
|
|
Thanks for your replies, however the encryption / decrption part works fine. I have a setup like so:
for each (File......)
try {
load file into a byte array
try and decrypt data in byte array
catch (Exception ex)
{
Oh no, failed to decrypt..
}
When I try to decrypt the file and it fails the exception is thrown and I am then exited from the app. There is no way to get back to the for each loop. I am hoping there is some command or routine that I can use that would enable me to look for something to determine if it is encrypted.
I thought about a header but I am using salt which randomizes the first 4 bytes.
Thanks
Russell
|
|
|
|
|
First, use the code block formatting on code samples.
Second, if your code's written like this (had to insert a few extra }'s), unless you have a throw statement inside the catch block the exception shouldn't break the loop. That should only happen if the entire loop is inside a try/catch block instead of each iteration of it.
for each (File......)
{
try
{
load file into a byte array
try and decrypt data in byte array
}
catch (Exception ex)
{
Oh no, failed to decrypt..
}
}
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
My 2 cents: I would try to catch a specific exception, instead of any, because an IOException could happen, which would not necessarily mean the file is not encrypted.
|
|
|
|
|
Hi,
a simple solution would be to change the filename, preferably by appending a new extension; that way you now a decrypt is necessary, which would decrypt and remove the added extension.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Yes I thought about that, but it defeats the purpose of my app, and it is too easy for a user to change the filename to something else and then I am back to stage 1 again.
|
|
|
|
|
The main goal of a file extension is to indicate which program(s) can open your file; as long as a .doc file is custom-encrypted, Word won't be able to decrypt it, your own decryptor can, so it makes perfect sense to use a special file extension.
A user can always change filename parts; if he changes .doc into .xls things will go wrong too.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
The only way to tell is to try and decrypt the file. WHen you get the exception, handle it appropriately and you've got your answer as to if the file is encrypted or not. There's really no other way to tell.
|
|
|
|