Powershell v2 - The correct way to load an assembly as part of a module - module

I have a Powershell (v2.0) script that I am working on.
One of the first things it does is loads a Module (runMySQLQuery.psm1) which includes (amongst other bits) a function to connect to a MySQL Database.
Import-Module runMySQLQuery.psm1
However, this requires that an assembly MySQL.Data.DLL is loaded in order for this to work.
If I place the line:
[void][system.reflection.Assembly]::LoadFrom("C:\PowerShell\modules\runMySQLQuery\MySql.Data.dll")
at the top of my script (separate to the Import-Module entry), then the whole thing works fine.
But I want to be able to load this assembly at the same time as the module, so that I don't have to worry about forgetting to including the assembly each time I use this module.
I tried placing it at the top of the .psm1 file, but that didn't work.
I then added it to my manifest file as:
RequiredAssemblies = #("C:\PowerShell\modules\runMySQLQuery\MySql.Data.dll")
This also didn't work.
Am I missing something here, is there a proper way to include assemblies as part of a module?
n.b. the error I get when it hasn't loaded properly is:
You cannot call a method on a null-valued expression

Can you just try to assign a varialbe a the beginig of you module :
$dumy = [system.reflection.Assembly]::LoadFrom("C:\PowerShell\modules\runMySQLQuery\MySql.Data.dll")

Related

Undefined global variable when using QuestaSim

I have a variable defined in foo_const.v which is defined like this in foo_const.v:
localparam NUM_BITS = 32;
Then I have another file foo_const_slice.v which does this:
localparam SLICE_ADDR_BITS = NUM_BITS;
This compiles fine with the vcs command:
vcs -sverilog foo_const.v foo_const_slice.v
But when I try to use QuestaSim:
vlog -work work -sv foo_const.v foo_const_slice.v
I get the following error message:
** Error: foo_const_slice.v(46): (vlog-2730) Undefined variable: 'NUM_BITS'.
The problem is that by default, each file that vlog compiles goes into a separate compilation unit, just like C/C++ and many other languages. By default, vcs concatenates all files together into a single compilation unit.
Although there is a way to change the default (you can look it up in the user manual), the proper way to code this is to put your parameters in a package, and import the package where needed.
Dave

Compiling and Llnking to used modules in external directory Compaq Fortran command prompt

I've already asked a similar question, here:
Linking to modules in external directory Compaq Visual Fortran command prompt
And I thought that the first answer was correct (that is, in the manual they say you can simply specify the path name before the module), but after deleting the temporary files in my library folder, this approach seemed to stop working. Trying with the /include[:path] approach, here is my .bat file:
df /include:..\FORTRAN_LIB\ __constants
myIO griddata_mod myfdgen myDiff magneticField /exe:magneticField
And an error is returned saying:
__constants
myIO
griddata_mod
myfdgen
myDiff
magneticField
f90: Severe: No such file or directory
... file is '__constants'
Again, I apologize that this question is VERY specific, but it seems like it should be simple and does not work at all.
p.s. Originally, I was using:
df ..\FORTRAN_LIB\__constants ..\FORTRAN_LIB\myIO
..\FORTRAN_LIB\griddata_mod ..\FORTRAN_LIB\myfdgen
..\FORTRAN_LIB\myDiff magneticField /exe:magneticField
But, as I've said, it stopped working after I deleted the temporary files in my FORTRAN_LIB folder. Also note, these .bat files used only one line, I've broken them into several lines just for readability. I would prefer using the /include[:path] option since that seems like a better solution.
Okay, so I think I figured out a workaround at the very least. I understood that the /include[:dir] specifies to search in "dir" for included files. But it seemed from documentation, that this also specifies to search for USEd modules but that doesn't seem to be the case.
My program now looks like this:
include '..\FORTRAN_LIB\__constants.f90'
include '..\FORTRAN_LIB\computeError.f90'
include '..\FORTRAN_LIB\griddata_mod.f90'
include '..\FORTRAN_LIB\myfdgen.f90'
include '..\FORTRAN_LIB\myDiff.f90'
include '..\FORTRAN_LIB\myIO.f90'
program magneticField
use constants
use computeError_mod
use griddata_mod
use myfdgen_mod
use myDiff_mod
use myIO_mod
implicit none
...
And my DF command like this:
df magneticField /exe:magneticField
And everything seems to work fine. It would be nicer to have the /include[:dir] option, but so long I'm able to reach in a separate directory, I'm satisfied. If anyone can find a better solution I'll switch the checkmark. I hope this helps with anyone else who was confused like me.

ActiveX component can't create object: 'jsShell.Ops' - but works via Editor

I have following problem. I would like to use jsShell.dll (Link to dll and description) in my project. I use Win7 64 bit.
I downloaded dll and put it in C:\Windows\system\jsshell (files jsShell.dll and khook.dll)
I succesfully registered dll using c:\Windows\SysWOW64> regsvr32.exe c:\Windows\system\jsshell\jsShell.dll (it is not needed to register khook.dll)
Then I tried to run test file jsshell\jsShell DLL\demo scripts\window.vbs which is part of jsShell.zip by:
a) double click to window.vbs and getting following error:
SCRIPT: C:\Users\joe\Downloads\jsshell\jsShell DLL\demoscripts\windows.vbs
LINE: 6
CHAR: 3
ERROR: ActiveX component can't create object: 'jsShell.Ops'
CODE: 800A01AD
SOURCE: Microsoft VBScript runtime error
This is the line with error: Set jsS = CreateObject("jsShell.Ops")
b) loading in WEB-ED Editor (Link to WEB-EDD) and running script over via editor, which works perfectly.
Could somebody please explain me, where is the difference between (a) and (b)? And what have to be done in order to run my script using (a) variant?
Thx a lot

MsTest, DataSourceAttribute - how to get it working with a runtime generated file?

for some test I need to run a data driven test with a configuration that is generated (via reflection) in the ClassInitialize method (by using reflection). I tried out everything, but I just can not get the data source properly set up.
The test takes a list of classes in a csv file (one line per class) and then will test that the mappings to the database work out well (i.e. try to get one item from the database for every entity, which will throw an exception when the table structure does not match).
The testmethod is:
[DataSource(
"Microsoft.VisualStudio.TestTools.DataSource.CSV",
"|DataDirectory|\\EntityMappingsTests.Types.csv",
"EntityMappingsTests.Types#csv",
DataAccessMethod.Sequential)
]
[TestMethod()]
public void TestMappings () {
Obviously the file is EntityMappingsTests.Types.csv. It should be in the DataDirectory.
Now, in the Initialize method (marked with ClassInitialize) I put that together and then try to write it.
WHERE should I write it to? WHERE IS THE DataDirectory?
I tried:
File.WriteAllText(context.TestDeploymentDir + "\\EntityMappingsTests.Types.csv", types.ToString());
File.WriteAllText("EntityMappingsTests.Types.csv", types.ToString());
Both result in "the unit test adapter failed to connect to the data source or read the data". More exact:
Error details: The Microsoft Jet database engine could not find the
object 'EntityMappingsTests.Types.csv'. Make sure the object exists
and that you spell its name and the path name correctly.
So where should I put that file?
I also tried just writing it to the current directory and taking out the DataDirectory part - same result. Sadly, there is limited debugging support here.
Please use the ProcessMonitor tool from technet.microsoft.com/en-us/sysinternals/bb896645. Put a filter on MSTest.exe or the associate qtagent32.exe and find out what locations it is trying to load from and at what point in time in the test loading process. Then please provide an update on those details here .
After you add the CSV file to your VS project, you need to open the properties for it. Set the Property "Copy To Output Directory" to "Copy Always". The DataDirectory defaults to the location of the compiled executable, which runs from the output directory so it will find it there.

extra-paths not added to python path with zc.recipe.testrunner

I am trying to run tests by adding a version of tornado downloaded from github.com in the sys.path.
[tests]
recipe = zc.recipe.testrunner
extra-paths = ${buildout:directory}/parts/tornado/
defaults = ['--auto-color', '--auto-progress', '-v']
But when I run bin/tests I get the following error :
ImportError: No module named tornado
Am I not understanding how to use extra-paths ?
Martin
Have you tried looking into generated bin/tests script if it contains your path? It will tell definitely if your buildout.cfg is correct or not. Maybe problem is elsewhere. Because it seem that your code is ok.
If you happen to regularly include various branches from git/mercurial or elsewhere to buildout, you might be interested in mr.developer. mr.developer can download and add package to develop =. You wont need to set extra-path in every section.