Visual Studio upgrade to .NET 4 - error with 'inherits Microsoft.Office.Interop.Excel.ApplicationClass'

I have a Visual Studio project that is an interactive Windows forms application to import data from an Excel file.
In the process of upgrading the project from VS 2008 to VS 2013, from .NET 2 to .NET 4 and changing the reference Microsoft.Office.Interop.Excel from pointing to an 'Office12' folder to an 'Office14' folder to get the latest and greatest Excel features, I got the following error:
Reference to class ‘ApplicationClass’ is not allowed when its assembly is linked using No-PIA mode.
This was due to one of the files having the following line:
Inherits Microsoft.Office.Interop.Excel.Application Class
Apparently, for .NET 4 and Visual Studio, the default action is to set EmbedInteropTypes to TRUE when I removed and added the updated reference Microsoft.Office.Interop.Excel.

Is there a way in Visual Studio to set EmbedInteropTypes to FALSE for this reference without editing the .vbproj file outside of Visual Studio?  Or, should I be doing something differently to resolve this error?  
Even after a manual edit of the .vbproj file, I am getting the warning '... is not CLS-compliant because it derives from 'ApplicationClass', which is not CLS-compliant.  How do I resolve this warning or can I ignore it?
pharringtontaberAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
First, you should not set the reference by pointing to a folder. Do it through the Reference window by selecting the target version in the COM tab. The Interop for the target version should be automatically referenced when you do so. If you still get the same error, then the Excel Interop/PIA (a dll that is used as a bridge between .NET and COM) has not been installed on your computer. It is usually installed by default when you install Excel or Office. If not, relaunch the installation and make sure that the option to install .NET components is checked.

But why do you want to set EmbedInteropTypes to False? There is a reason why True is the default. True is a lot more insteresting, because everything is included in your application when you compile it. The user does not need to have the PIA installed on his station in order for the application to run.
pharringtontaberAuthor Commented:
I added the reference on the COM tab to the 'Microsoft Excel 14.0 Object Library' which has a path of C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0_...\Microsoft.Office.Interop.Excel.dll and removed the reference to the dll that had been under the Visual Studio folders.
When I try to build the application, the file CigXLS.vb has the following line:
Inherits Microsoft.Office.Interop.Excel.ApplicationClass (which worked in .NET 2.0)
which causes the following error:
Reference to class 'ApplicationClass' is not allowed when its assembly is linked using No-PIA mode.
and the warning:
'CigXLS' is not CLS-compliant because it derives from 'ApplicationClass', which is not CLS-compliant.

What else do I need to change to resolve the error and possibly the warning? I did not write the original code. I am just trying to maintain some code written by someone who is no longer around.
pharringtontaberAuthor Commented:
The other option that I just tried is to change the 'Target Framework' to '.NET Framework 3.5' and the error goes away, but the warning still exists.  This is not a long-term solution as I have read that VS 2013 will require at least '.NET Framework 4.0'.   I will just have to resolve the problem differently when I am forced to so that I can get this application built in VS 2012.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Jacques Bourgeois (James Burger)PresidentCommented:
Inherits from Application instead of ApplicationClass.

The warning might not disappear however, because COM objects are not built to be CLS-compliant. This means that they do not follow the Common Language Specification that they use features that some .NET languages cannot use. VB does not have this problem however, at least with Office, so you can disregard the warning.

If it is still there and you want to get rid of it, this can usually be done by making sure that you have the following line in the AssemblyInfo.vb file in the My Project directory: <Assembly: CLSCompliant(False)>
Jacques Bourgeois (James Burger)PresidentCommented:
I was writing my last post while you were sending your's.

When you talk about VS2013, do not say "will". It has been around for 2 years. It "does" support the framework from version 2.0 up. But when you install it, it installs 4.5, which includes 4.0, but not the previous versions. You have to install them separately if they are not already installed on the development computer.

As for version 2015, it is in preview right now, and my understanding is that it does not support the older versions of the framework yet. But it should in the release version. This is still preview information however, and things can change a lot between the preview edition and the final release.
pharringtontaberAuthor Commented:
Thanks for the clarification. I think that I will stick with the Target Framework of .Net 3.5 for as long as possible for this application so that I do not have to rewrite it. In our group, we are using VS2012 but I do not know of any plans to start using VS2013 so I do not have to face that upgrade yet.
pharringtontaberAuthor Commented:
I missed your earlier comment about inherits, but I just tried it. I changed:
Inherits Microsoft.Office.Interop.Excel.ApplicationClass
to
Inherits Microsoft.Office.Interop.Excel.Application
Now I get the following error and then a bunch more:
Classes can inherit only from other classes.
I think that I will have to stick with .NET 3.5 until I find a solution that works for .NET 4.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
You usually do not have to rewrite most applications when moving from one version of the framework to another.

It has been my experience, and the experience of the hundreds of professional programmers I have trained since framework 1.0, that things go smoothly if you never skip a version of the framework and Visual Studio. But they can become problematic if you wait too long before making the jump.

For instance, a lot of programmers are still on Visual Studio 2008 and program thousand of lines of code with the OracleClient namespace classes. Since Visual Studio 2010, there is a warning when you do so, telling you that it is obsolete, that it will eventually not be supported, and telling about the alternative. They do not have that warning in 2008.

These programmers will have to rewrite everything the day they will be force to move to a newer version of the framework. Those who have moved to VS2010 or later have already started to use the alternative, and adapt the old code slowly but surely as they maintain it. The day OracleClient won't be there anymore, they will be ready.

I suggest to my students to always install one of the free editions  (Express or Community) of the latest version of Visual Studio on their development computer. You can have many versions installed at the same time on the same computer without any problem (I have 2010-2012-2013 on the portable I sometimes use for my training). They load their project in the newest version from time to time, just to make sure that it will still work in newer versions of the framework. That way, they can be prepared for changes, or have the necessary arguments to bring to their superiors in order to move to a newer version for production work before it is too late.

Hitting the road soon. I won't be there for most of the day, and maybe not at all in the next 2 days.
pharringtontaberAuthor Commented:
I would appreciate being able to completely resolve this in .NET 4.0 instead of just leaving this application at .NET 3.5.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.