有个项目,实施的时候需要用vb根据现场的不同重新编译一个com组件GetData.dll。这个com组件要转换成。net程序集的方式被其他。net程序调用。
问题出现在这里:
如果我用tlbimp.exe GetData.dll /out:Interop.GetData.dll重新生成的dll会报错。
而用visual studio express IDE新建一个工程然后添加引用的方式加入,让IDE自动生成com组件的.net程序集,这样产生的Interop.GetData.dll却不报错。
为什么啊。

解决方案 »

  1.   

    报错是没有从Interop.GetData.dll找到getdata.dll中的某个类。
      

  2.   

    那应该是这个库又依赖了另一个COM库。
      

  3.   

    会涉及第三方库的,这个会有影响吗,为什么用IDE方式生成就没问题呢。
      

  4.   

    同意ls,先应该用 regsvr32.exe注册COM
      

  5.   

    我记得IDE也应该是调用tlbimp.exe的。
    你可以这样,将tlbimp.exe改名成tlbimp1.exe。
    然后编写一个小程序,叫tlbimp.exe,它将传入的参数保存下来(从Main()的args里面得到),然后调用tlbimp1.exe(Process.Start()),传入对应的参数。然后看看这个程序能拦截出IDE怎么调用的。
      

  6.   

    在安装的机器上我会先regsvr32 GetData.dll的。然后再用tlbimp生成对应的。net dll
      

  7.   

    我试试看,你别走开啊。用/refrence
      

  8.   

    你用 Dependency Walker 这个工具分析下,你都依赖哪些库
    除了微软的,你都需要带到部署机器上,然后全部注册,tlbimp这样。
      

  9.   

    好的,不过要说明的是我到的第三方库肯定都安装到要部署的机器上了的,这个不会是问题。
    问题是我vb做的dll引用了第三方库。而这导致了用tlbimp生成的inerop不能使用,而用IDE生成的可以。
    另一个实验是用vb作的dll不涉及引用第三方库,如此用tlbimp生成inerop和用IDE生成的都可以用。
      

  10.   

    所以fangxinggood是不是误会我的意思了。
      

  11.   

    具体的我也不清楚了。但有点怀疑,你的IDE是在部署端,只通过browser引用你的vb dll也没有问题吗?
      

  12.   

    查了查:tlbimp不是任何情况都适用的,解决方案是手动编写MappingAlthough TlbImp is the preferred method for converting COM definitions to C#, it is not always possible to use it (for example, if there is no typelib for the COM definitions, or if TlbImp cannot handle the definitions in the typelib). In these cases, the alternative is to manually define the COM definitions in C# source code using C# attributes. Once you have created the C# source mapping, you simply compile the C# source code to produce the managed wrapper. http://www.cnblogs.com/DylanWind/archive/2010/11/24/1886714.html
      

  13.   


    谢谢,这我也看到过,但是IDE使用的也是用tlbimp生成的呀,这很奇怪啊。这句话是要求不用tlbimp来生成了。