PRB: 'System.IO.FileNotFoundException' When You Use the Assembly.LoadFrom Method to Load a DLL (818434)
The information in this article applies to:
- Microsoft Visual J# .NET 2002
SYMPTOMSWhen you try to load a DLL in your Visual J# .NET
application by using the Assembly.LoadFrom method, and the URL of the DLL contains encoded characters (such
as %20 for the space character), you receive the following
exception error message: System.IO.FileNotFoundException: File or
assembly name My%20JSharp%20Class%20Library.dll, or
one of its dependencies, was not found. CAUSEThe URL is made up of a restricted set of characters. The
restricted set contains letters, numbers, and some symbols. This problem occurs because the Assembly.LoadForm method cannot interpret the encoded characters, such as %20, in the URL.RESOLUTIONTo resolve this problem, remove all percent sign ( %) encoded characters
from the URL before you pass it to the Assembly.LoadForm method. To remove the encoded characters programmatically, you may use
the UrlUnescapeW Win32 API function. To load a DLL that has encoded characters in the URL by using Assembly.LoadFrom, follow these steps:
- Start Microsoft Visual Studio .NET.
- On the File menu, point to
New, and then click Project.
- In the New Project dialog box, click Visual J# Projects under
Project Types, click Console Application
under Templates, and then click OK. By default, ConsoleApplication1 is created.
- Replace the existing code in Class1.jsl with the following sample code:
import System.Reflection.*;
import System.*;
import System.Runtime.InteropServices.*;
public class Class1
{
// Importing the Win32 DLL shlwapi.dll
/** @attribute DllImport("shlwapi.dll", CharSet=CharSet.Unicode ) */
static native long UrlUnescapeW(String url1, String url2, long i1[], long i2);
// This method loads the DLL from the URL, and then tries to
// get the details of a specified method in the loaded DLL.
public void GetMethodDetails(String url, String methodName)
{
Assembly SampleAssembly;
try
{
SampleAssembly = Assembly.LoadFrom(Unescape(url));
MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod(methodName);
ParameterInfo[] Params = Method.GetParameters();
for (int i=0; i<Params.length; i++)
{
ParameterInfo Param = Params[i];
System.Console.WriteLine("Param=" + Param.get_Name());
System.Console.WriteLine(" Type=" + Param.get_ParameterType());
System.Console.WriteLine(" Position=" + Param.get_Position());
System.Console.WriteLine(" Optional=" + Param.get_IsOptional());
}
}
catch(System.Exception excep)
{
System.out.println(excep.ToString());
}
finally
{
System.Console.Read();
}
}
// This method removes the encoded characters in the URL by using Win32 API,
// and then returns the URL without the encoded characters.
public String Unescape(String url)
{
String outUrl = new String(' ', 260);
long[] j = {260};
UrlUnescapeW(url, outUrl, j, 0);
System.out.println(outUrl);
return outUrl;
}
// Main method.
public static void main(String[] args)
{
Class1 myObj = new Class1();
String url = "http://localhost/My%20JSharp%20Class%20Library/bin/debug/My%20JSharp%20Class%20Library.dll";
myObj.GetMethodDetails(url, "Cube");
}
}
- On the Debug menu, click
Start.
STATUS This
behavior is by design.REFERENCESFor more information about how to name URLs, visit the following
W3C Web site:
Modification Type: | Minor | Last Reviewed: | 8/15/2005 |
---|
Keywords: | kbDLL kbCompiler kberrmsg kbURLMon kbprb KB818434 kbAudDeveloper |
---|
|