反射而不是 .NET 到 .NET 的场景
Reflection instead .NET-to-.NET scenario
我创建了 Person.dll 并在 Visual Studio 2019 的命令提示符中注册了它(regsvcs.exe)。作为注册的结果,我得到了 Person.tlb。我试图在控制台项目中添加 Person.tlb 作为参考 COM 组件,但我收到警告 MSB3290.
warning MSB3290: Failed to create the wrapper assembly for type
library "{8b1098cb-d453-4dc7-96ac-52df54d0a2ce}". Type library
'Person' was exported from a CLR assembly and cannot be re-imported as
a CLR assembly.
如何使用反射在控制台项目中添加 Person.tlb?
Person.dll:
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
namespace COM
{
[ClassInterface(ClassInterfaceType.None)]
public class Person : ServicedComponent, COM.IPerson
{
public string FirstName { get; set; }
public string LastName { get; set; }
public bool IsMale { get; set; }
public void Persist(string FilePath)
{
StreamWriter oFile = new StreamWriter(FilePath);
XmlSerializer oXmlSerializer = new XmlSerializer(typeof(Person));
oXmlSerializer.Serialize(oFile, this);
oFile.Flush();
oFile.Close();
}
static public Person Retrieve(string FilePath)
{
StreamReader oFile = new StreamReader(FilePath);
XmlSerializer oXmlSerilizer = new XmlSerializer(typeof(Person));
Person oPerson = oXmlSerilizer.Deserialize(oFile) as Person;
return oPerson;
}
}
}
控制台项目:
using System;
namespace Test10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
COM.Person per = new COM.Person();
per.FirstName = "Maxim";
per.LastName = "Donax";
per.Persist(@" C:\myFile.xml ");
}
}
}
我使用了其他方式:在 Visual Studio 中创建了 Person.dll 并注册了它 (regsvcs.exe)。在 Visual Basic 6.0.
中使用参考后 Person.tlb
我创建了 Person.dll 并在 Visual Studio 2019 的命令提示符中注册了它(regsvcs.exe)。作为注册的结果,我得到了 Person.tlb。我试图在控制台项目中添加 Person.tlb 作为参考 COM 组件,但我收到警告 MSB3290.
warning MSB3290: Failed to create the wrapper assembly for type library "{8b1098cb-d453-4dc7-96ac-52df54d0a2ce}". Type library 'Person' was exported from a CLR assembly and cannot be re-imported as a CLR assembly.
如何使用反射在控制台项目中添加 Person.tlb?
Person.dll:
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
namespace COM
{
[ClassInterface(ClassInterfaceType.None)]
public class Person : ServicedComponent, COM.IPerson
{
public string FirstName { get; set; }
public string LastName { get; set; }
public bool IsMale { get; set; }
public void Persist(string FilePath)
{
StreamWriter oFile = new StreamWriter(FilePath);
XmlSerializer oXmlSerializer = new XmlSerializer(typeof(Person));
oXmlSerializer.Serialize(oFile, this);
oFile.Flush();
oFile.Close();
}
static public Person Retrieve(string FilePath)
{
StreamReader oFile = new StreamReader(FilePath);
XmlSerializer oXmlSerilizer = new XmlSerializer(typeof(Person));
Person oPerson = oXmlSerilizer.Deserialize(oFile) as Person;
return oPerson;
}
}
}
控制台项目:
using System;
namespace Test10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
COM.Person per = new COM.Person();
per.FirstName = "Maxim";
per.LastName = "Donax";
per.Persist(@" C:\myFile.xml ");
}
}
}
我使用了其他方式:在 Visual Studio 中创建了 Person.dll 并注册了它 (regsvcs.exe)。在 Visual Basic 6.0.
中使用参考后 Person.tlb