日期:2014-05-17  浏览次数:20905 次

C#引用一个Com组件,为什么Interop的属性要设置为false才能用呢?
我建立一个C#的工程,Add reference增加一个com组件的引用,在这个引用的属性栏里面,我必须得把Embeded Interop Type项设置成false,然后这个com组件才能被调用。默认值true的话,常常会有运行时错误。

这是为什么呢? 什么时候应该用True,什么时候应该用False呢? 看起来False比True好用啊

------解决方案--------------------
出现这种情况时,最好设置为False
当设置为True时,该COM组件的交互类型信息将在编译时被嵌入到项目的类库中。
当设置为False时,该COM组件的交互类型都需要一个额外的Primary Interop Assemblies(PIA)来提供。但是Net中已经将其封装了,对开发者而言是透明的。
参考
http://stackoverflow.com/questions/8156488/what-does-reference-was-created-to-embedded-interop-assembly-mean
http://blogs.clariusconsulting.net/kzu/check-your-embed-interop-types-flag-when-doing-visual-studio-extensibility-work/