Converts a COM type library to an assembly.
Namespace:
System.Runtime.InteropServices
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Public Function ConvertTypeLibToAssembly ( _
typeLib As Object, _
asmFileName As String, _
flags As TypeLibImporterFlags, _
notifySink As ITypeLibImporterNotifySink, _
publicKey As Byte(), _
keyPair As StrongNameKeyPair, _
asmNamespace As String, _
asmVersion As Version _
) As AssemblyBuilder
Dim instance As TypeLibConverter
Dim typeLib As Object
Dim asmFileName As String
Dim flags As TypeLibImporterFlags
Dim notifySink As ITypeLibImporterNotifySink
Dim publicKey As Byte()
Dim keyPair As StrongNameKeyPair
Dim asmNamespace As String
Dim asmVersion As Version
Dim returnValue As AssemblyBuilder
returnValue = instance.ConvertTypeLibToAssembly(typeLib, _
asmFileName, flags, notifySink, publicKey, _
keyPair, asmNamespace, asmVersion)
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public AssemblyBuilder ConvertTypeLibToAssembly(
Object typeLib,
string asmFileName,
TypeLibImporterFlags flags,
ITypeLibImporterNotifySink notifySink,
byte[] publicKey,
StrongNameKeyPair keyPair,
string asmNamespace,
Version asmVersion
)
[SecurityPermissionAttribute(SecurityAction::Demand, Flags = SecurityPermissionFlag::UnmanagedCode)]
public:
virtual AssemblyBuilder^ ConvertTypeLibToAssembly(
Object^ typeLib,
String^ asmFileName,
TypeLibImporterFlags flags,
ITypeLibImporterNotifySink^ notifySink,
array<unsigned char>^ publicKey,
StrongNameKeyPair^ keyPair,
String^ asmNamespace,
Version^ asmVersion
) sealed
public final function ConvertTypeLibToAssembly(
typeLib : Object,
asmFileName : String,
flags : TypeLibImporterFlags,
notifySink : ITypeLibImporterNotifySink,
publicKey : byte[],
keyPair : StrongNameKeyPair,
asmNamespace : String,
asmVersion : Version
) : AssemblyBuilder
Implements
ITypeLibConverter..::.ConvertTypeLibToAssembly(Object, String, TypeLibImporterFlags, ITypeLibImporterNotifySink, array<Byte>[]()[], StrongNameKeyPair, String, Version)
| Exception | Condition |
|---|
| ArgumentNullException |
typeLib is nullNothingnullptra null reference (Nothing in Visual Basic). -or-
asmFileName is nullNothingnullptra null reference (Nothing in Visual Basic). -or-
notifySink is nullNothingnullptra null reference (Nothing in Visual Basic). |
| ArgumentException |
asmFileName is an empty string. -or-
asmFileName is longer than MAX_PATH. |
| InvalidOperationException |
flags is not PrimaryInteropAssembly. -or-
publicKey and keyPair are nullNothingnullptra null reference (Nothing in Visual Basic). |
| ReflectionTypeLoadException | The metadata produced has errors preventing any types from loading. |
If you do not want to generate a strong name for your assembly, it is valid for publicKey and keyPair to be nullNothingnullptra null reference (Nothing in Visual Basic), as long as flags does not equal TypeLibImporterFlags..::.PrimaryInteropAssembly. Otherwise, atleast one of these parameters must be specified. If publicKey is nullNothingnullptra null reference (Nothing in Visual Basic), the public key in keyPair will be set in the target assembly's manifest metadata and a signature will be generated based on the contents of the assembly. If keyPair is nullNothingnullptra null reference (Nothing in Visual Basic), publicKey will be set in the target assembly's manifest metadata and no signature will be generated. Specifying both parameters is not generally useful, and can result in an invalid signature.
For more information on ITypeLib, please see its existing documentation in the MSDN library.
Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices
Public Class App
Private Enum RegKind
RegKind_Default = 0
RegKind_Register = 1
RegKind_None = 2
End Enum 'RegKind
<DllImport("oleaut32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
Private Shared Sub LoadTypeLibEx(ByVal strTypeLibName As [String], ByVal regKind As RegKind, <MarshalAs(UnmanagedType.Interface)> ByRef typeLib As [Object])
End Sub
Public Shared Sub Main()
Dim typeLib As [Object]
LoadTypeLibEx("SHDocVw.dll", RegKind.RegKind_None, typeLib)
If typeLib Is Nothing Then
Console.WriteLine("LoadTypeLibEx failed.")
Return
End If
Dim converter As New TypeLibConverter()
Dim eventHandler As New ConversionEventHandler()
Dim asm As AssemblyBuilder = converter.ConvertTypeLibToAssembly(typeLib, "ExplorerLib.dll", 0, eventHandler, Nothing, Nothing, Nothing, Nothing)
asm.Save("ExplorerLib.dll")
End Sub 'Main
End Class 'App
_
Public Class ConversionEventHandler
Implements ITypeLibImporterNotifySink
Public Sub ReportEvent(ByVal eventKind As ImporterEventKind, ByVal eventCode As Integer, ByVal eventMsg As String) Implements ITypeLibImporterNotifySink.ReportEvent
' handle warning event here...
End Sub 'ReportEvent
Public Function ResolveRef(ByVal typeLib As Object) As [Assembly] Implements ITypeLibImporterNotifySink.ResolveRef
' resolve reference here and return a correct assembly...
Return Nothing
End Function 'ResolveRef
End Class 'ConversionEventHandler
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
public class App
{
private enum RegKind
{
RegKind_Default = 0,
RegKind_Register = 1,
RegKind_None = 2
}
[ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false )]
private static extern void LoadTypeLibEx( String strTypeLibName, RegKind regKind,
[ MarshalAs( UnmanagedType.Interface )] out Object typeLib );
public static void Main()
{
Object typeLib;
LoadTypeLibEx( "SHDocVw.dll", RegKind.RegKind_None, out typeLib );
if( typeLib == null )
{
Console.WriteLine( "LoadTypeLibEx failed." );
return;
}
TypeLibConverter converter = new TypeLibConverter();
ConversionEventHandler eventHandler = new ConversionEventHandler();
AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", 0, eventHandler, null, null, null, null );
asm.Save( "ExplorerLib.dll" );
}
}
public class ConversionEventHandler : ITypeLibImporterNotifySink
{
public void ReportEvent( ImporterEventKind eventKind, int eventCode, string eventMsg )
{
// handle warning event here...
}
public Assembly ResolveRef( object typeLib )
{
// resolve reference here and return a correct assembly...
return null;
}
}
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Runtime::InteropServices;
enum class RegKind
{
RegKind_Default, RegKind_Register, RegKind_None
};
ref class ConversionEventHandler: public ITypeLibImporterNotifySink
{
public:
virtual void ReportEvent( ImporterEventKind eventKind, int eventCode, String^ eventMsg )
{
// handle warning event here...
}
virtual Assembly^ ResolveRef( Object^ typeLib )
{
// resolve reference here and return a correct assembly...
return nullptr;
}
};
[DllImport("oleaut32.dll",CharSet=CharSet::Unicode,PreserveSig=false)]
extern void LoadTypeLibEx( String^ strTypeLibName, RegKind regkind,
[MarshalAs(UnmanagedType::Interface)] interior_ptr<Object^> typeLib );
int main()
{
Object^ typeLib = gcnew Object;
LoadTypeLibEx( "SHDocVw.dll", RegKind::RegKind_None, &typeLib );
if ( typeLib == nullptr )
{
Console::WriteLine( "LoadTypeLibEx failed." );
return 0;
}
TypeLibConverter^ converter = gcnew TypeLibConverter;
ConversionEventHandler^ eventHandler = gcnew ConversionEventHandler;
AssemblyBuilder^ asmb = converter->ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", (System::Runtime::InteropServices::TypeLibImporterFlags)0, eventHandler, nullptr, nullptr, nullptr, nullptr );
asmb->Save( "ExplorerLib.dll" );
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference
Other Resources