Page 1 of 1

IWshRuntimeLibrary Error

Posted: Thu Sep 29, 2011 7:50 pm
by costamesakid
I pulled a solution using Subversion from a different branch that was developed on another PC. The solution runs fine on other machines but when I try to run a specific recording I get the following error:
Could not load file or assembly 'Interop.IWshRuntimeLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
The specific code being referenced is below. Any ideas what the problem is? Thanks

Code: Select all

		/*
		 * Launch Desktop shortcuts by name 'appName'
		 */
		[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
        private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);
		
		public void LaunchShortcut(string appName)
		{
        	//Get the public desktop
        	const int MAX_PATH = 260;
        	const int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019;
            StringBuilder sbPath = new StringBuilder(MAX_PATH);
            SHGetFolderPath(IntPtr.Zero, CSIDL_COMMON_DESKTOPDIRECTORY, IntPtr.Zero, 0, sbPath);
            string strDesktop = sbPath.ToString() + "\\" + appName + ".lnk";
	        			
	        //Start a process that will launch the shortcut
	        //This is not creating a short cut, its actually, opening the shortcut
			WshShell Wshell = new WshShell();
            IWshRuntimeLibrary.IWshShortcut shortc = (IWshRuntimeLibrary.IWshShortcut)Wshell.CreateShortcut(strDesktop);
            if(shortc!=null)
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents=false;
                proc.StartInfo.FileName=(string)shortc.TargetPath;
                proc.StartInfo.Arguments = (string)shortc.Arguments;
                proc.StartInfo.WorkingDirectory = (string)shortc.WorkingDirectory;
                proc.Start();
            }
		}

Re: IWshRuntimeLibrary Error

Posted: Fri Sep 30, 2011 10:43 am
by Support Team
Hi,

It seems that on the other machine is a newer version of the Interop.IWshRuntimeLibrary than on yours. Have you checked the version of your Interop.IWshRuntimeLibrary?

Regards,
Peter
Ranorex Team

Re: IWshRuntimeLibrary Error

Posted: Fri Sep 30, 2011 4:18 pm
by costamesakid
After typing 'CScript' at a command prompt I determined my local PC is running Windows Script Host 5.8. As far as I can tell thats the latest version. Do you know of a newer version? Thanks

Re: IWshRuntimeLibrary Error

Posted: Mon Oct 03, 2011 2:28 pm
by Support Team
Hi,

What Peter supposed was that the machine on which the assembly/project was created uses another version, so you have to use the same version as the other machine.
Can you check if the other machine uses a different one?
This does not necessarily mean that you have to install the newest one.
But 5.8 should be the newest version.

Regards,
Markus
Ranorex Support Team

Re: IWshRuntimeLibrary Error

Posted: Mon Oct 03, 2011 7:51 pm
by costamesakid
Im sure the other machine uses another version, you would think a recompile would alleviate this error. What is the best way to get past this error? Do I have to find the version of the other machines dll then uninstall my dll and reinstall the older version?

Re: IWshRuntimeLibrary Error

Posted: Mon Oct 03, 2011 10:27 pm
by costamesakid
From what I can tell the original script was recorded on a Windows XP machine, while my local machine is running Windows 7. When I pull the code onto a Windows XP machine I do not see the error message. It only occurs on my Windows 7 machine. I really thought these recordings could be run across multiple Windows platforms. Any idea how to fix this Windows Script Host issue, as it it is really holding me up? Thanks

Re: IWshRuntimeLibrary Error

Posted: Tue Oct 04, 2011 1:05 pm
by Support Team
Hi,
I really thought these recordings could be run across multiple Windows platforms
This is of course the case, but if you build a project with for instance Ranorex 3.X and you want to execute it on a machine with 2.X it won't work, because you have to install the same versions of your software.
I think that's the same with WSH, you are using two different versions of it and this causes the error, you can check this if you just call the appropriate code without any Ranorex functions.
You have to use the same/compatible version of the library on the two systems.
So which version is in use on the XP machine?

Regards,
Markus
Ranorex Support Team

Re: IWshRuntimeLibrary Error

Posted: Tue Oct 04, 2011 3:41 pm
by costamesakid
The XP machine is using 5.6.

Im looking to download 5.6 but its not available for Windows 7, so what are my options? Thanks

Re: IWshRuntimeLibrary Error

Posted: Tue Oct 04, 2011 9:58 pm
by costamesakid
5.6 as in Windows Script Host 5.6 which is what XP uses. Windows 7 uses 5.8 so Im not sure what can be done. Thanks

Re: IWshRuntimeLibrary Error

Posted: Wed Oct 05, 2011 8:59 am
by sdaly
Out of curiosity, is there a reason why you have to do this through code yourself?

Re: IWshRuntimeLibrary Error

Posted: Wed Oct 05, 2011 9:12 am
by Support Team
Hi,
costamesakid wrote:5.6 as in Windows Script Host 5.6 which is what XP uses. Windows 7 uses 5.8 so Im not sure what can be done. Thanks
Could it be that you've installed .Net Framework 4 Extended on your Windows 7 machine and on the Win XP machine only the .Net 2.0/3.5 Framework is installed? This could be too one possible reason why you get this error message. Please install also the .Net 4.0 Framework on the Windows XP machine or build your project on the Windows 7 machine against the .Net 2.0 Framework.

Regards,
Peter
Ranorex Team

Re: IWshRuntimeLibrary Error

Posted: Thu Oct 06, 2011 4:42 pm
by costamesakid
Please define 'Build Against'

Does that mean set the Target Framework to 2.0 in the Project Properties Window? Because I have already tried that and the outcome is the same