Tuesday, 15 April 2014

com - Is PIA embedding broken in .NET 4.0 beta 2? -


Some time ago, I had written some word interop examples in Visual Studio Beta 1, and had set Microsoft's references <<

To embed Office.Interop.Word (set the" Embed Interp "type = correct in the reference properties). This work is fine, and I did not run them for some time ... to date.

Of course, now I am running under both Visual Studio 2010 and Beta 2 of .NET 4.0 - and it seems to be somewhat broken.

There is a code in question (only dummy example code):

  using Microsoft.Office.Interop.Word; Class Word Promotion 1 {Static Wide Men () {App App = New Application {Visual = true}; App.Documents.Add (); Document Doctor = App. Active document; Article paras = Doctor. Paragraph Add (); Paragraph Range. Text = "Best wishes for C # 4"; Object filename = "demo.doc"; Object format = wdSaveFormat.wdFormatDocument97; Doc.SaveAs (filename: ref filename, file format: riff format); Doc.Close (); App.Quit (); }}  

Exceptions of this time get me the most , when the "embed interop type" is set to "right" or "/ l "I'm linking to the command line:

  System.MissingMethodException: Method not found: 'Zero Microsoft.office.inIntext.Word._app.set_visible (boolean)'  

Very rarely, it works - which is even more bizarre.

If I remove the "FT type type" to "false" (or "

if I remove the" visible = true "property setter then it also works ... But I have know that property ... this is also suggested by Intelligence!

Unless I have done complete testing on many boxes, I can confirm that my netbook (Windows 7 Vista, but still .NET 4.0 beta 2) looks at the same problem.

Is there a need Is it broken or .NET 4.0 beta 2?

Great grip! It is indexed properties Our code looks like a bug in generation (one is not known, so thanks for reporting it!) I have tried to build the latest internal VS 2010 and this is the same replica.

What happens is that if you use an object analyzer, the following code is generated:

  Away Day << g__initLocal19 = (app) catalyst.createININSANCE (Type.GetTypeFromCLSID (New Guid ("000209FF-0000-0000-C000-000000000046"))); & Lt; & Gt; G__initLocal19.set_Visible (true);  

However if you set visible = true in a separate statement (without the object initializer), the following code is emitted:

  application application = (application) Activator.rate instence (type gate typefrum CLSID (new guide ("00020 9FF -0000-0000-C 2000-000000000046"))); Application.Visible = true;  

The PIA defines only the lower one, so when you are using an object initiator, it fails. For now the solution is to set visible in a separate statement that should work fine.

I have logged a bug about this again thanks again!


No comments:

Post a Comment