Why different error codes for same Exception? - c#

I am doing one synchronization example. I got two exceptions which are having same details about exception. But with the error codes.
And both exceptions have the same Inner Exceptions
What is means? What Error Codes will tell us more than exceptions?
How to get the details about my error code.
Thanks in Advance
Microsoft.Synchronization.SyncException: A storage engine operation failed with error code 25051 (HRESULT = 0x80004005, Source IID = {0FB15084-AF41-11CE-BD2B-204C4F4F5020}, Parameters=(0, 0, 0, , , , )).
Microsoft.Synchronization.SyncException: A storage engine operation failed with error code 25009 (HRESULT = 0x80004005, Source IID = {0FB15084-AF41-11CE-BD2B-204C4F4F5020}, Parameters=(0, 0, 0, , , , )).

From the wording of the message it looks like these are SQL CE errors. If so, have a look here for the meaning of the actual error codes. For .NET code that wraps native code, it is not uncommon that one managed exception, SyncException here, is used with multiple error codes in addition (most prominent example Win32Exception).
From the documentation there seems to be no apparent way to get this numeric code.
However, whether you can really react differently in your code, depending on one error code or the other, is questionable anyway. Log the error with all details
and be done with it.

Finally got cleaned after reading the documentation

Related

Application crashes on element reader (pdftron)

I have an issue with pdftron, where opening a certain file, will cause our application to crash with following error:
An unhandled exception of type 'pdftron.Common.PDFNetException' occurred in PDFNet.dll
Additional information: Exception:
Message: Missing resource
Conditional expression: res
Filename : ContentResources.hpp
Function : trn::PDF::ContentResources::GetResource
Linenumber : 26
In our code: it's in the following line that the error occurs:
while ((element = elReader.Next()) != null)
When doing try/catch, we see that the only thing missing from the page is the text that's written diagonally on that page. Does this have anything to do with a missing font maybe ? Don't mind the cursor in the picture, it doesn't know where to go with the text missing.
I can send the pdf file on request.
PDF File
If you are not on the latest version of PDFNet, 6.7.1, then I would first try against that, as the issue might have been resolved already.
Otherwise, since the issue is document specific, you would need to provide that, by either sharing here, or sending to pdftron support.

C# powershell ErrorDetail usage

I have a custom powershell command derived from PSCmdlet and on error I want to provide my own error message. As per MSDN ErrorDetails propery on ErrorRecord does that :
Provides additional error information for an error record, such as a
more detailed replacement error message.
How ever I am not able to get it working, I have DisplayStrings.resx, in this I have stored my custom error message with the ID InvalidOrNoSite, but when I execute the following code, it shows the same old style error and not my custom error.
ErrorRecord err = new ErrorRecord(new ArgumentException(), "", ErrorCategory.InvalidArgument, this);
err.ErrorDetails = new ErrorDetails(this, "Resources.DisplayStrings.ResourceManager", "InvalidOrNoSite", null);
ThrowTerminatingError(err);
Any examples on how to use ErrorDetails?
The customisation of ErrorDetail works if you change your error in a non-terminating error.
This behaviour is not explained in microsoft documentation [ or at least I have not found it :) ] but in a book I've buy some year ago ( Wrox - Professional Windows PowerShell Programming - February 2008 ) at page 97 is reported that in terminating error doesn't work.
My workaround is to set a 'flag' variable to true in the catch and after test this variable and do or not do some or all following code.

Copy and read files from dvd and CD C#

I am trying to use the following code in my project. http://www.codeproject.com/KB/miscctrl/imapi2.aspx
However, When I run the application and click on "Detect Media" it says "Media not supported".
Can someone please help me with this issue. Why does it say Media not supported?
Thank you,
Divya.
Referring to Eric's source code for the application, this text comes from the buttonDetectMedia_Click method in the MainForm class:
discFormatData = new MsftDiscFormat2Data();
if (!discFormatData.IsCurrentMediaSupported(discRecorder))
{
labelMediaType.Text = "Media not supported!";
_totalDiscSize = 0;
return;
}
So, the call to IsCurrentMediaSupported is failing. This is actually a COM Interop call to IDiscFormat2::IsCurrentMediaSupported. The MSDN documentation does mention some other possible HRESULT values, though I'd expect that if they occurred, a COMException would be thrown. The sample code does catch this exception, in which case a message box is displayed - that's not the case here though.
When I ran the sample, I got the same "Media not supported!" error. I have a DVD burner, but there is no disc in the drive (don't have any blank discs with me at the moment!), so that appears to be one answer to why you'd get that message. I'd guess if the media in the drive was not writable or incompatible with your burner, you'd also get that message.

DSACryptoServiceProvider constructor throws CryptographicException

This code below thows the following error:
System.Security.Cryptography.CryptographicException "The handle is invalid"
CspParameters CSPParam = new System.Security.Cryptography.CspParameters(13, null, null);
CSPParam.Flags = CspProviderFlags.UseMachineKeyStore;
CSPParam.KeyContainerName = "MyKeys";
System.Security.Cryptography.DSACryptoServiceProvider r = new System.Security.Cryptography.DSACryptoServiceProvider(CSPParam); //Error occurs here
This code had been working with no issues then it started throwing this error. I can't think of anything that I have changed that relates to this. Has nayone seen this error? Any ideas of what to try?
I cannot remember everything that goes on behind the scenes in CAPI, but if I recall it can be fairly painful. By using null arguments you might get something called (I think) the default key container. I don't think you can count on the default key container not existing before you run your code, and perhaps if it exists then you get an error. You can read all about the CryptAcquireContext function and the various _KEYSET_THIS_THAT flags to learn about how to do this in unmanaged code. I have no clue if there is a .NET wrapper around that horror or not.
Make sure you have the proper permissions to do this action.
information

Problem : Getting a mobile drive size using C# throws exception - Commented

when i run this code :
CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo;
int iResult = 0;
IntPtr Buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CONADefinitions.CONAPI_FOLDER_INFO2)));
iResult = CONAFileSystem.CONAFindNextFolder(hFindHandle, Buffer);
while (iResult == PCCSErrors.CONA_OK )
{
FolderInfo = (CONADefinitions.CONAPI_FOLDER_INFO2)Marshal.PtrToStructure(Buffer,typeof(CONADefinitions.CONAPI_FOLDER_INFO2));
//......................... i got an error msg here as follows:
// Error Messege:
FatalExecutionEngineError was detected Message: The runtime has encountered a
fatal error. The address of the error was at 0x7a0ba769, on thread 0x1294. The
error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe
or non-verifiable portions of user code. Common sources of this bug include
user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
how to use CONADefinitions.CONAPI_FOLDER_INFO2, coz when i use CONADefinitions.CONAPI_FOLDER_INFO it only gives me the name and lable of the device
but when is use CONADefinitions.CONAPI_FOLDER_INFO2 it gives me freeSize and TotalSize
please help
I'm not sure what that error means but if you want to get the drive's size, you can use
DriveInfo di = new DriveInfo("f"); //Put your mobile drive name
long totalBytes = di.TotalSize;
long freeBytes = di.TotalFreeSpace;
It is correct that you get the exception when you try and convert the data in the buffer to a different type of structure than was originally created by CONAFileSystem.CONAFindNextFolder.
You are trying to force a data structure of type CONADefinitions.CONAPI_FOLDER_INFO into a structure of type CONADefinitions.CONAPI_FOLDER_INFO2. They almost certainly have different lengths and so on so its extremely unlikely this method would ever work.
From experience with C++ development on the Symbian OS, the pattern Nokia are likely to be using here is one where they have subsequently developed a newer version of the API and so have created a newer version of the CONADefinitions.CONAPI_FOLDER_INFO structure (i.e. CONADefinitions.CONAPI_FOLDER_INFO2).
Assuming this is correct there are 3 likelihoods:
1) There is an enum parameter to the first function which specifies which version of the output structure is to be created.
2) There is a new function which returns the new structure e.g. CONAFileSystem.CONAFindFirstFolder2, CONAFileSystem.CONAFindNextFolder2
3) Nokia have developed the new version internally but not yet released it publicly.

Categories