How many times have I now already gotten this error message. It is incredible.
I portiere an Office 2003/2007 add-in at the time that using VSTO is designed for Office 2002/XP. There the VSTO is up to date no longer but the PIA's (primary interop assemblies) for Office XP. On the whole, the add-in is loaded just differently. In particular may be with the Extensibility. IDTExtensibility2 interface work. You can take the rest of the code 1 to 1.
The add-in is registered in the Office as a normal COM add-in and treated as such. This gives now several problems that must be avoided.
That.NET runtime searches the various involved references to the run directory of the new Office application in this constellation. This is most often in the folder "C:\Program Files\Microsoft Office\Office10". The assemblies are there but not there. What to do against it?
For example this file to do exactly in the said order helps, Word prepared. The file is WINWORD.EXE.config and has the following content.
<? xml version = "1.0"? >
< configuration >
< startup >
< supportedRuntime version="v2.0.50727"/ >
< / startup >
< / configuration >
This facilitates a prepared. The standard assemblies will be found so.
But this does not work when the BinaryFormatter. Here you have it different solving.
licenses = (LicenseCollection) formatter.Deserialize(licensestream);
Here comes the message that the Assembly for the type of LicenseCollection cannot be found. This is of course very annoying.
Here , I have found the solution then.
private static void InitializeLicenses()
{
ResolveEventHandler loadComponentAssembly = new ResolveEventHandler(LoadComponentAssembly);
}AppDomain.CurrentDomain.AssemblyResolve += loadComponentAssembly;
licenses = new LicenseCollection();
string licensefilename =
path.combine (Path.GetDirectoryName(System.Reflection.Assembly._
))GetExecutingAssembly().((Code base),
"license.dat").Replace(@"file:\",_"");
If(File.Exists(licensefilename))
{
try
{
= FileStream licensestream
new FileStream (licensefilename, FileMode.Open, FileAccess.Read);
}}BinaryFormatter formatter =
new BinaryFormatter();
formatter.AssemblyFormat =
System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
licenses = (LicenseCollection) formatter.Deserialize(licensestream);
licensestream.{Close();
}
{catch (Exception ex)
{}
finally
{
AppDomain.CurrentDomain.AssemblyResolve-= loadComponentAssembly;
}
}
{else
{
ErrorHandler.LogInfo(1000,_"License_not_found!");
}
}
static Assembly LoadComponentAssembly(Object_sender,_ResolveEventArgs_args)
{
string simpleName = args.}Name.Substring(0,_args.)Name.IndexOf(','));
string assemblyPath = simpleName + ".dll";
return Assembly.LoadFrom(Path.Combine_
_(Path.GetDirectoryName_
_(System.Reflection.Assembly.GetExecutingAssembly().))((Code base),
assemblyPath).{(Replace(@"file:\",_""));
}So, the Assembly is found.
And again a problem of less. To the next. :-)