GetMethods for CF assembly gets invalid methods

  • Thread starter Vamsi T via DotNetMonster.com
  • Start date
V

Vamsi T via DotNetMonster.com

Hi,

I'm using .NET CF 2.0. I have a problem in retrieving the exact methods of a
Class in CF. When I do a type.GetMethods() (where type is System.Xml.XPath.
XPathException for example), I get get_HelpLink (GetProperties also returns
HelpLink) which is not available in CF. I'm loading the exact System.Xml.dll
from the CF directory using ReflectionOnlyLoadFrom. So the dll being probed
is correct but the methods being returned are not the exact ones available.
Here's the code. Any help is very much appreciated. Urgent.

using System;
using System.Reflection;
using System.Diagnostics;
using System.IO;
using System.Collections;
using System.Text;

namespace DNVsCF
{
class Program
{
static string assemblyPath = string.Empty;
static void Main(string[] args)
{
try
{
// Hardcoding args for testing
args = new string[] {@"C:\Program Files\Microsoft Visual
Studio 8\SmartDevices\SDK\CompactFramework\2.0\WindowsCE\System.Xml.dll"};
assemblyPath = Path.GetDirectoryName(args[0]);
Assembly assembly = Assembly.ReflectionOnlyLoadFrom(args[0]);
AppDomain appDomain = AppDomain.CurrentDomain;
appDomain.ReflectionOnlyAssemblyResolve += new
ResolveEventHandler(appDomain_ReflectionOnlyAssemblyResolve);
Console.WriteLine("Loaded: " + assembly.FullName + "\
n========");
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
// Test System.Xml.XPath.XPathException's methods
if (type.FullName == "System.Xml.XPath.XPathException")
{
Console.WriteLine(type.FullName);
Console.WriteLine("\nMethodInfo\n=======\n");
foreach (MethodInfo methodInfo in type.GetMethods()
{
Console.WriteLine(methodInfo + ": " + attributes.
Length.ToString());
}
}
}
Console.WriteLine("\n=======");
}
catch (ReflectionTypeLoadException ex)
{
Console.WriteLine(ex.Message + "\n===");
}
}

static Assembly appDomain_ReflectionOnlyAssemblyResolve(object sender,
ResolveEventArgs args)
{
return Assembly.ReflectionOnlyLoadFrom(@assemblyPath + "\\" +
(args.Name.Substring(0, args.Name.IndexOf(','))) + ".dll");
}
}
}
 
R

Ryan Chapman [MSFT]

Hi Vamsi,

Could you please provide the output from running this test?

Thanks,

Ryan Chapman
.NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Ryan Chapman [MSFT]

HI Vamsi,

I get the same results here. I think what's happening is that because your
app is a desktop application and XPathException derives from
System.Exception, the loader is deriving XPathException from
System.Exception in the desktop version of mscorlib and picks up the
methods from that one. The desktop loader is designed to retarget NetCF
assemblies to desktop ones in certain circumstances. This app would likely
return the expected results if it were a NetCF app.

What are you trying to do here? I might be better able to help if I could
understand the ultimate goal.

Thanks,

Ryan Chapman
.NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
 
V

Vamsi T via DotNetMonster.com

Hi Ryan,

I understand what u say. But from my knowledge, mscorlib vesion should come
into play only when we use Load/LoadFrom/LoadFile. But when we use
ReflectionOnlyLoadFrom, the CF version would be used. Right? Anyways, my
ultimate goal is to find all the methods that are supported in .NET but not
supported in CF. I have no issues in extracting the info from .NET assemblies.
Problem is only with the CF assemblies which give invalid info. Is there any
better way to accomplish this task?
Thanks - Vamsi TP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top