IWshRuntimeLibrary Error

Ask general questions here.
costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

IWshRuntimeLibrary Error

Post by costamesakid » Thu Sep 29, 2011 7:50 pm

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();
            }
		}

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: IWshRuntimeLibrary Error

Post by Support Team » Fri Sep 30, 2011 10:43 am

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

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: IWshRuntimeLibrary Error

Post by costamesakid » Fri Sep 30, 2011 4:18 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: IWshRuntimeLibrary Error

Post by Support Team » Mon Oct 03, 2011 2:28 pm

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

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: IWshRuntimeLibrary Error

Post by costamesakid » Mon Oct 03, 2011 7:51 pm

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?

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: IWshRuntimeLibrary Error

Post by costamesakid » Mon Oct 03, 2011 10:27 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: IWshRuntimeLibrary Error

Post by Support Team » Tue Oct 04, 2011 1:05 pm

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

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: IWshRuntimeLibrary Error

Post by costamesakid » Tue Oct 04, 2011 3:41 pm

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

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: IWshRuntimeLibrary Error

Post by costamesakid » Tue Oct 04, 2011 9:58 pm

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

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: IWshRuntimeLibrary Error

Post by sdaly » Wed Oct 05, 2011 8:59 am

Out of curiosity, is there a reason why you have to do this through code yourself?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: IWshRuntimeLibrary Error

Post by Support Team » Wed Oct 05, 2011 9:12 am

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

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: IWshRuntimeLibrary Error

Post by costamesakid » Thu Oct 06, 2011 4:42 pm

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