Word 2010 addin does not load, vsto 2010 - visual-studio-2010

Our development machine is 64 bit hardware running Windows 7 Professional N (64 bit), 64 bit Office Professional 2010 and Visual Studio Professional 2010.
We created a Word 2010 (Application Level Add-In) using .NET Framework 4, Ribbons and Windows installer targeting Office 2010. We followed everything from the official MSDN online tutorials to the dot several times. For our installer we selected .NET 4 client profile and Windows installer 3.1 as prerequisites, since Office 2010 has VSTO 4.0 runtime installed and .NET framework 4 has no-PIA functionality. In launch conditions we checked for Office 2010 Shared PIA and Word 2010 PIA availability using the appropriate component ids. Additionally we checked for VSTO runtime availability as is laid out in the MSDN article.
Our Add-In loads and executes with full functionality from ONLY within Visual Studio debug (F5). Building the setup project creates the Windows installer (msi). Installing it installs the Add-In on the machine without any errors. However after installing the Add-In when we try to open any Word 2010 document, we are witnessing the following behavior:
We try to open any Microsoft Word 2010 document, Word 2010 startup screen shows up and we can see our Add-In being loaded "Loading [Our] Add-In" but then Word 2010 does not open. The startup screen disappears and no error message is displayed.
Opening the word document for the second time just fires up this message (no word 2010 startup screen this time):
Word experienced a serious problem with the '[Our] word addin' add-in. If you have seen this message multiple times, you should disable this add-in and check to see if an update is available. Do you want to disable this add-in?'
Clicking on No, briefly fires up the startup screen of Microsoft Word 2010 and then it stops loading again (disappears). Clicking on Yes, opens Word 2010 with the [Our] add in disabled. Verified by clicking File-Options-AddIns. Looked under Disabled Application Add-Ins
Setting VSTO_SUPPRESSDISPLAYALERTS=0 and VSTO_LOGALERTS=1 was of no use either. We checked our Temp directory, there were no logs.
Since the above method did not work I downloaded the sample project from this link named 'Deploying a VSTO 2010 solution for Office 2007/2010 using Windows Installer' and used the appropriate project found under Office Development - Setup and Deployment Projects Samples\FX40\AddIn Deployment\All User Install for 64-bit Office.
Initially I tested the solution to correctly load the demo Excel 2010 Add-In project by creating and running the installer (msi) Then we added our Word AddIn project to the solution file by file and built it correctly (CTRL+SHIFT+B). It even ran from Visual Studio debug (F5) correctly. Then we reconfigured the existing set up project to delete the demo Excel project and load our word Add-In's primary output, [OurAdd-In].vsto and [OurAdd-In].dll.manifest files. We refreshed project dependencies and took appropriate steps to exclude relevant files. We kept the registry checks intact and added launch conditions to check for Word 2010 PIA.
The installer built successfully and installed without errors but unfortunately we witnessed the exact same behavior of Word 2010 as described previously.
We also tried debugging using Windows event logging. I found this event with event id 4096:
************** Exception Text **************
Microsoft.VisualStudio.Tools.Applications.Deployment.FrameworkVersionMismatchException: <compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.0" profile="Client" supportedRuntime="4.0.30319" />
<framework targetVersion="4.0" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
We need to create an installer for our Word Add-In for both 32-bit and 64-bit Word 2010.
I've researched further and this is what I've found.
I used AddInSpy to investigate further and this is the debug information I get ...
<addIn>
<Item>1</Item>
<Host>Word</Host>
<Running>true</Running>
<Loaded>false</Loaded>
<Type>VSTO</Type>
<FriendlyName>[OURADDIN]WordAddIn</FriendlyName>
<ProgID>[OURADDIN].WordAddIn</ProgID>
<CLSID>n/a</CLSID>
<Manifest>C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN]WordAddIn.vsto|vstolocal</Manifest>
<DllPath>C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN]WordAddIn.dll</DllPath>
<LoadBehavior>3</LoadBehavior>
<RegHive>HKCU</RegHive>
<AssemblyName>?</AssemblyName>
<CLR_version>?</CLR_version>
<Exposed>false</Exposed>
<Interfaces>?</Interfaces>
<FormRegions>n/a</FormRegions>
<VSTOR>2008</VSTOR>
<Installed>?</Installed>
<PubVer>n/a</PubVer>
<Status>Alert</Status>
<StatusDescription>Add-in DLL path is not found. System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN].dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN].dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at AddInSpy.AssemblyScanner.GetAssemblyInfo(String fileName, String hostName, Boolean isVstoAddIn)
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Users\Interance\Downloads\AddInSpy\AddInSpy.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Interance-PC\Interance
LOG: Where-ref bind. Location = C:\Program Files\Microsoft\[OURADDIN]Setup2010\[OURADDIN].dll
LOG: Appbase = file:///C:/Users/Interance/Downloads/AddInSpy/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This is an inspection only bind.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft/[OURADDIN]Setup2010/[OURADDIN]AddIn.dll.
ERR: Failed to complete setup of assembly (hr = 0x8013101b). Probing terminated.
</StatusDescription>
</addIn>
I believe what is interesting above are the following lines
This assembly is built by a runtime newer than the currently loaded
runtime and cannot be loaded...
Assembly manager loaded from:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
In my understanding Word 2010 is trying to load my Add-In using Assembly Manager and Machine Configuration File referencing F/W version v2.0.50727 when it should be referencing \Framework64\v4.0.30319\ since I've built my Add-In using .NET 4. As a consequence is the error message 'This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded...'
I think this might be the source. Any thoughts why this might be happening and how to resolve it?
Hmm... I think I should have mentioned this earlier but I'm using open xml 2 sdk to create/read word files in my Word 2010 Add-In with .NET f/w 4. I've followed the documentation provided here. If you scroll down that page you will find in the section Introducing Open XML SDK Format Architecture subsection system support layer that it supports .NET f/w 3.5 and currently the Open XML Format SDK is based on Standard Ecma-376.
Furthermore, after couple of hours of squinting and reading lots of articles such as Chris Rae's detailed article where he states that Office 2010 uses another standard, ISO/IEC 29500, as its default file format while Office 2007 supports ECMA-376. Further it states that:
ISO/IEC 29500 is a direct descendant of ECMA-376. It's so direct a descendant, in fact, that ECMA-376 2nd edition is identical to ISO/IEC 29500.
I found that Open XML SDK Format Architecture system support layer supports .NET f/w 3.5 and currently the Open XML Format SDK 2 is based on Standard Ecma-376.
Link for Reference
Therefore I'm just wondering if Open XML SDK 2 is the source of my problem? Since ISO/IEC 29500 is descendant of ECMA-376, can I use Open XML SDK 2 to create/modify word 2010 documents in my code?
Is that why the assembly manager and machine configuration file are loading from framework\v2.0.50727\ and not from \Framework64\v4.0.30319\?

Open XML SDK 2 was the cause, I avoided Open XML SDK 2 and my AddIn works perfectly now. Rebuilt my project from scratch using Microsoft Interop to read/write Microsoft Office 2010 documents.
Issue is that there is not much documentation around for developers to read. I've done the grunt work reading articles and figuring out the problem myself.
Hopefully others would not have to face the same ordeal.

See maybe the following link will help... How to create a custom install program.
It helped me, and I had a somewhat similar scenario (a Word 2010 Addin + Open XML SDK 2.0 - deployed on machine running from Windows XP Service Pack 3 32 bit to Windows 7 Professional 64 bit).
Hope it helps you.

Related

Installing VS 2015 Community edition makes VS 2013 to throw errors

I have downloaded and installed the free Community Edition of VS 2015 from Microsoft. After the install, I am unable to use VS 2013 Professional, which was working fine before the install. The start page shows, "Content Load Error". The solution explorer shows the following errors:
An exception was encountered while constructing the content of this frame. This information is also logged in "C:\Users\VeluMain\AppData\Roaming\Microsoft\VisualStudio\12.0\ActivityLog.xml".
Exception details:
System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.VisualStudio.Shell.Interop.IVsShell5.LoadPackageWithContext(Guid& packageGuid, Int32 reason, Guid& context)
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage()
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()
I searched in Google, but couldn't find any solution.
Thanks
It's possible that one of your plugins for VS2013 has been broken by the VS2015 installer. For example I had an issue where VS2015 installer also installed .NET Framework 4.6 which alters the .NET Framework 4.5.1 DLLs, I guess there's a chance it could be the same kind of thing...
Try running VS2013 in Safe Mode (i.e. without plugins). If this works fine then you know it's one of your plugins that is causing the issue, you should then use a process of elimination to determine which one is the culprit. If it doesn't work then you might want to reinstall VS2013.

What does "Wrap the file in another setup package through Visual Studio or other Windows Installer aware setup editor" mean?

I am working in Visual Studio 2012 and I was missing the "Microsoft.Office.Interop.Excel" assembly. After downloading the missing exe from http://www.microsoft.com/en-us/download/details.aspx?id=3508,
the instructions are as follows:
"Wrap the O2010pia.msi file in another setup package through Visual Studio or other Windows Installer aware setup editor"
I ran the exe, but the missing assembly is still missing from Visual Studio.
I am quite new to development and after googling for a while, I am no closer to understanding what this means. I would greatly appreciate some insight.
You did not read it correctly. The page says "Use one of the following installation methods". The one you are asking about is what you do when you create an installer for your program so the PIA also gets installed on your client's machine. You are not there yet.
You should not be doing this anymore, PIAs are outdated since VS2010. Replaced by the "Embed interop types" feature, aka "NoPIA". Project, Add Reference, click COM, select the "Microsoft Excel xx.x Object Library" entry where xx.x is the version number of Office you've got installed on your machine. This automatically adds the Microsoft.Office.Core and Microsoft.Office.Interop.Excel references to your project. With their Embed Interop Types property set to True so you don't have to install anything on the client's machine.
If you don't see this entry then you will need to install Office on your machine. Required to add the reference and to debug and test your code.

Developing in Visual Studio 2010 and Sharepoint 2007. Using new SPSite throws errors

I'm re-writing a console application using Visual Studio 2010. The original application was written using Visual Studio 2008 and works OK, but has no tests associated with it. Hence, the idea of re-writing it with tests.
Both applications are working with a Sharepoint 2007 site.
The project compiles but when I try and run it the code below is throwing errors.
SPSite spsite = null;
SPSecurity.RunWithElevatedPrivileges(delegate() {
spsite = new SPSite("http://sharepointdev");
});
return spsite;
I'm running this on Windows Server 2008. I've set the platform target of the build to be x86 (this is in the properties of my project) and in Security I've checked that this is a full trust application. I'm also running the project as an administrator. I've also set the .NET Framework to be 3.5
Is it just a case that SharePoint 2007 just doesn't want to play with Visual Studio 2010, or is there something else I've not yet considered?
I've tried searching on the web and stackoverflow but all the articles I've seen deal with trying to get Visual Studio 2010 to work with Sharepoint 2010.
The exact error I get is 'Object reference not set to an instant of an object' with the debugger high-lighting the SPSecurity call.
If I just use this code
using(SPSite spsite = new SPSite("http://sharepointdev")){
Then I get a FileNotFoundException, which isn't exactly true! I've got plenty of applications that do find a site using that URL. What I suspect the error message is trying to say is that my 2010 application is not being allowed to access the site, but I've not found any clues as to why that should be.
Any clues, hints or suggestions gratefully accepted.
EDIT
I've lifted the code from my VS 2010 project and dropped it into a new VS 2008 project and it ran straight-away.
FURTHER EDIT
I created a simple little console application in VS 2010. By default it uses .NET Framework 4, I had to set this to .NET Framework 3.5. I also set the platform target to be 'Any CPU' and it works. This makes me wonder if there is an issue with the Test Project associated with my first application?
I re-created the console application but this time without a Test Project associated with it (the test project was a class library and worked with NUnit). It ran with no problems. I guess the problem lies within the test project and something there that the solution doesn't like. Probably there's a build there it doesn't like
TL;DR; answer: Switch to Any CPU build - don't choose x86.
I've run into this problem before with a console utility. I got the same FileNotFound error but it's referring to the DLL, not your SharePoint site. Digging a bit I discovered a deeper error of BadImageFormat and realized it was complaining about a DLL or EXE. I guessed it was due to the linking from x86 to MSIL. There's a lot of things that have to happen to marshal calls between the two and I guess it led to an incompatibility. When I switched it (and verified all my support library projects) built to MSIL/Any CPU the application worked with no problems and no other changes.
I use Visual Studio 2010 to develop for SharePoint 2007 all day for a long time now and the only problems I've encountered aren't related to that combination. More often than not it's a quirk of a 3rd party add-on I'm using. For almost all of my development I start with the WSP Builder templates but they are buggy and have a few quirks you have to work around (some severe enough to take down your SharePoint server) so I don't blame VS 2010 directly.

Visual studio redistributable & side-by-side / DependentAssembly error

(I'm running Windows7 and using Visual Studio 2010.)
I'm using ClamAV in a .NET Azure project, and I'm running into side-by-side errors whenever I run clamd.exe, either through my code or by running clamd.exe on it's own.
In Visual Studio 2010 I am getting the error:
Win32Exception was unhandled The application has failed to start
because its side-by-side configuration is incorrect. Please see the
application event log or use the command-line sxstrace.exe tool for
more detail
And in Event Viewer I get:
Activation context generation failed for
"C:\Users\pconerly\code\AntiVirus_source\WorkerRole\clamav\clamd.exe".
Dependent Assembly
Microsoft.VC80.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="8.0.50727.6195"
could not be found. Please use sxstrace.exe for detailed diagnosis.
When I searched for "8.0.50727.6195" it led me to the 2005 redist, so I downloaded it
http://www.microsoft.com/download/en/details.aspx?id=3387
After a restart I am still getting the side-by-side error. Additionally, I think that the redist installer is not completing it's install-- like it's seeing visual studio 2010 and saying "oh, that's good enough, no need for me to install". I haven't tried uninstalling 2010 and using 2005, because the rest of my Dev team is using VS 2010.
What's the deal? How can this be fixed? I'm ready to pull out my hair.
The link Timores posted is the update for Visual Studio. The actual redistributable package is this:
http://www.microsoft.com/en-us/download/details.aspx?id=26347
The version you mention is actually at found here
Microsoft Visual Studio 2005 Service Pack 1 MFC Security Update
Timores is right: the redist should be this one, which is related to this KB entry
As you can see there, msvcr80.dll has been updated to version 8.0.50727.6195.
It is the "security update" of the "SP1" of the 2005 C++ runtime..
Your exe probably requires (through an internal manifest) that specific version.
If it is not found on the system (there's a lot of places searched for) nor in the current folder (with a suitable manifest aside) it won't load the exe since it is not able to "activate the context", that is load the specific DLL required in the manifest.
I had similar issues when my system got updated (windows updates) and the newly compiled EXEs were not working with an old-versioned runtime placed on the same folder.
I had to update msvcr80.dll and its manifest (which I found deep in \windows\winsxs) to make everything work.
Context activation is a tricky matter, anyway :)
HTH

Visual C++ 2010: Changes to MSVC runtime deployment (no more SxS with manifest)

Where can I find some official note, kb article or other documentation describing changes to the Visual Studio 2010 C/C++ runtime linking and deployment policy?
Under Visual Studio 2008 (with the VC90 runtime) a manifest was embedded in native images, and the runtime libraries were deployed as side-by-side assemblies (WinSxS). This caused problems when rebuilding a native exe or library using VS 2008 SP1, in that an updated version of the C++ runtime was required by the embedded manifest.
For VS 2010 and the MSVCR100 runtime version, the policy seems to have changed completely.
The file msvcr100.dll and the other C/C++ runtime libraries are no longer install as SxS assemblies.
When compiling under VS2010, no runtime 'dependency' entry is added to the embedded manifest, meaning that any version of msvcr100.dll might be loaded at runtime.
On machines with .NET 4 installed, the matching runtime is named msvcr100_clr0400.dll, and won't be loaded by native code, though a copy renamed to msvcr100.dll works fine. I think this means any process with C/C++ code will always have two versions of the same C/C++ runtime loaded.
This seems to be a significant change in policy, backtracking from the SxS deployment and manifest dependencies we had under VS 2008. Could anyone shed more light on what changed, and perhaps point to some documentation, a readme or blog post that describes these changes, the motivation and related impact?
It think it's better this way - the strong version manifest and SxS deployment was a nightmare - but I'm surprised at these unexpected and seemingly undocumented changes in VS 2010.
Bonus question: How can I compile my C++/CLI library under VS 2010 to link to msvcr100_clr0400.dll instead of msvcr100.dll? This idea is that the C++/CLI assembly should run with no dependencies other than that installed by .NET 4 (without static linking).
You already answered most of your question, the side-by-side deployment of the CRT was a nightmare that got way too many programmers in trouble. Microsoft agreed and gave up on it for the VS2010 release. It's back to a DLL in c:\windows\system32, named msvcr100.dll. And msvcp100.dll, vcomp100.dll, atl100.dll, mfc100.dll, mfcm100.dll, the other runtime support DLLs. The way it was for VS2003 and earlier editions. Now it is again the user's burden to sort out a DLL Hell problem. The person least likely to be able to do so but they do tend to have a budget to pay for support. Unlike programmers that need to get help from a free web site :)
But you can help, app-local deployment is now again enabled, you can deploy msvcr100.dll in the same directory as your main EXE. That was explicitly checked and forbidden in previous versions. App-local has some niceties, it isolates you from well-meant but unfortunate updates that break your app. Albeit that you are now yourself responsible for getting updates deployed that fix a security hole. If that's uncomfortable then deploy and rely on the copy in the system directory.
Do not try to link to msvr100_clr0400.dll, that's a private copy for use by the CLR. Much like msvcr.dll is a private copy for use by Microsoft DLLs. You don't have the .lib file you need to link to these DLLs.
Just a couple of links about the topic – I hope someone will find them useful:
Visual Studio 2010 changes for VC++ (part 5)
Visual C++ Application: How to use manifests and re-distributable assemblies?

Resources