Test driving a remote desktop feature in an app but keep getting a weird error with the server name I'm putting in.
Code:
rdp.Server = txtServer.Text;
rdp.UserName = txtUser.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = txtPass.Text;
rdp.Connect();
Keep getting the error:
An unhandled exception of type 'System.ArgumentException' occurred in AxInterop.MSTSCLib.dll
Additional information: Value does not fall within the expected range.
On line:
rdp.Server = txtServer.Text;
txtServer.Text is being input as (but with a real address):
123.456.789.10:1234
Anybody else had this issue?
EDIT
The issue is with the port in the address, how can I get around this?
There should be an .AdvancedSettings.RDPPort property where you can set the port. Look at this CodeProject article, specifically page 2 of the comments.
Related
I am collecting Resultant Set of Policies using the Group Policy Management dll. There exist a class GPRSop, which I use, with the attributes RsopMode and WMI Namspace as a string:
GPRsop test = new GPRsop(RsopMode.Logging, "Root/RSOP");
test.LoggingMode = LoggingMode.Computer;
test.LoggingComputer = "MyComputer";
test.LoggingUser = "domain\\user";
test.CreateQueryResults();
test.GenerateReportToFile(ReportType.Xml, "C:\\Temp\\test.xml");
LoggingMode, LoggingComputer and LoggingUser all throw the same exception:
System.ArgumentException: 'Value does not fall within the expected range.'
If I set the wmiNamespace " " as recommended, it also throws an exception.
I had to run Visual Studio as an administrator. After that I did not even need to provide a wmiNamespace.
Thanks for your help
At work I have encountered a problem with EvoPdf for DotNet client where it won't actually convert the html because of the following exception:
An error occured. Initialization failed: Insufficient data
The stack trace shows the following:
at am.aa()
at EvoPdf.HtmlToPdfClient.HtmlToPdfConverter.ConvertHtml(String html, String baseUrl)
at evoPdfTest.Program.Main(String[] args) in D:\git\evoPdfTest\evoPdfTest\Program.cs:line 32
This of course makes no sense, because in order to verify it wasn't anything I did, I decided to make a small console app as follows (also this same error occurs in their demo code as well.
var pdfConverter = new HtmlToPdfConverter(myIpString, myPort);
var paragraphHtml = $$"<!DOCTYPE html><html> <body> The content of the body element is displayed in your browser.</body></html> "";
pdfConverter.LicenseKey = myKey;
// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
pdfConverter.ConversionDelay = 2;
// set PDF page size
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
// set PDF page orientation
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
var pdfBytes = pdfConverter.ConvertHtml(paragraphHtml, null);
Where am I going wrong, and is this just a case of a superemly poorly written error message?
For anyone getting this error in the future:
An error occured. Initialization failed: Insufficient data
This occurs due to a mismatch in versions. In our case, we had an Azure Function running version 8.0.0 of the EvoPDF NuGet library and an Azure Cloud Application endpoint running version 7.5.0. Ensure that all services are running the same version.
I am trying to create and connect to a WLAN profile using Native WiFi (https://managedwifi.codeplex.com/). I am able to view all the Network BSS List and their parameters. However, when I am trying to create/overwrite a WLAN profile, I get the below mentioned error message (Error#1):
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in ManagedWifi.dll.
Additional information: The network connection profile is corrupted
However, when I created a profile normally from "Network and Sharing Center" of the Windows 7 control panel and then tried to connect using the ManagedWiFi, I get another error message(Error#2):
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Type 'NativeWifi.Wlan+WlanReasonCode' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
I noticed that this error occurs even if I try to connect/disconnect to a WLAN profile from the "Network and Sharing Center", with the windows application running in the background.
Here is the sample code that I am using:
Dim profileName As String = GlobalVariables.ssidname ' Provides the selected SSID name from the Network BSS List
Dim hexval As String = StringToHex(GlobalVariables.ssidname) ' Function to get the hexadecimal value for a provided string
Dim key As String = TextBox1.Text ' Security key from the textbook provided
Dim profileXml As String = String.Format("<?xml version=""1.0""?><WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", 'GlobalVariables.ssidname, hexval, TextBox1.Text)
wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, True) 'Error#1 occurs here
wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName) 'Error#2 occurs here
From the forum "Type Native Wifi.Wlan + WlanReasonCode cannot be marshaled error", the issue (Error#2) seems to be within the WlanAPI.cs, where there is a line of code that checks for the size of the return code. This is the line:
int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanReasonCode));
if (notifyData.dataSize >= expectedSize)
{
Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr);
if (wlanIface != null)
wlanIface.OnWlanReason(notifyData, reasonCode);
}
Changing the above code to the below seems to fix the issue.
//int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanReasonCode));
if (notifyData.dataSize >= 0)
{
Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr);
if (wlanIface != null)
wlanIface.OnWlanReason(notifyData, reasonCode);
}
However, I am not sure on how to add this fix to my solution. I installed the ManagedWiFi from the NuGet Package Manager. Hence, not sure how to change the WlanApi.cs file. Any help regarding the above mentioned two issues are much appreciated.
The issue (Error#1) is now resolved. The profilexml file format was different for me. Here is the profilexml after I changed it.
Dim profileXml As String = String.Format("<?xml version=""1.0""?><WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey></security></MSM></WLANProfile>", GlobalVariables.ssidname, hexval, TextBox1.Text)
Also the second issue (Error#2) was resolved when I uninstalled ManagedWiFi package from my solution and added the whole ManagedWiFi project to the solution. Then I made the change in WlanApi.cs as mentioned in SimpleWiFi Or Type Native Wifi.Wlan + WlanReasonCode cannot be marshaled error.
I had a simpler task (read the SSID of the connected network), which was throwing the same error.
I solved it by switching to using SimpleWiFi entirely and ignore the ManagedWifi package.
Glancing at the source code, it looks like SW is a fixed reimplementation of some of the functionality in MW.
I have problem with webdriver on IE9 (win7, c#, selenium 2.3). I get NoSuchWindowException exception.
I found that I need to change 'Enable Protected Mode' for all Security Level to the same value. But I don't want to change my settings generally and manually, just programmatically for time of testing. I thought that I've just need to set IntroduceInstabilityByIgnoringProtectedModeSettings to true and it will be working, but it doesn't. My code (these lines work ok):
var option = new InternetExplorerOptions();
option.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IWebDriver Driver = new InternetExplorerDriver(option);
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Driver.Navigate().GoToUrl(baseUrl);
This cause exception:
Driver.Manage().Window.Maximize();
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred in WebDriver.dll but was not handled in user code
Additional information: Error retrieving window with handle current
also this:
string pageSource = Driver.PageSource;
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to get browse
Do you have idea what is going wrong/what can I do to run my test?
Getting this exception The file size exceeds the limit allowed and cannot be saved when writing to event viewer using EventLog
Code used:
string cs = "LoggingService";
EventLog elog = new EventLog();
if (!EventLog.SourceExists(cs))
{
EventLog.CreateEventSource(cs, cs);
}
elog.Source = cs;
elog.EnableRaisingEvents = true;
elog.WriteEntry(message);
Stack trace:
System.ComponentModel.Win32Exception (0x80004005): The file size exceeds the limit allowed and cannot be saved
at System.Diagnostics.EventLogInternal.get_OldestEntryNumber()
at System.Diagnostics.EventLogInternal.StartRaisingEvents(String currentMachineName, String currentLogName)
at System.Diagnostics.EventLogInternal.set_EnableRaisingEvents(Boolean value)
Things tried:
http://support.microsoft.com/kb/328380#top
When I put this statement elog.Clear() before elog.EnableRaisingEvents = true;
I am getting different exception
System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Diagnostics.EventLogInternal.Clear()
The above code is executed by a web service which runs under LocalSystem which has full permission on the computer.
OS: windows server 2008R2 and .NET 4.0
There is a method EventLog.ModifyOverflowPolicy that modifies log policy.
I believe EventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded,0) could be helpful.
Event Viewer - Properties - Maximum log size was 1028. I bumped it and it started working fine.
But the same code was working from another window service before I made the above the change.
which make me think what could have happened
The message I was trying to log was just a line (less then 255 characters)