Could not load file or assembly(dll file path+name) or one of its dependencies. An attempt was made to load a program with an incorrect format - powershell

When trying to perform-
Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'
through program, I am receiving below error:
Could not load file or assembly 'file:///C:\Program Files\Nimble
Storage\bin\Nimble.Powershell.dll' or one of its dependencies. An
attempt was made to load a program with an incorrect format.
The same works when ran directly from Powershell but in the above case, facing issue.
C# program used and have used statement:
Collection< PSObject > resultCollection = runspaceInvoke.Invoke("Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'", null, out errors);

EBGreen is right. Need to see your code bro. In absence of that, something like the following should work:
using System.Management.Automation;
using System.Management.Automation.Runspaces;
class foo {
static void Main(string[] args) {
InitialSessionState initial = InitialSessionState.CreateDefault();
initial.ImportPSModule(new string[] {"'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'"} );
...
}
}
Check out Creating an InitialSessionState for more information.

Related

Problem when I am running java code in the terminal in vs code

public class Main {
public static void main(String[] args) {
// System.out.println("Hello");
int a = 5,b=6;
int c = a+b;
System.out.println(c);
}
}
When I am running this code in vscode I am getting my desired result i.e. 11 but with that I am getting a huge address of a file in my local computer . Can somebody explain the reason behind that?
The output I am getting :-
k:; cd 'k:\JavaBasics'; & 'C:\Program Files\Java\jdk-11.0.10\New Folder\bin\java.exe' '-cp' 'C:\Users\khushal\AppData\Roaming\Code\User\workspaceStorage\a6084cec5acdec0bc4f5c4be0d94ed8a\redhat.java\jdt_ws\JavaBasics_22fbb3a7\bin' 'Main'
11
I am only expecting 11 but why the address of that file
That's the actual command that sending to the terminal. If you do not want to see them, you can update the setting java.debug.settings.console to internalConsole.
Note: If your program needs to consume user input, you still needs to use the integrated terminal. Internal console will not work for that case.

PowerShell 5 class: Import module needed for type

I have a written a PowerShell 5 class:
class ConnectionManager
{
# Public Properties
static [String] $SiteUrl
static [System.Management.Automation.PSCredential] $Credentials
static [SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection] $Connection
...
}
The type "SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection" is from a custom (installed module), named "SharePointPnPPowerShell2016"
My class is inside another module/file, called "connection.manager.psm1".
When I load this module to make use of this class, it returns me the following error:
> Import-Module connection.manager.psm1
At connection.manager.psm1:6 char:11
+ static [SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type
[SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection].
When I manually load the (PNP) module in the PowerShell session before loading my module it is loaded correctly and I can use it.
But I don't want to always have to manually load the other module first before I use my module. I tried to import the PNP-Module directly inside my module by adding:
Import-Module "SharePointPnPPowerShell2016"
at the beginning, before the class declaration, but it changes nothing, the error "Unable to find type" still appears.
Any ideas how to do this correctly?
I think you can fix this problem by using a module manifest
There is a "Required Module" and a "required Assembly" section you could use. This should handle loading the requirements (as long as they are installed) when you load your custom module, which holds the class.
If you have declared a class in a module, you cannot use it if you Import-Module; that only brings in cmdlets, functions, and aliases. Instead, your script should Using module the module; that will bring in the class as well as the other exported items.
(I actually misread the problem; this does not work to solve the querent's specific problem - but for a class that does not use classes from other modules, this will allow importing of classes from modules. The querent has found a known issue in PowerShell; see the comments for further information.)

Cudafy chapter 3 example has path issue how to fix?

Using Cudafy version 1.29, which can be downloaded from here
I am executing the examples that are found in the install folder CudafyV1.29\CudafyByExample\
Specifically, "chapter 3" example that begins line 42 of program.cs calls the following:
simple_kernel.Execute();
which is this:
public static void Execute()
{
CudafyModule km = CudafyTranslator.Cudafy(); // <--exception thrown!
GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
gpu.LoadModule(km);
gpu.Launch().thekernel(); // or gpu.Launch(1, 1, "kernel");
Console.WriteLine("Hello, World!");
}
The indicated line throws this exception:
Compilation error: CUDAFYSOURCETEMP.cu
'C:\Program' is not recognized as an internal or external command,
operable program or batch file. .
Which is immediately obvious that the path has spaces and the programmer did not double quote or use ~ to make it operational.
So, I did not write this code. And I cannot step through the sealed code contained within CudafyModule km = CudafyTranslator.Cudafy();In fact I don't even know the full path that is causing the exception, it is cut-off in the exception message.
Does anyone have a suggestion for how to fix this issue?
Update #1: I discovered where CUDAFYSOURCETEMP.cu lives on my computer, here it is:
C:\Users\humphrt\Desktop\Active Projects\Visual Studio
Projects\CudafyV1.29\CudafyByExample\bin\Debug
...I'm still trying to determine what the program is looking for along the path to 'C:\Program~'.
I was able to apply a workaround to bypass this issue. The workaround is to reinstall all components of cudafy in to folders with paths with no ' ' (spaces). My setup looks like the below screenshot. Notice that I also installed the CUDA TOOLKIT from NVIDIA in the same folder - also with no spaces in folder names.
I created a folder named "C:\CUDA" and installed all components within it, here is the folder structure:

How can I write the trace, console and error outputs into my XML report file?

I want the Trace, Console and Console Error outputs would be written into the common XML report file (for example into cad.UnitTests.xml). By default this info is not written in XML.
How can I do it? nunit-console.exe has such parameters:
/output=STR File to receive test output (Short format: /out=STR)
/err=STR File to receive test error output
But I need to get it in the same XML file. I need it for both cases: nunit-console.exe and nunit.exe. Also, I looked the settings of GUI NUnit but found nothing.
My BAT file has such content:
:: run_me.bat
:: © Andrey Bushman, 2015
ECHO OFF
CD /D %~dp0
SET file_name=cad.UnitTests
:: Run NUnit tests
call "%NUNIT%\nunit-console.exe" ^
/out="%~dp0%file_name%_out.txt" ^
/err="%~dp0%file_name%_err.txt" ^
/trace=Verbose ^
/noshadow ^
/xml="%~dp0%file_name%.xml" ^
"%~dp0%file_name%.dll"
:: Get the HTML report of the unit testing
call "%ReportUnit%\ReportUnit.exe" ^
"%~dp0%file_name%.xml" ^
"%~dp0%file_name%.html"
But even if I use such command:
call "%NUNIT%\nunit-console.exe" ^
/out="%~dp0%file_name%_out.txt" ^
/err="%~dp0%file_name%_err.txt" ^
/noshadow ^
/xml="%~dp0%file_name%.xml" ^
"%~dp0%file_name%.dll"
then the Trace output is absent in both files (the "%~dp0%file_name%_out.txt" and "%~dp0%file_name%_err.txt").
I don't see of nunit-console.exe option for Trace output redirection (something like /traceFile). I see the /trace parameter, but it has other purpose.
It is necessary for me, because I use the result XML for generation of HTML through the ReportUnit.exe. I want to see the detailed info in the HTML.
I can save the Trace output into TXT file in the code of my unit tests:
/* SetUpClass.cs
* © Andrey Bushman, 2015
*/
namespace Bushman.CAD.UnitTests {
using System;
using System.IO;
using System.Diagnostics;
using NUnit.Framework;
[SetUpFixture]
public class SetUpClass {
private TextWriterTraceListener listener = null;
[SetUp]
public void RunBeforeAnyTests() {
Stream traceFile = File.Create("trace_out.txt");
listener = new TextWriterTraceListener(traceFile);
Trace.Listeners.Add(listener);
}
[TearDown]
public void RunAfterAnyTests() {
listener.Flush();
}
}
}
But I still have a hope what I can to get this info in the XML file (which is generated by NUnit) through the "native" way of NUnit.

How to execute JMeter test case from Java code

How do I run a JMeter test case from Java code?
I have followed the example Here from Blazemeter.com
My code is as follows:
public class BasicSampler {
public static void main(String[] argv) throws Exception {
// JMeter Engine
StandardJMeterEngine jmeter = new StandardJMeterEngine();
// Initialize Properties, logging, locale, etc.
JMeterUtils.loadJMeterProperties("/home/stone/Workbench/automated-testing/apache-jmeter-2.11/bin/jmeter.properties");
JMeterUtils.setJMeterHome("/home/stone/Workbench/automated-testing/apache-jmeter-2.11");
JMeterUtils.initLogging();// you can comment this line out to see extra log messages of i.e. DEBUG level
JMeterUtils.initLocale();
// Initialize JMeter SaveService
SaveService.loadProperties();
// Load existing .jmx Test Plan
FileInputStream in = new FileInputStream("/home/stone/Workbench/automated-testing/apache-jmeter-2.11/bin/examples/CSVSample.jmx");
HashTree testPlanTree = SaveService.loadTree(in);
in.close();
// Run JMeter Test
jmeter.configure(testPlanTree);
jmeter.run();
}
}
but I keep getting the following messages in the console and my test never executes.
INFO 2014-09-23 12:04:40.492 [jmeter.e] (): Listeners will be started after enabling running version
INFO 2014-09-23 12:04:40.511 [jmeter.e] (): To revert to the earlier behaviour, define jmeterengine.startlistenerslater=false
I have also tried uncommented jmeterengine.startlistenerslater=false from jmeter.properties file
How do you know that your "test never executes"?
What is in jmeter.log file (it should be in the root of your project). Or alternatively comment JMeterUtils.initLogging() line to see the full output in STDOUT
Have you changed relative path CSVSample_user.csv in "Get user details" CSV Data Set Config as it may resolve into a different location as it recommended in Using CSV DATA SET CONFIG
Is CSVSample.jtl file generated anywhere (again it should be in the root of your project by default)? What is in it?
The code looks good and I'm pretty sure that the problem is with the path to CSVSample_user.csv file and you have something like java.io.FileNotFoundException in your log. Please double check that CSVSample.jmx file contains valid full path to CSVSample_user.csv.
UPDATE TO ANSWER QUESTIONS IN COMMENTS
jmeter.log file should be under your Eclipse workspace folder by default
Looking into CSVSample.jmx there is a View Resulst in Table listener which is configured to store results under ~/CSVSample.jtl
If you want to see summarizer messages and "classic" .jtl reporting add next few lines before jmeter.configure(testPlanTree); stanza
Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}
String logFile = "/path/to/jtl/results/file.jtl";
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
testPlanTree.add(testPlanTree.getArray()[0], logger);
Try using library - https://github.com/abstracta/jmeter-java-dsl.
It supports implementing JMeter test as java code.
Below example shows how to implement and execute test for REST API. Same approach could be applied to other type of tests as well.
#Test
public void testPerformance() throws IOException {
TestPlanStats stats = testPlan(
threadGroup(2, 10,
httpSampler("http://my.service")
.post("{\"name\": \"test\"}", Type.APPLICATION_JSON)
),
//this is just to log details of each request stats
jtlWriter("test" + Instant.now().toString().replace(":", "-") + ".jtl")
).run();
assertThat(stats.overall().elapsedTimePercentile99()).isLessThan(Duration.ofSeconds(5));
}