By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Need help adding reference to Microsoft.Office.Core

P: n/a
Hi all,

Using C#, I've created a simple wrapper class for using Excel. I have
Office Pro 2003 installed on my devel machine. The wrapper class works
great, reading and writing to/from Excel. To do this, I created a
reference to "Microsoft Excel 11.0 Object Library", and have a "using
Excel;" directive.

I decided to add a method for creating a TextBox using the
Shapes.AddTextBox method, which requires a
Microsoft.Office.Core.MsoTextOrientation as a parameter. Unfortunately,
I can't find what I need to reference to get the Microsoft.Office.Core
namespace into my project. I've tried adding references to "Microsoft
Office 11.0 Object Library" in COM, but that didn't provide me with the
needed namespace.

I then added a reference to "Office" (version 11.0.0.0) in the GAC, and
received the following errors:

D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(303,10 ) : error CS0012: The
type 'Microsoft.Office.Core.MsoTextOrientation' is defined in an
assembly that is not referenced. You must add a reference to assembly
'office, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.
D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(303,20 ) : error CS1502: The
best overloaded method match for
'Excel.Shapes.AddTextbox(Microsoft.Office.Core.Mso TextOrientation,
float, float, float, float)' has some invalid arguments
D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(305,17 ) : error CS1503:
Argument '1': cannot convert from
'Microsoft.Office.Core.MsoTextOrientation
[c:\WINDOWS\assembly\GAC\Office\7.0.3300.0__b03f5f7 f11d50a3a\Office.dll]'
to 'Microsoft.Office.Core.MsoTextOrientation []'

Any help would be greatly appreciated,
Michael

May 26 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Michael Russell wrote:
Hi all,

D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(303,10 ) : error CS0012: The
type 'Microsoft.Office.Core.MsoTextOrientation' is defined in an
assembly that is not referenced. You must add a reference to assembly
'office, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.
D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(303,20 ) : error CS1502: The
best overloaded method match for
'Excel.Shapes.AddTextbox(Microsoft.Office.Core.Mso TextOrientation,
float, float, float, float)' has some invalid arguments
D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(305,17 ) : error CS1503:
Argument '1': cannot convert from
'Microsoft.Office.Core.MsoTextOrientation
[c:\WINDOWS\assembly\GAC\Office\7.0.3300.0__b03f5f7 f11d50a3a\Office.dll]'
to 'Microsoft.Office.Core.MsoTextOrientation []'

Any help would be greatly appreciated,
Michael


No one has any input? This is a real problem for me, I could really use
some pointers.

Michael
May 27 '06 #2

P: n/a
Hi Michael,

Without seeing your code also, it is hard to tell what the exact problem is.
Maybe something accidentally got out of whack with changing references and
all. Try this to get things back to normal:

1. Delete the "Excel", "Microsoft.Office.Core", and "VBIDE" references from
your project.
2. Right-click on References and select "Add Reference"
3. Click the COM tab.
4. Select Microsoft Excel 11.0 Object Library and click OK.
5. You should see Excel, Microsoft.Office.Core, and VBIDE in your
references list.

If you don't see those items (from #5) in your references list, you may not
have Office PIAs installed properly. You may have to uninstall and
reinstall them. Another alternative is to go into the Excel installation
process and find the process that allows you to select which components are
installed. There is an option to install .NET or Managed code
programability options, which will ensure PIAs are installed for you.

Here's some code I ran to try to reproduce your problem. However, following
the procedures I used above, it worked just fine:

using System;
using System.Collections.Generic;
using System.Text;

namespace OfficeAppTest
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Core.MsoTextOrientation orientation =
Microsoft.Office.Core.MsoTextOrientation.msoTextOr ientationHorizontal;
}
}
}

Your error message also indicates that it is possible that the method you
are trying to use takes only a single instance of MsoTextOrientation, but
you are trying to give it an array of MsoTextOrientation
(MsoTextOrientation[]), which are different types.

If you do post some code, you should make it the smallest example possible
that I can cut-and-paste so I can see the problem for myself. A large
listing that doesn't compile is often not much use.

Joe
--
http://www.csharp-station.com

"Michael Russell" <mr*******@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP02.phx.gbl...
Michael Russell wrote:
Hi all,

D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(303,10 ) : error CS0012: The
type 'Microsoft.Office.Core.MsoTextOrientation' is defined in an assembly
that is not referenced. You must add a reference to assembly 'office,
Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(303,20 ) : error CS1502: The
best overloaded method match for
'Excel.Shapes.AddTextbox(Microsoft.Office.Core.Mso TextOrientation, float,
float, float, float)' has some invalid arguments
D:\Work\CSharp\ExcelWrapper\ExcelWrapper.cs(305,17 ) : error CS1503:
Argument '1': cannot convert from
'Microsoft.Office.Core.MsoTextOrientation
[c:\WINDOWS\assembly\GAC\Office\7.0.3300.0__b03f5f7 f11d50a3a\Office.dll]'
to 'Microsoft.Office.Core.MsoTextOrientation []'

Any help would be greatly appreciated,
Michael


No one has any input? This is a real problem for me, I could really use
some pointers.

Michael

May 27 '06 #3

P: n/a
Joe Mayo [C# MVP] wrote:
Hi Michael,

Without seeing your code also, it is hard to tell what the exact problem is.
Maybe something accidentally got out of whack with changing references and
all. Try this to get things back to normal:

1. Delete the "Excel", "Microsoft.Office.Core", and "VBIDE" references from
your project.
2. Right-click on References and select "Add Reference"
3. Click the COM tab.
4. Select Microsoft Excel 11.0 Object Library and click OK.
5. You should see Excel, Microsoft.Office.Core, and VBIDE in your
references list.
Tried this, VBIDE and Microsoft.Office.Core never appear in the list of
references.

If you don't see those items (from #5) in your references list, you may not
have Office PIAs installed properly. You may have to uninstall and
reinstall them. Another alternative is to go into the Excel installation
process and find the process that allows you to select which components are
installed. There is an option to install .NET or Managed code
programability options, which will ensure PIAs are installed for you.

Using Office 2003 setup, removed then reinstalled the .Net Programming
support for all the components of Office, the problem remains unchanged.
I also made sure that I've downloaded the SP and updates for Office 2003.

FWIW, while reinstalling the support from the CD, I noticed that it said
that the support is for version 1.1 of the .Net Runtime; the PIA
redistributable on Microsoft's web site also says that 1.1 is required,
no mention of 2.0 or "1.1 or higher". Perhaps this is my problem?

<Sample code deleted>

Your error message also indicates that it is possible that the method you
are trying to use takes only a single instance of MsoTextOrientation, but
you are trying to give it an array of MsoTextOrientation
(MsoTextOrientation[]), which are different types.

If you do post some code, you should make it the smallest example possible
that I can cut-and-paste so I can see the problem for myself. A large
listing that doesn't compile is often not much use.


The section of code where I need the Microsoft.Office.Core reference:

Excel.Shapes shapes = xlWks.Shapes;
xlShape = shapes.AddTextbox(
MsoTextOrientation.msoTextOrientationHorizontal,
(float)left, (float)top, (float)width, (float)height );

I don't think it's a problem with the code, but it won't compile because
I'm unable to get a reference to Microsoft.Office.Core.

Thanks,
Michael
May 28 '06 #4

P: n/a
"Michael Russell" <mr*******@hotmail.com> wrote in message
news:uO****************@TK2MSFTNGP04.phx.gbl...
Joe Mayo [C# MVP] wrote:
Hi Michael,

Without seeing your code also, it is hard to tell what the exact problem
is. Maybe something accidentally got out of whack with changing
references and all. Try this to get things back to normal:

1. Delete the "Excel", "Microsoft.Office.Core", and "VBIDE" references
from your project.
2. Right-click on References and select "Add Reference"
3. Click the COM tab.
4. Select Microsoft Excel 11.0 Object Library and click OK.
5. You should see Excel, Microsoft.Office.Core, and VBIDE in your
references list.


Tried this, VBIDE and Microsoft.Office.Core never appear in the list of
references.

If you don't see those items (from #5) in your references list, you may
not have Office PIAs installed properly. You may have to uninstall and
reinstall them. Another alternative is to go into the Excel installation
process and find the process that allows you to select which components
are installed. There is an option to install .NET or Managed code
programability options, which will ensure PIAs are installed for you.


Using Office 2003 setup, removed then reinstalled the .Net Programming
support for all the components of Office, the problem remains unchanged. I
also made sure that I've downloaded the SP and updates for Office 2003.

FWIW, while reinstalling the support from the CD, I noticed that it said
that the support is for version 1.1 of the .Net Runtime; the PIA
redistributable on Microsoft's web site also says that 1.1 is required, no
mention of 2.0 or "1.1 or higher". Perhaps this is my problem?

<Sample code deleted>

Your error message also indicates that it is possible that the method you
are trying to use takes only a single instance of MsoTextOrientation, but
you are trying to give it an array of MsoTextOrientation
(MsoTextOrientation[]), which are different types.

If you do post some code, you should make it the smallest example
possible that I can cut-and-paste so I can see the problem for myself. A
large listing that doesn't compile is often not much use.


The section of code where I need the Microsoft.Office.Core reference:

Excel.Shapes shapes = xlWks.Shapes;
xlShape = shapes.AddTextbox(
MsoTextOrientation.msoTextOrientationHorizontal,
(float)left, (float)top, (float)width, (float)height );

I don't think it's a problem with the code, but it won't compile because
I'm unable to get a reference to Microsoft.Office.Core.


I was able to get it to work like this:

Excel.Shapes shapes = xlWks.Shapes;
xlShape = shapes.AddTextbox(
Microsoft.Office.Core.MsoTextOrientation.msoTextOr ientationHorizontal,
(float)left, (float)top, (float)width, (float)height );

The only thing now is to get the reference to the Microsoft.Office.Core dll.
Something is keeping it from properly adding the right proxies to your
reference list. Here's something else to try:

1. Remove the Excel, Microsoft.Office.Core, VBIDE reference from your list.
2. Close down Visual Studio to make sure it isn't holding any file locks.
Are you using Visual Studio 2003? There was a problem with this on some
machines that was similar to this, which was incredibly difficult to fix.
3. Look in the directories of your project, looking for interop assemblies.
They are named Interop.*.dll. Delete the Interop.Excel.dll,
Microsoft.Office.Core.dll, and Interop.VBIDE.dll wherever you find them.
4. Maybe reboot after that, but I'm not sure that's necessary. Perhaps
just an old habit that sometimes worked. <grin>
5. Restart Visual Studio and re-add the Microsoft Office Excel 11.0 Object
Library reference.
6. Keep your fingers crossed if it properly added a reference to
Microsoft.Office.Core.dll.

The previous steps were the ideal situation. If they don't work, try to add
the reference back from the GAC, like you did before.

Then run and see if it works.

Joe
--
http://www.csharp-station.com
May 28 '06 #5

P: n/a
Joe Mayo [C# MVP] wrote:
"Michael Russell" <mr*******@hotmail.com> wrote in message
news:uO****************@TK2MSFTNGP04.phx.gbl...
Joe Mayo [C# MVP] wrote:

<snip>
I was able to get it to work like this:

Excel.Shapes shapes = xlWks.Shapes;
xlShape = shapes.AddTextbox(
Microsoft.Office.Core.MsoTextOrientation.msoTextOr ientationHorizontal,
(float)left, (float)top, (float)width, (float)height );

The only thing now is to get the reference to the Microsoft.Office.Core dll.
Something is keeping it from properly adding the right proxies to your
reference list. Here's something else to try:

1. Remove the Excel, Microsoft.Office.Core, VBIDE reference from your list.
2. Close down Visual Studio to make sure it isn't holding any file locks.
Are you using Visual Studio 2003? There was a problem with this on some
machines that was similar to this, which was incredibly difficult to fix.
3. Look in the directories of your project, looking for interop assemblies.
They are named Interop.*.dll. Delete the Interop.Excel.dll,
Microsoft.Office.Core.dll, and Interop.VBIDE.dll wherever you find them.
4. Maybe reboot after that, but I'm not sure that's necessary. Perhaps
just an old habit that sometimes worked. <grin>
5. Restart Visual Studio and re-add the Microsoft Office Excel 11.0 Object
Library reference.
6. Keep your fingers crossed if it properly added a reference to
Microsoft.Office.Core.dll.

The previous steps were the ideal situation. If they don't work, try to add
the reference back from the GAC, like you did before.

Then run and see if it works.

Joe


Joe,
Thanks for following up on this. I'm not running VS, but SharpDevelop
2.0. To verify the problem, though, I downloaded Visual C# Express and
loaded my code into it to see what would happen. Sure enough, when I
added the reference to Excel in COM, the references to
Microsoft.Office.Core and VBIDE appeared just as they should.

So, the problem appears to be limited to SharpDevelop, and I've
submitted this to them to find out what's going on. Again, thanks for
the follow-up, it helped to have someone verify that I wasn't doing
something wrong in my part.

Michael
May 28 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.