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-InsSetting
VSTO_SUPPRESSDISPLAYALERTS=0
andVSTO_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.
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\
?