I am trying to write buffer data to SCSI device, but when I fire the deviceIoControl call, I get the windows error code 183. The error code indicates File already exits but I am not able to understand the error with respect to the IOCTL call.
The CreateFile function passed as i was able to get the appropriate device Handle as shown below.
int devHandle = DeviceIoControlHelper.CreateFile(
deviceName,
DeviceIoControlHelper.GENERIC_READ | DeviceIoControlHelper.GENERIC_WRITE,
DeviceIoControlHelper.FILE_SHARE_READ | DeviceIoControlHelper.FILE_SHARE_WRITE,
IntPtr.Zero,
DeviceIoControlHelper.OPEN_EXISTING,
0,
IntPtr.Zero);
However, when i try to write the buffer I get the error :
dwReturned = 0;
int b = DeviceIoControlHelper.DeviceIoControl(
devHandle,
DeviceIoControlHelper.IOCTL_SCSI_PASS_THROUGH,
inpBuffer,
(uint)Marshal.SizeOf(info),
inpBuffer, //out pDriveLayout,
(uint)Marshal.SizeOf(info), //(uint)Marshal.SizeOf(typeof(DRIVE_LAYOUT_INFORMATION_EX)),
out dwReturned,
IntPtr.Zero);
Log.Write(Log.TraceLevel_5,"ExecuteDeviceIoControl return pass_through scsistatus = " + info.spt.ScsiStatus);
if (b == 0)
{
int win_err = this.GetWindowsErrorCode();
Log.Write(Log.TraceLevel_5, "ExecuteDeviceIoControl failed, error = " + win_err);
LogMyTrace.Write(LogMyTrace.TraceLevel_5, "ExecuteDeviceIoControl failed, error = " + win_err);
this.CloseOpenHandle(devHandle);
Marshal.FreeHGlobal(inpBuffer);
throw new Exception("DeviceIoControl failed " + deviceName +
" is '" + deviceName + "'. Windows Err is " + win_err);
}
The error code is 183.
Please provide some inputs as why this error is being caused and the soultion.
I am using Windows 2008 R2 (x64) and it is the iSCSI path.
Related
My code (intended for searching for steam market items using an API call) is supposed to read the response from an API call into my program and this works great, however, when the API call fails I want to display a separate error message letting the user know that something has gone wrong but currently it will simply crash the code.
An example of a successful API call is:
https://steamcommunity.com/market/priceoverview/?currency=2&appid=730&market_hash_name=Glock-18%20%7C%20Steel%20Disruption%20%28Minimal%20Wear%29
This results in the following;
{"success":true,"lowest_price":"\u00a31.39","volume":"22","median_price":"\u00a31.40"}
So far this works perfectly fine, the problem arises when an incorrect link is used, like this:
https://steamcommunity.com/market/priceoverview/?currency=2&appid=730&market_hash_name=this-skin-does-not-exist
This results in an error like so;
{"success":false}
I want to know when this happens so I can display a message to the user however in my code's current state it simply crashes when this is returned. Here's my current code:
webpage = "https://steamcommunity.com/market/priceoverview/?currency=2&appid=730&market_hash_name=" + Model.category + Model.weapon + " | " + Model.skin + " (" + Model.wear + ")";
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData(webpage);
string webData = System.Text.Encoding.UTF8.GetString(raw);
if (webData.Substring(11, 1) == "t")
{
int lowestPos = webData.IndexOf("\"lowest_price\":\"");
int volumePos = webData.IndexOf("\",\"volume\":\"");
int medianPos = webData.IndexOf("\",\"median_price\":\"");
int endPos = webData.IndexOf("\"}");
Model.lowestPrice = webData.Substring(lowestPos + 16, volumePos - lowestPos - 16);
if (Model.lowestPrice.IndexOf("\\u00a3") != -1)
{
Model.lowestPrice = "£" + Model.lowestPrice.Substring(6);
}
Model.medianPrice = webData.Substring(medianPos + 18, endPos - medianPos - 18);
if (Model.medianPrice.IndexOf("\\u00a3") != -1)
{
Model.medianPrice = "£" + Model.medianPrice.Substring(6);
}
Model.volume = webData.Substring(volumePos + 12, medianPos - volumePos - 12);
}
else
{
Console.WriteLine("An error has occurred, please enter a correct skin");
}
The error occurs at byte[] raw = wc.DownloadData(webpage);
Any help would be appreciated :)
Webclient is deprecated and you should consider using HttpClient if possible. Webclient throws an exception. So you should wrap your code inside a try/catch block to catch the exception and react accordingly:
try
{
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData(webpage);
string webData = System.Text.Encoding.UTF8.GetString(raw);
}
catch(System.Net.WebException e)
{
//handle the error here
}
I'm attempting to monitor multiple SNMP agents (timeticks) with SnmpSharpNet across separate networks. The code below works with a single IP address, but when I try and connect to a second IP address the code fails, I'm trying to run this asynchronously but it appears that SnmpSharpNet won't allow me to receive data from more than one agent.
Is this the right way to approach this problem? Is there a better alternative to SmnpSharpNet?
community = new OctetString("public");
// Define agent parameters class
param = new AgentParameters(community);
// Set SNMP version to 1 (or 2)
param.Version = SnmpVersion.Ver1;
for (int i = 0; i < sendsqldatalist.Count(); i++)
{
agent = new IpAddress(sendsqldatalist[i].ip);
target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
// Make SNMP request
resultlist.Add(result = (SnmpV1Packet)target.Request(pdu, param));
// If result is null then agent didn't reply or we couldn't parse the reply.r
if (resultlist[i] != null)
{
// ErrorStatus other then 0 is an error returned by
// the Agent - see SnmpConstants for error definitions
if (resultlist[i].Pdu.ErrorStatus != 0)
{
Console.WriteLine("error on - " + sendsqldatalist[i].oid + " " + sendsqldatalist[i].ip);
// agent reported an error with the request
//- Error status found here http://www.docs.snmpsharpnet.com/docs-0-9-1/
MessageBox.Show("Error in SNMP reply from " + target.Address.ToString() + Environment.NewLine + "Error status " + result.Pdu.ErrorStatus.GetType() + Environment.NewLine + "Error Index " + result.Pdu.ErrorIndex.ToString(), "WARNING!");
}
else
{
Console.WriteLine("ConnectSNMP() CONNECTED - " + sendsqldatalist[i].oid + " - " + sendsqldatalist[i].ip);
}
}
}
Thanks in advance!
Developing a winforms C# 4.5 on Win10 that creates multiple AxWindowsMediaPlayer control objects dynamically on Form1 (the only form). Relative code segments look like this:
axWMPn[zi] = new AxWindowsMediaPlayer();
((ISupportInitialize)(axWMPn[zi])).BeginInit();
axWMPn[zi].Name = "Zone " + zi; //Zone name + index
axWMPn[zi].Tag = "Z" + zi; // "Z" + Zone index
axWMPn[zi].Location = loc;
axWMPn[zi].Size = sz;
Controls.Add(axWMPn[zi]);
((ISupportInitialize)(axWMPn[zi])).EndInit();
axWMPn[zi].uiMode = "none";
axWmpDisplayZones.Add(axWMPn[zi].Tag.ToString(), axWMPn[zi]);
axWMPn[zi].StatusChange += axWMPx_StatusChange;
axWMPn[zi].PlayStateChange += axWMPx_PlayStateChange;
I create 6 zones - 3 are assigned static JPEG images and the other 3 are used for video (*.avi and *.mov). The video files are assigned like this:
private void playVideo(string file)
{
int tc6 = 0;
axWMPn[0].URL = file;
axWMPn[4].URL = file;
axWMPn[5].URL = file;
axWMPn[6].URL = "C:/test/AmexDonut.mov";
}
This all works - playVideo is called from another process and the first time all videos run without errors; however when I call playVideo a second time I intermittently get a COMException error:
Exception thrown: 'System.Runtime.InteropServices.COMException' in AxInterop.WMPLib.dll -- Message: The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)).
Notes:
1. If I just do 2 axWMPn[x].URL=file it always works no COMException; if I had a third axWMPn[x].URL=file it mostly works with a COMException once every few dozen calls to playVideo. Adding the 4th awWMPn[x].URL=file almost always causes the COMException but not every single time.
So I did following to see more about what was going on:
private void playVideo(string file)
{
int tc6 = 0;
try
{
axWMPn[0].URL = file;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
Console.WriteLine("playVideo COMException 0: " + comEx.Source + " -- " + comEx.Message);
}
try
{
axWMPn[4].URL = file;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
Console.WriteLine("playVideo COMException 4: " + comEx.Source + " -- " + comEx.Message);
}
try
{
axWMPn[5].URL = file;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
Console.WriteLine("playVideo COMException 5: " + comEx.Source + " -- " + comEx.Message);
}
Again:
try
{
axWMPn[6].URL = "C:/test/AmexDonut.mov";
}
catch (System.Runtime.InteropServices.COMException comEx)
{
tc6++;
Console.WriteLine("playVideo COMException 6: try again count = " + tc6 + " - " + comEx.Source + " -- " + comEx.Message);
goto Again;
}
The COMException "busy" when it occurs always occurs in axWMPn[6].URL=file and putting the goto Again in works - tc6 will always just be 1. So merely trying one more time to assign axWMPn[6].URL=file always works. It never takes more than 1 additional try (tc6 never goes beyond 1).
I could leave it this way - I have run it dozens of times and it works just fine; but it sure seems like a bad hack. Does anybody have any thoughts or ideas?
Thanks for any input
System.NotSupportedException: Specified method is not supported
I'm getting this error sometimes while calling Start method of captureSource to record video on windows phone 8.
Below is my code :
if (captureSource.VideoCaptureDevice != null
&& captureSource.State == CaptureState.Started)
{
captureSource.Stop();
//UpdateUI(ButtonState.Recording, "Initializing...");
//Create Dir If Not Exist
if (!IsolatedStorageFile.GetUserStoreForApplication().DirectoryExists(FileLocation))
IsolatedStorageFile.GetUserStoreForApplication().CreateDirectory(FileLocation);
DateTime theDate = DateTime.Now;
isoVideoFileName = theDate.ToString("yyyyMMdd") + "_" + theDate.ToString("HHmmss") + "_" + "Video" + "." + GlobalDTO.VideoFormat;
// Connect the input and output of fileSink.
captureSource = new CaptureSource();
captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed);
captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted;
fileSink.CaptureSource = captureSource;
fileSink.IsolatedStorageFileName = FileLocation + isoVideoFileName;
}
// Begin recording.
if (captureSource.VideoCaptureDevice != null
&& captureSource.State == CaptureState.Stopped)
{
videoRecorderBrush.SetSource(captureSource);
captureSource.Start();
captureSource.CaptureImageAsync();
}
// Set the button states and the message.
UpdateUI(ButtonState.Recording, "Recording...");
That feature may not be supported on all phones?
That maybe why you are getting that exception. you should catch the exception and handle it in an appropriate way to inform the user the functionality is not supported.
I'm having a problem with this query below. I'm connecting to OrientDB using the C# driver and running the query in my c# code. All this code is in a loop and the queries in the try block works for a number of iterations and afterwards fails throwing a FormatException. At the point it fails I copy out the query and run it in the orientDB web interface and it returns the expect records so I'm sure it's not the input. So I'm so confused as to why it succeeds sometimes and fails at other times even when the input string is correct. Has anyone encountered a similar problem? Someone please help.
string origin = route[i].Trim();
string destination = route[i + 1].Trim();
List<ODocument> document = new List<ODocument>();
try
{
document = database.Query("select from (traverse out_Connects from " + origin + ") where in = " + destination);
//document = database.Query("select from Connects where (out = " + origin + " and in = " + destination + ")");
}
catch (Exception e)
{
//document = database.Query("select from Connects where (out = " + origin + " and in = " + destination + ")");
}