Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以从.NET3.5中的COM互操作返回System.Type?_C#_.net_Com_Com Interop - Fatal编程技术网

C# 是否可以从.NET3.5中的COM互操作返回System.Type?

C# 是否可以从.NET3.5中的COM互操作返回System.Type?,c#,.net,com,com-interop,C#,.net,Com,Com Interop,我有一门课: public class A { public void Test() { Type t = icom.ReturnType; } } [ComVisible(true), Guid("81C99F84-AA95-41A5-868E-62FAC8FAC263"), InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface Icom { Type ReturnT

我有一门课:

public class A
{
    public void Test()
    {
        Type t = icom.ReturnType;
    }
}

[ComVisible(true),
Guid("81C99F84-AA95-41A5-868E-62FAC8FAC263"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface Icom
{
    Type ReturnType { get; }
}

[ComVisible(true)]
[Guid("6DF6B926-8EB1-4333-827F-DD814B868097")]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(Icom))]
public class B : Icom
{
    public Type ReturnType
    {
        get
        {
            return SomeAssembly.GetType("fullname");
        }
    }
}

这是否可能在.NET3.5中实现?我的目标是从B类返回
System.Type
。在这种情况下,我收到一个无法将
System.Com
转换为
System.Type
的错误。我将尝试解释我所理解的情况。您似乎有以下调用(或正在传递的对象)工作流:.NET4.x->COM->.NET3.5。您的
Icom
接口被封送到COM,如下所示(OleView):

注意
\u Type
是托管
Type
类的非托管代理,在
mscorlib.dll
中实现(Type library
mscorlib.tlb
)。它的实现特定于每个.NET运行时版本。显然,它是由.NET运行时v4.0创建的


在稍后的某个时候,您试图将其解封送回来,这次是在.NET3.5端。如果是v4.0,您将返回相同的托管
类型
对象。但是,在v3.5中,您得到的是一个未老化的
系统。\uuu ComObject
,无法转换为v3.5托管
类型
对象。

为什么它特定于.NET 3.5,它适用于4.5吗?到底是哪一行给了你这个错误?
SomeAssembly
的类型是什么(您确定是吗)?一般来说,如果你告诉我们你想要实现什么,这也会有所帮助。因为它在4.5版本中有效,A级是在3.5版本的基础上构建的项目中。Type t=icom.ReturnType是给我一个错误的行。例如,我需要返回这个类型:return LoadedAssembly.GetType(“Microsoft.SqlServer.Management.DatabaseMaintenance.dbMaintenance TsqlExecuteTask”);其中LoadedAssembly是先前加载的MaintenancePlanTasks dll。我只是没有编写加载该程序集的代码,因为它已经在数组中,但我希望您能看到我需要返回的内容。MaintenancePlantask也是.net 4.0 dll。这就是B类出现在.NET4.0项目中的原因,因为我可以加载这些程序集。是的,您做对了。好的,谢谢你的解释。这很有帮助。
[
  odl,
  uuid(81C99F84-AA95-41A5-868E-62FAC8FAC263),
  version(1.0),
  dual,
  oleautomation,
  custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "InteropTest.Icom")    

]
interface Icom : IDispatch {
    [id(0x60020000), propget]
    HRESULT ReturnType([out, retval] _Type** pRetVal);
};