DLL load should be easy, but errors

G

Guest

here is a DLL I need to mimic because the application does not connect to
real hardware depending on where the application runs ( it runs in a
simulation mode ).

The application ( C#.exe ) -> HeatDrivers.DLL ( the hardware one ) and
application ( C# .exe) -> HeatDrivers.DLL ( has a restricted simulation stub
). Also I should note these are static classes

By an input file I would redirect the application to load the applicable DLL
( locations are different ). Without using an interface class I called /
loaded each DLL - althought I could see all the classes/methods the load was
flawed, because an internal error was generated. this is the simplified DLL :

using System;
using System.Collections.Generic;
using System.Text;

namespace FTEE.HeatDrivers
{
public static class CartInfo
{
public static string ExecRev
{
get
{
string _ExecRev = "TMS Simulation stub";
return _ExecRev;
}
}
}

}

This is the calling piece from the EXE :

Assembly a = Assembly.LoadFrom(heatDriversPath);
Type[] types = a.GetTypes();
foreach (Type typ in types)
{
// ERRORS here ! < why is that ?? >
'typ.DeclaringMethod' threw an exception of type
'System.InvalidOperationException'
'typ.GenericParameterAttributes' threw an exception of type
'System.InvalidOperationException'
'typ.GenericParameterPosition' threw an exception of type
'System.InvalidOperationException'
}

Again Thank you for you effort & time
 
N

Nicholas Paldino [.NET/C# MVP]

Can you post a complete example which details the problem?

Also, I would recommend using interfaces. While all of your methods
might be static, there is no reason you can't create an object which will
make the calls on the static method. This will help with your code, and
make abstracting out the provider (HeadDrivers.dll) a little easier.
 
G

Guest

Thanks for the reply. The only thing missing from the code I gave was the
dialog to find the path to both DLL's. But I cant load even the simple DLL I
gave without inner errors. I replaced the winodws diagnostic with a quick
console app as shown. Just supply the exe with the path to the DLL I showed.

Here's the console app code ( no binding or reference in the console
project ) :

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

namespace testDLLLoad
{
class Program
{
static void Main(string[] args)
{
if (args.Length>0)
{
string heatDriversPath = args[0];
if (File.Exists(heatDriversPath))
{
Assembly a = Assembly.LoadFrom(heatDriversPath);
Type[] types = a.GetTypes();
foreach (Type typ in types)
{ // check typ and find all the errors
MethodInfo mi = typ.GetMethod("CartInfo.ExecRev");
mi.Invoke(0, null);
Console.WriteLine(" ??? what now ???" + mi.ToString());
}

}
}

Console.ReadLine();
}
}
}







--
Andrew


Nicholas Paldino said:
Can you post a complete example which details the problem?

Also, I would recommend using interfaces. While all of your methods
might be static, there is no reason you can't create an object which will
make the calls on the static method. This will help with your code, and
make abstracting out the provider (HeadDrivers.dll) a little easier.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

andrewcw said:
here is a DLL I need to mimic because the application does not connect to
real hardware depending on where the application runs ( it runs in a
simulation mode ).

The application ( C#.exe ) -> HeatDrivers.DLL ( the hardware one )
and
application ( C# .exe) -> HeatDrivers.DLL ( has a restricted simulation
stub
). Also I should note these are static classes

By an input file I would redirect the application to load the applicable
DLL
( locations are different ). Without using an interface class I called /
loaded each DLL - althought I could see all the classes/methods the load
was
flawed, because an internal error was generated. this is the simplified
DLL :

using System;
using System.Collections.Generic;
using System.Text;

namespace FTEE.HeatDrivers
{
public static class CartInfo
{
public static string ExecRev
{
get
{
string _ExecRev = "TMS Simulation stub";
return _ExecRev;
}
}
}

}

This is the calling piece from the EXE :

Assembly a = Assembly.LoadFrom(heatDriversPath);
Type[] types = a.GetTypes();
foreach (Type typ in types)
{
// ERRORS here ! < why is that ?? >
'typ.DeclaringMethod' threw an exception of type
'System.InvalidOperationException'
'typ.GenericParameterAttributes' threw an exception of type
'System.InvalidOperationException'
'typ.GenericParameterPosition' threw an exception of type
'System.InvalidOperationException'
}

Again Thank you for you effort & time
 

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