HighTechTalks DotNet Forums  

Type library cannot be re-imported as a CLR assembly

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Type library cannot be re-imported as a CLR assembly in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Alex
 
Posts: n/a

Default Type library cannot be re-imported as a CLR assembly - 06-10-2007 , 01:28 PM






Dear All,

I am trying to write a C# DLL that would work with VBA and C++ applications.
After registering my DLL with RegAsm (regasm MyDll.dll \t MyDll.tlb) I can
use it in VBA. However I can not add a MyDll.dll or MyDll.tlb to
VisualStudio 2005. If I am trying to add it in C++ environment the following
Error erise: "TlbImp : error TI0000 :
System.Runtime.InteropServices.COMException - Type library MyDLL was
exported from a CLR assembly and cannot be re-imported as a CLR assembly"

Any help would be highly appreciated

Alex



Reply With Quote
  #2  
Old   
Alex
 
Posts: n/a

Default Re: Type library cannot be re-imported as a CLR assembly - 06-11-2007 , 08:42 AM






Mattias Sjögren schrieb:
Quote:
I am trying to write a C# DLL that would work with VBA and C++ applications.
After registering my DLL with RegAsm (regasm MyDll.dll \t MyDll.tlb) I can
use it in VBA. However I can not add a MyDll.dll or MyDll.tlb to
VisualStudio 2005. If I am trying to add it in C++ environment the following
Error erise: "TlbImp : error TI0000 :
System.Runtime.InteropServices.COMException - Type library MyDLL was
exported from a CLR assembly and cannot be re-imported as a CLR assembly"

You should be able to reference MyDll.dll. Just make sure you
reference it as a .NET assembly (ie don't look at the COM tab in the
VS Add Reference dialog).


Mattias

Mattias,
Thank you very much for your answer. I would like to compile
My_VC++_WrapperDll.dll that would use My_C#_DLL.dll. If I am adding
My_C#_DLL.dll as .NET component to My_VC++_WrapperDll.dll project then
VS2005 requires to enable CLR support (/clr option). Unfortunately under
WinXP with CLR enabled the client application crashes while trying to
access My_VC++_WrapperDll.dll. Under Win 2000 everything works fine.

Alex


Reply With Quote
  #3  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Type library cannot be re-imported as a CLR assembly - 06-12-2007 , 01:30 AM




"Alex" <alexzeit (AT) mail (DOT) ru> wrote

Quote:
Mattias Sjögren schrieb:
I am trying to write a C# DLL that would work with VBA and C++
applications. After registering my DLL with RegAsm (regasm MyDll.dll \t
MyDll.tlb) I can use it in VBA. However I can not add a MyDll.dll or
MyDll.tlb to VisualStudio 2005. If I am trying to add it in C++
environment the following Error erise: "TlbImp : error TI0000 :
System.Runtime.InteropServices.COMException - Type library MyDLL was
exported from a CLR assembly and cannot be re-imported as a CLR
assembly"

You should be able to reference MyDll.dll. Just make sure you
reference it as a .NET assembly (ie don't look at the COM tab in the
VS Add Reference dialog).


Mattias


Mattias,
Thank you very much for your answer. I would like to compile
My_VC++_WrapperDll.dll that would use My_C#_DLL.dll. If I am adding
My_C#_DLL.dll as .NET component to My_VC++_WrapperDll.dll project then
VS2005 requires to enable CLR support (/clr option). Unfortunately under
WinXP with CLR enabled the client application crashes while trying to
access My_VC++_WrapperDll.dll. Under Win 2000 everything works fine.
Sounds like a deeper bug you need to look into.

But it does seem strange that when importing a tlb into non-CLR C++, it
creates a .NET assembly. Are you invoking tlbimp directly, or using
#import?

Quote:
Alex


Reply With Quote
  #4  
Old   
Alex
 
Posts: n/a

Default Re: Type library cannot be re-imported as a CLR assembly - 06-12-2007 , 09:02 AM



Ben Voigt [C++ MVP] schrieb:
Quote:
"Alex" <alexzeit (AT) mail (DOT) ru> wrote in message
news:uk3F8UCrHHA.4624 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Mattias Sjögren schrieb:
I am trying to write a C# DLL that would work with VBA and C++
applications. After registering my DLL with RegAsm (regasm MyDll.dll
\t MyDll.tlb) I can use it in VBA. However I can not add a MyDll.dll
or MyDll.tlb to VisualStudio 2005. If I am trying to add it in C++
environment the following Error erise: "TlbImp : error TI0000 :
System.Runtime.InteropServices.COMException - Type library MyDLL was
exported from a CLR assembly and cannot be re-imported as a CLR
assembly"

You should be able to reference MyDll.dll. Just make sure you
reference it as a .NET assembly (ie don't look at the COM tab in the
VS Add Reference dialog).


Mattias


Mattias,
Thank you very much for your answer. I would like to compile
My_VC++_WrapperDll.dll that would use My_C#_DLL.dll. If I am adding
My_C#_DLL.dll as .NET component to My_VC++_WrapperDll.dll project then
VS2005 requires to enable CLR support (/clr option). Unfortunately
under WinXP with CLR enabled the client application crashes while
trying to access My_VC++_WrapperDll.dll. Under Win 2000 everything
works fine.

Sounds like a deeper bug you need to look into.

But it does seem strange that when importing a tlb into non-CLR C++, it
creates a .NET assembly. Are you invoking tlbimp directly, or using
#import?


Alex

I have a C# class there is only one class with only one method and one Form:

namespace Cs_CLR_DLLns
{
public class Class1
{
public int OpenForm1()
{
Form1 f1 = new Form1();
f1.Show();

return 2;
}
}
}

AssemblyInfo.cs is:

[assembly: AssemblyTitle("Cs_CLR_DLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("UKA")]
[assembly: AssemblyProduct("Cs_CLR_DLL")]
[assembly: AssemblyCopyright("Copyright 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
[assembly: Guid("32fa638b-e5fd-4ab0-aa5f-f34d0cfc4913")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]



After compiling Cs_CLR_DLL I registered it with
RegAsm.exe Cs_CLR_DLL.dll /t Cs_CLR_DLL.tlb

I can load Cs_CLR_DLL.tlb in VBA and use it as follows:
Private Sub CommandButton1_Click()
Dim tt As New Cs_CLR_DLL.Class1
Call tt.openform1
End Sub

But I cannot load Cs_CLR_DLL.tlb in C++ Project.
I tried :
1) #import "D:\\Projects\\Cs_CLR_DLL.tlb"
2) #import "D:\\Projects\\Cs_CLR_DLL.dll"
3) using "References" dialog:
There is a Cs_CLR_DLL only in COM tab but
it does not loads from there. There is a following error:
"TlbImp : error TI0000 : System.Runtime.InteropServices.COMException -
Type library MyDLL was exported from a CLR assembly and cannot be
re-imported as a CLR assembly"

The only possibility is to load a dll by browsing to its location (using
"references" dialog)

in C++ I call and export it as follows:
extern "C" {

__declspec(dllexport) int CallFromAV1(){

AFX_MANAGE_STATE(AfxGetStaticModuleState());
int i = 0;

Cs_CLR_DLLns::Class1 cls1;
i = cls1.OpenForm1();

return i;};
}

Old Win32 application is calling CallFromAV1 function.
As soon as I have Cs_CLR_DLLns::Class1 cls1; in this function the client
application crashes under win2000 and winXP.

How to properly access classes in Cs_CLR_DLL.dll from C++?

is it possible to create a C++ Dll (that uses .net(C#) Dll with Forms)
without /clr enabled in C++?

Thank you very much in advance.


Reply With Quote
  #5  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Type library cannot be re-imported as a CLR assembly - 06-13-2007 , 02:00 AM




Quote:
But it does seem strange that when importing a tlb into non-CLR C++, it
creates a .NET assembly. Are you invoking tlbimp directly, or using
#import?


Alex


I have a C# class there is only one class with only one method and one
Form:

namespace Cs_CLR_DLLns
{
public class Class1
{
public int OpenForm1()
{
Form1 f1 = new Form1();
f1.Show();

return 2;
}
}
}

AssemblyInfo.cs is:

[assembly: AssemblyTitle("Cs_CLR_DLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("UKA")]
[assembly: AssemblyProduct("Cs_CLR_DLL")]
[assembly: AssemblyCopyright("Copyright 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
[assembly: Guid("32fa638b-e5fd-4ab0-aa5f-f34d0cfc4913")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]



After compiling Cs_CLR_DLL I registered it with
RegAsm.exe Cs_CLR_DLL.dll /t Cs_CLR_DLL.tlb

I can load Cs_CLR_DLL.tlb in VBA and use it as follows:
Private Sub CommandButton1_Click()
Dim tt As New Cs_CLR_DLL.Class1
Call tt.openform1
End Sub

But I cannot load Cs_CLR_DLL.tlb in C++ Project.
I tried :
1) #import "D:\\Projects\\Cs_CLR_DLL.tlb"
2) #import "D:\\Projects\\Cs_CLR_DLL.dll"
3) using "References" dialog:
There is a Cs_CLR_DLL only in COM tab but
it does not loads from there. There is a following error:
"TlbImp : error TI0000 : System.Runtime.InteropServices.COMException -
Type library MyDLL was exported from a CLR assembly and cannot be
re-imported as a CLR assembly"

The only possibility is to load a dll by browsing to its location (using
"references" dialog)

in C++ I call and export it as follows:
extern "C" {

__declspec(dllexport) int CallFromAV1(){

AFX_MANAGE_STATE(AfxGetStaticModuleState());
int i = 0;

Cs_CLR_DLLns::Class1 cls1;
i = cls1.OpenForm1();

return i;};
}

Old Win32 application is calling CallFromAV1 function.
As soon as I have Cs_CLR_DLLns::Class1 cls1; in this function the client
application crashes under win2000 and winXP.

How to properly access classes in Cs_CLR_DLL.dll from C++?

is it possible to create a C++ Dll (that uses .net(C#) Dll with Forms)
without /clr enabled in C++?

Thank you very much in advance.
I think things are pretty well designed around the other way. Yes, a native
application can call a .NET component via COM... if the native application
defined a COM interface for plugins or whatever, then the .NET application
can implement that interface, and the native app can use it. As far as the
native application seeing the .NET interface, I don't know. I've never had
to do that.



Reply With Quote
  #6  
Old   
TM Software
 
Posts: n/a

Default Re: Type library cannot be re-imported as a CLR assembly - 06-13-2007 , 05:58 PM



Alex pisze:
Quote:
Dear All,

I am trying to write a C# DLL that would work with VBA and C++ applications.
After registering my DLL with RegAsm (regasm MyDll.dll \t MyDll.tlb)
try register with /codebase option
regasm MyDll.dll /tlb:MyDll.tlb /codebase

It can help

TM


Reply With Quote
  #7  
Old   
Alex
 
Posts: n/a

Default partial solution, it does not work under XP - 06-14-2007 , 05:50 AM



Alex schrieb:
Quote:
Dear All,

I am trying to write a C# DLL that would work with VBA and C++ applications.
After registering my DLL with RegAsm (regasm MyDll.dll \t MyDll.tlb) I can
use it in VBA. However I can not add a MyDll.dll or MyDll.tlb to
VisualStudio 2005. If I am trying to add it in C++ environment the following
Error erise: "TlbImp : error TI0000 :
System.Runtime.InteropServices.COMException - Type library MyDLL was
exported from a CLR assembly and cannot be re-imported as a CLR assembly"

Any help would be highly appreciated

Alex


I found a partial solution to this problem:


1) C# Dll code:

namespace Cs_CLR_DLL
{
public class Class1 : IClass1
public Class1() { }

public int OpenForm1()
{
// Form1 f1 = new Form1();
// f1.ShowDialog();

return 1;
}

public interface IClass1
{
int OpenForm1();
}
}

AssemblyInfo.cs:
....
[assembly: ComVisible(true)]
// [assembly: Guid("32fa638b-e5fd-4ab0-aa5f-f34d0cfc4913")]
....

Register for COM interop check box (in Properties) is checked


2) register C# dll with regasm:
regasm MyC#Dll.dll /t MyC#Dll.tlb



3) MFC VC++ Dll code:

#include "atlbase.h"
#import "Cs_CLR_DLL.tlb" no_namespace


extern "C" __declspec(dllexport)
int CallFromAV1(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());

HRESULT resH;
resH = CoInitialize(NULL); //initialising COM
assert( SUCCEEDED(resH) );

CComPtr<IClass1> m_pClient;

resH = CoCreateInstance(_uuidof(Class1),NULL, CLSCTX_SERVER,
_uuidof(IClass1), (void**)&m_pClient);
assert( SUCCEEDED(resH) );

resH = m_pClient->OpenForm1();
assert( SUCCEEDED(resH) );

return resH;
}


PROBLEM: Everything runs fine under Win2000. But unfortunately under
WinXP my application that calls C++ wrapper Dll crashes without any
messages on CoCreateInstance(...


Do I need to add something to C# dll code (some attributes like
[ComVisible(true)])?


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.