I'm trying to do some simple data retrieval with C# and Directory Services, but for some reason it doesn't work on any XP machines. If I run my code on a Server 2003 machine, there are no problems. I've spent a fair bit of time trying to find out if maybe there's some redistributable I need on XP or if the functionality simply isn't there, but I've found references to other developers who have similar code working under XP. If anyone has any experience or advice to share, I'd appreciate it.
A simple code snippet that's crashing for me:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.DirectoryServices;
namespace IIS_Site_Query_Tool
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
foreach (DirectoryEntry Site in W3SVC.Children)
{
//Do some data processing
}
}
}
}
Running this under XP gives me the folowing error with an HRESULT of -2147463168:
System.Runtime.InteropServices.COMException was unhandled
Message="Unknown error (0x80005000)"
Source="System.DirectoryServices"
ErrorCode=-2147463168
StackTrace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
at System.DirectoryServices.DirectoryEntries.GetEnumerator()
...
Googling the various pieces of information in the error lead me to think that it's a pretty generic COM interop error, and I'm out of ideas at this point. Any help is appreciated!
Based on the stack trace and reflector it looks like a call to ADsOpenObject is returning E_ADS_BAD_PATHNAME. This error indicates that the path you supplied to the DirectoryEntry class is not valid on the current machine.
If IIS is installed, then it's possible that the IIS provider is not properly installed on your machine.
See this SO question for more details: ADSI will not connect to IIS from XP Workstation
Installing IIS fixed it. I hadn't encountered ADSI before writing this little utility, so I didn't realize that software could install their own chunks of ADSI functionality. Thanks for the help!
Related
I want to connect to an OKUMA Windows based control from external PC (i.e. Other than OKUMA controller) and utilize the OKUMA Open API on that machine. Is it possible? (If yes then How?)
Below is my code which I want to run from my laptop to check machine running mode. I'm getting errors because Okuma.CLDATAPI can't run on my local PC :
using Okuma.CLDATAPI.Enumerations; // Part of the API on the machine
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OKUMA_TRIAL
{
public partial class Form1 : Form
{
Okuma.CLDATAPI.DataAPI.CMachine objCMachine;
public Form1()
{
InitializeComponent();
objCMachine = new Okuma.CLDATAPI.DataAPI.CMachine();
objCMachine.Init();
}
private ExecutionModeEnum fnGetRunMode()
{
return objCMachine.GetExecutionMode();
}
private void btnRead_Click(object sender, EventArgs e)
{
txtRunMode.Text = fnGetRunMode().ToString();
}
}
}
If this isn't possible, is there another way to communicate with the machine?
Use Windows Communication Foundation to wrap the API.
Due to popular demand, the Open API SDK now includes a WCF client / service example.
OkumaAmerica/Open-API-SDK/Examples/WCF/
It is important to note that we do not feel comfortable releasing code of a publicly available service with API access, so this example is configured for local-host only. Of course it is trivial to change the configuration, but whomever does so needs to accept all responsibility for doing so.
Microsoft has actually done a good job of documenting WCF features, see below.
Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4
Sample Code
Documentation
I'm attempting to use ArduinoDriver (through NU-Get) to connect to my Arduino Uno R3 in Visual Studio (in C#). This is the code I'm attempting to run:
using ArduinoUploader;
using ArduinoUploader.Hardware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArduinoDriver.SerialProtocol;
using System.Threading;
using ArduinoDriver;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var driver = new ArduinoDriver.ArduinoDriver(ArduinoModel.UnoR3, "COM3", true);
driver.Send(new DigitalWriteRequest(13, ArduinoDriver.DigitalValue.Low));
driver.Send(new DigitalWriteRequest(13, ArduinoDriver.DigitalValue.High));
Console.WriteLine("doing it!");
}
}
}
The code compiles correctly. However I'm getting an exception at runtime on line 18 (the new Driver Instantiation) in the form of:
System.MissingMethodException: 'Method not found: 'Void ArduinoUploader.ArduinoSketchUploader..ctor(ArduinoUploader.ArduinoSketchUploaderOptions)'.'
I have checked and double-checked the package and dependencies and they are all installed and up to date.
I have also tried both false and true for the AutoBootstrap option in the Arduino Driver Constructor. When it is set to true, the results are as above. When set to false I receive the following exception instead:
System.IO.IOException: 'Unable to get a handshake ACK when sending a handshake request to the Arduino on port COM3. Pass 'true' for optional parameter autoBootStrap in one of the ArduinoDriver constructors to automatically configure the Arduino (please note: this will overwrite the existing sketch on the Arduino).'
I should also point out that I have checked the port for the Arduino and it is definitely connected to COM3 (tested and working in the Arduino I.D.E).
Finally on running the script in Visual Studio, the Arduino flashes its lights in the way that it normally would when a successful upload is in progress. However it hangs for a couple of seconds at the driver instantiation and then puts out the exceptions.
If anyone out there can shed some light on this that would be amazing, I have googled like crazy and have not found any tutorials or other people dealing with this issue. Please let me know if any further info is required.
Cheers!
Using Windows 10 Bootcamped (Mac)
I got the same MissingMethodExeption. I synchronized the packages ArduinoDriver and ArduinoUploader (i.e. in my case downgrading the ArduinoUploader form v3.0.0 to v2.4.5) using the NuGet package manager.
This solved the issue for now...
I copped a tumbleweed badge on this one, so I think I have discovered my own answer; which is to use visual micro, and never speak of Arduino Driver again.
cheers!
I am working with VS C# to manipulate test cases, create projects, and anything else that's beneficial to my testing in TFS. However, there are not any solid examples out there. The API that is on the Microsoft Developer site is just not helpful to me (could be my lack of experience in coding in VS), but I am becoming frustrated. Any progress that I make takes several days ( ... really hit and miss). Can someone direct me to a consolidated resource for using the team foundation server object model to implement features programmatically: WebSites, Books, etc...? Thanks!!! Below is what appears to be very straightforward code to create a Default collection/Project and write a test case in VSO TFS with C# (It continues to fail):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace myProject
{
class Program
{
static void Main(string[] args)
{
string serverurl = "http://localhost:8080/tfs";
string project = "Beta1";
ITestManagementTeamProject proj = GetProject(serverurl, project);
ITestCase tc = proj.TestCases.Create();
tc.Title = "Test";
tc.Save();
Console.WriteLine("TC: {0}", tc.Id);
}
static ITestManagementTeamProject GetProject(string serverUrl,
string project)
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullQualifiedUriForName(serverUrl));
ITestManagementService tms = tfs.GetService<ITestManagementService>();
return tms.GetTeamProject(project);
}
}
}
The serverul "http://localhost:8080/tfs" in your code snippet means you are handling with on-premise TFS. But in your description, you want to create a test case work item in Visual Studio Online.
For Visual Studio Online api, you can refer to Visual Studio Online REST API at website:
https://www.visualstudio.com/en-us/integrate/api/overview
For deal with on-premise TFS programmatically, you can refer to blogs below:
http://joymonscode.blogspot.in/2009/05/beginning-tfs-programming.html
http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx
I'm developing a proof of concept web application: A web page with a button that opens the Word Application installed on the user's PC.
I'm stuck with a C# project in Visual Studio 2008 Express (Windows XP client, LAMP server). I've followed the Writing an ActiveX Control in .NET tutorial and after some tuning it worked fine. Then I added my button for opening Word.
The problem is that I can reference the Microsoft.Office.Interop.Word from the project, but I'm not able to access it from the web page. The error says "That assembly does not allow partially trusted callers".
I've read a lot about security in .NET, but I'm totally lost now. Disclaimer: I'm into .NET since 4 days ago.
I've tried to work around this issue but I cannot see the light!!
I don't even know if it will ever be possible!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using System.IO;
using System.Security.Permissions;
using System.Security;
[assembly: AllowPartiallyTrustedCallers]
namespace OfficeAutomation
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void openWord_Click(object sender, EventArgs e)
{
try
{
Word.Application Word_App = null;
Word_App = new Word.Application();
Word_App.Visible = true;
}
catch (Exception exc)
{
MessageBox.Show("Can't open Word application (" + exc.ToString() + ")");
}
}
}
}
Using .Net Framework 4 + XBAP makes this easy: You could use WPF XBAP instead of ActiveX.
And on Project settings window do:
Signing: unckeck all boxes. (this project does not need to be signed),
under Security tab, Just change it to Full Trust.
The user will be prompted one time if he wants to allow the application to Run.
The post How to provide extra trust for an Internet Explorer hosted assembly in the .NET Security Blog sheds light on the issue. It's dated 2003 so things could have changed now... I don't know.
But a commenter asked (2006)
Is it possible to execute the .net
assembly with all the trust permission
without changing anything on the
client side? We previously have been
using a signed ActiveX in a CAB that
was working fine, and try to port it
to C#.
And Shawnfa answered
No, it is not currently possible to
elevate your permissions on the client
side for a control. The closest
option is ClickOnce which will allow
you to prompt and elevate an
application -- although this
application will not be hosed in the
web page.
Is there something I need to do to get System.Net working with Microsoft Visual C# 2008 Express Edition? I can't seem to get any web type controls or classes to work at all.. the below WebClient example always throws the exception "Unable to connect to the remote server".. and consequently I can't get the WebBrowser control to load a page either.
Here is the code (Edited):
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
using (WebClient client = new WebClient()) {
string s = client.DownloadString("http://www.google.com");
this.textBox1.Text = s;
}
}
}
}
This is in a simple form with only a textbox control (with multiline set to true) in it. The exception gets thrown on the DownloadString(...) line. I also tried using WebRequest.. same exception!
EDIT:
I am connected to a Linksys WRT54G Router that connects directly to my cable modem. I am not behind a proxy server, although I did run proxycfg -u and I got:
Updated proxy settings
Current WinHTTP proxy settings under:
HKEY_LOCAL_MACHINE\
SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\
WinHttpSettings :
Direct access (no proxy server).
I am using Windows XP and not running any kind of firewall. Only AVG at the moment. I'm pretty sure I shouldn't have to forward any ports or anything, but I did try forwarding port 80 to my workstation on my router. Didn't help.
(update - I meant proxycfg, not httpcfg; proxycfg -u will do the import)
First, there is nothing special about "express" here. Second, contoso is a dummy url.
What OS are you on? And do you go through a proxy server? If so, you might need to configure the OS's http stack - proxycfg will do the job on XP, and can be used to import the user's IE settings.
The sample is fine, although it doesn't correctly handle the multiple IDisposable objects - the following is much simpler:
using (WebClient client = new WebClient()) {
string s = client.DownloadString("http://www.google.com");
// do something with s
}
Do you have any firewall software on your PC that might be affecting it? Have you tried with any sites other than Google?