开发者

Class cannot be embedded. Use the applicable interface instead

I'm using WIA to capture an image fron the scanner to the windows form. Here is the code I'm using:

private void button2_Click(object sender, EventArgs e)
{
    const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
    CommonDialogClass wiaDiag = new CommonDialogClass();
    WIA.ImageFile wiaImage = null;

    wiaImage = wiaDiag.ShowAcquireImage(
            WiaDeviceType.UnspecifiedDeviceType,
            WiaImageIntent.GrayscaleIntent,
            WiaImageBias.MaximizeQuality,
            wiaFormatJPEG, true, true, false);

    WIA.Vector v开发者_StackOverflow社区ector = wiaImage.FileData;

    Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
    i.Save(@"D:\prueba1.jpeg");
}

When trying to run this little test, I get this error:

Interop type 'WIA.CommonDialogClass' cannot be embedded. Use the applicable interface instead.

And this:

'WIA.CommonDialogClass' does not contain a definition for 'ShowAcquireImage' and no extension method 'ShowAcquireImage' accepting a first argument of type 'WIA.CommonDialogClass' could be found (are you missing a using directive or an assembly reference?

I'm guessing the second error is being risen because of the first error, right?

Any suggestions on how to fix this?


The 2nd error is caused by the first one. The Embed Interop Types feature only supports embedding interfaces, not classes. Other than just setting that option on the WIA reference to False and deploy the interop library, you could also fix it like this:

 WIA.CommonDialog wiaDiag = new WIA.CommonDialog();

Unintuitive but creating COM interfaces with the new operator is allowed. You need to prefix the namespace name because CommonDialog is ambiguous with the Winforms CommonDialog class.


http://digital.ni.com/public.nsf/allkb/4EA929B78B5718238625789D0071F307

This error occurs because the default value is true for the Embed Interop Types property of the TestStand API Interop assembly referenced in the new project. To resolve this error, change the value of the Embed Interop Types property to False by following these steps:

Select the TestStand Interop Assembly reference in the references section of your project in the Solution Explorer.
Find the Embed Interop Types property in the Property Browser, and change the value to False

Related Links: KnowledgeBase 595FQJPI: Can I Use Visual Studio 2010 with TestStand and Call .NET Framework 4.0 Code Modules?


Simply, you just choose the error assembly into Solution Panel/References. Then, press Alt-Enter (Properties), find "Embed Interop Type" and set its value to "False" if it True Brgs !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜