I have the following VBScript code in MyScript.vbs:
Dim myApp
Set myApp = GetObject(,"ViewDraw.Application")
I call it from a PowerShell command line, like so:
cscript MyScript.vbs //I
This works as expected; myApp is set to the process I'm looking for and I'm able to interact with it.
Here's some C# code that attempts to do the same thing:
var script = new Process();
script.StartInfo.FileName = "cscript";
script.StartInfo.Arguments = #"<MyWorkingFolder>\MyScript.vbs //I";
script.StartInfo.CreateNoWindow = true;
script.StartInfo.RedirectStandardOutput = true;
script.StartInfo.UseShellExecute = false;
script.Start();
//Read anything sent out by program
string output = script.StandardOutput.ReadToEnd();
script.WaitForExit();
VBScriptResult result = new VBScriptResult();
result.returnCode = script.ExitCode;
result.stdOut = output;
return result;
When I execute the C# code, the VBScript fails on the GetObject() call. There have been similar SO questions, and I've tried their suggestions. One suggestion was to explicitly call either the 32bit or 64bit version of cscript. Neither worked, however.
This hasn't always been an issue. The code is a couple of years old now and has worked in the past. It's possible that an update to Visual Studio 2017 somehow caused this problem. I'm currently running version 15.3.5.
I've been stuck on this issue for a week now, so any help is greatly appreciated!
The problem is with Visual Studio 2017, probably a result of taking update 15.3 or later. The same code works fine in VS 2015 Update 3.
Related
I'm developing asp.net core application + IronPython.
But I've faced with the debugging issue...
So for example I have following code:
Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
ScriptEngine engine = Python.CreateEngine(options);
// output redirect
var eIO = engine.Runtime.IO;
var errors = new MemoryStream();
eIO.SetErrorOutput(errors, Encoding.Default);
var result = new MemoryStream();
eIO.SetOutput(result, Encoding.Default);
// execute script
ScriptScope scope = engine.CreateScope();
scope.SetVariable("testGlobalVar", 10);
engine.ExecuteFile(ScriptPath, scope);
in python file
some = "Test"
print(Test)
print("We have ->", testGlobalVar)
It works fine, but I don't know how to set breakpoint in python file and debug it step by step in Visual Studio, Pycharm(whatever), when running it via C#.
I found this question but it's almost completely useless. I'm setting breakpoint in python file and nothing happens.
Since it works well without debug mode as you mentioned. I think the reason for why the breakpoint won't be hit in debug mode is debugger can't find it.
Please Go=>Debug=>Options=>Uncheck Enable Just My Code to check if it helps.
Note:
Set the .net core app as startup project
If the uncheck Enable Just My Code not help, I suggest you go tools->Import/Export Settings->reset all settings, then uncheck the Enable Just My Code again.
After that, the breakpoint can be hit like below:
In addition: I use the .net console app to reproduce and test, but I think it has similar behavior like web-app. Any update feel free to contact me :)
Just wondering if someone out there might have some insight to what's going wrong here...
I have a python script that connects to a USB-to-CAN transceiver/dongle (made by PEAK System) to do some CAN communications. The script works pretty flawlessly. The script accepts command-line arguments and works fine when called from the Windows command-line.
I am trying to integrate this script into a C# Forms project. I have been successful at calling the Python script from the C# app, but things fall apart when it gets to the point at which the Python script tries to use the CAN transceiver.
It feels like the C# app front-end is not allowing the Python script to access the serial port.
Here is the error I get (Python script writing to StandardOut on the Visual Studio output):
line 86, in canSendRec
self.bus.send(canMessage, timeout=0.1)
AttributeError: 'Node' object has no attribute 'bus'
Unable to Connect to USB-CAN Device
Here is the line from canSendRec -- where the exception handler came from (which we wrote):
try:
self.bus = can.interface.Bus('PCAN_USBBUS1',bitrate=1000000)
self.bus.flush_tx_buffer()
except:
print("Unable to Connect to USB-CAN Device")
Here is my C# code calling the Python script:
public string pythonMakeCall(string script, string arg1){
ProcessStartInfo pyProcessStartInfo = new ProcessStartInfo(py_path);
pyProcessStartInfo.FileName = py_path;
pyProcessStartInfo.Arguments = string.Format("{0} {1}", script, arg1);
pyProcessStartInfo.CreateNoWindow = true;
pyProcessStartInfo.UseShellExecute = false;
pyProcessStartInfo.RedirectStandardOutput = true;
pyProcessStartInfo.RedirectStandardError = true;
Process pyProcess = new Process();
pyProcess.StartInfo = pyProcessStartInfo;
pyProcess.Start();
retString = pyProcess.StandardOutput.ReadToEnd();
pyProcess.WaitForExit();
return retString;}
Like I said, it feels like there is something going on with the C# app not allowing Python to access the USB ports, but I'm not sure where to begin with debugging that hunch, since, Disclaimer: this is my first time dabbling in C#/Visual Studio and I'm no Python expert either.
I'm just dummy in using SSIS&*.dtsx files from C#. Now I have WindowsForms project and OnClick handler with this code:
.....
string pkgLocation;
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
DTSEvents dtsEvents=new DTSEvents();
pkgLocation = System.Windows.Forms.Application.StartupPath+ #"\" + #"3StreamsImport.dtsx";
app = new Microsoft.SqlServer.Dts.Runtime.Application();
app.PackagePassword = "abudfv";
app.EnableDump = true;
app.DumpOnAnyError = true;
pkg = app.LoadPackage(pkgLocation, dtsEvents,true);
try {
pkgResults = pkg.Execute(null,null,dtsEvents,null,null);
}catch(System.Runtime.InteropServices.COMException ex) {
Console.WriteLine(ex.StackTrace);
}
.......
"3Streamsimport.dtsx" file was created with SqlServer management studio for SqlServer 2016 and is working fine from standard Еxecute Package Utility. Loading package in my code passes fine too. But executing fails allways! dtsEvents is instanceof object that implements all from IDTSEvents interface.
Dear ALL, who can help with definitions of ways to solve the problem?
It's been a while since I tried, so I don't know if later versions have improved anything, but I was never able to get an SSIS package to execute from C# the way you are trying to do.
What I eventually did was create a job that executed the package, and used C# to start the job. It worked fine.
Solved! All C# code is fine. As addition I'm implemented IDTSLogging. After changing "exectute" call to
pkgResults = pkg.Execute(null,null,dtsEvents,new DTSLogging(),null);
all events are firing smoothly. I don'nt know/ why, but it is working.
Now about DTSX- file: It was my mistake in project and the proper copy was simply in other place! :-(
Sorry :-(
I have transitioned my test project from Visual Studio 2010 to 2015.
Execution of the tests in earlier version was fine since it was Mbunit. In the new version is used Nunit 3.4.1. I do not see any problem in my code. Whenever I want to run test I receive Message: No arguments were provided.
Here is the code of test that have worked fine with MbUnit
[Test]
[TestCaseId(456123)]
[Priority(PriorityLevel.Critical)]
public void ExpiredJobViewPageUi(string channel, SeleniumWebDriverDeviceType seleniumWebDriverDeviceType,string widgetType) {
TestRunner.RunTest(MethodBase.GetCurrentMethod(), channel, seleniumWebDriverDeviceType, webDriver => {
//Test body
ReportLog.WriteLine("Step 1 - Create new flow.");
var flow = new StandardFlowModel<JobModel>(channel, webDriver, ReportLog.WriteLine);
ReportLog.WriteLine("Step 2 - Go to .");
var expPage = flow.GoToExpirationPage(123);
expPage.WaitPageIsLoaded(10);
....
When I click on Run Selected Test in the Text Explorer in Visual Studio 2015 I got the message No arguments were provided.
Can anybody help me what is wrong? Even though there is no chance to set break point to figure out what is going on.
the problem was that I missed some input parameters in [] brackets. When I dig into TestRunner and debugged it I found that I need to specify [Combination("parm", SeleniumWebDriverDeviceType.Desktop, "Popular Articles")]
Thank you for your hints!
I am attempting to create a copy of an existing dtsx file so I can change a few variables based on input from the user. I am able to make a copy of the file, look at the variables, and set the variables to the correct input. However, when I go to look at the file in Visual Studio I get a few errors.
Microsoft Visual Studio is unable to load this document: The package failed to load to to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors". This occurs when CPackage::LoadFromXML fails.
The errors contained in the error list:
Error 3 Error loading test.dtsx: Error loading value "<DTS:Property xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:Name="PackageFormatVersion">6</DTS:Property>" from node "DTS:Property". E:\test.dtsx 1 1
The version number in the package is not valid. The version number cannot be greater than current version number.
I looked into these errors and I saw potential issues with the server year and visual studio year. Both of these are the 2008 version.
My code:
string pkgPath = #"\\server\TestFolder\test.dtsx"
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgPath, null);
Console.WriteLine(pkg.Variables["filename"].Value.ToString());
pkg.Variables["filename"].Value = "testFile";
Console.WriteLine(pkg.Variables["filename"].Value.ToString());
app.SaveToXml(pkgPath, pkg, null);
If I open the file I am using to make a copy of in Visual Studio, it works no problem -- something strange is happening when I do app.SaveToXML();
Any ideas or suggestion would be wonderful.
To run this as a process from DTEXEC, it would look something like below. Please check out these two links for further details about ProcessStartInfo and how to use /SET so you can add that to your argument. Test this from the command line first because the syntax can be finicky.
https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo(v=vs.110).aspx
https://technet.microsoft.com/en-us/library/ms162810(v=sql.105).aspx
Using System.Diagnostics;
string args = #"/F'c:\MyPackage.dtsx' /SET'\package.variables[myvariable].Value;myvalue'";
ProcessStartInfo executePackage = new ProcessStartInfo("dtexec", args);
executePackage.UseShellExecute = false;
executePackage.RedirectStandardError = true;
executePackage.RedirectStandardOutput = true;
executePackage.CreateNoWindow = true;
StringBuilder output = new StringBuilder();
Process executing = Process.Start(executePackage);
while(!executing.StandardOutput.EndOfStream)
{
output.AppendLine(executing.StandardOutput.ReadLine();
}
executing.WaitForExit():