Reputation: 179
I have a registered type which is currently access in VB code via:
Dim prog As Object = CreateObject(sPath)
prog.Show(parameters)
I've rewritten this into C# as:
var progType = Type.GetTypeFromProgID(path);
progInstance = Activator.CreateInstance(progType);
progType.InvokeMember("Show", BindingFlags.InvokeMethod, null, progInstance, new object[] {parameters});
For some reason though, when I try to execute the Show method, it appears as if it does not exist. The following code in LINQPad shows the method however in my application results in nothing:
var methods = progType.GetMethods().Where(m => m.Name.ToLower() == "show");
I believe it has to do with this line from MSDN:
Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
I have tried adding the SecurityCritical
attribute to my method but nothing has changed. I'm not very familiar with .NET security, can someone explain what the line from MSDN means, and maybe why running my code in LINQPad and running my actual program give different results?
Upvotes: 2
Views: 781
Reputation: 179
I figured it out by looking at the LINQPad App.config -- I needed to add the following to my own App.config:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
Upvotes: 1
Reputation: 133
try that :
Type _progType = Type.GetTypeFromProgID(path);
System.Reflection.MethodInfo _MethodInfo = typeof(_progType).GetMethod("Show");
if (!ReferenceEquals(_MethodInfo, null))
{
// method is founded
}
else
{
// method is not founded
}
Attention !! the name is "Show" ou "show" ??? on your code ou write it differently !
Upvotes: 0