I moved few dialog forms from one class library to another (drag and drop) in the same solution (both are c# class libraries). Then at run time I started getting error inside the InitializeComponent
method of myform.Designer.cs
of moved and previously existed forms in that target dll at line similar to
this.pictureBox1.Image = global::mydll.Properties.Resources.Webster;
The exception is:
String cannot have zero length.
Sometimes the form will load correctly the first time but not after that.
Do you ever have issues moving forms from one project to another?
I did updated all namespaces to use the target dll namespace.
-- From Event viewer
Message: String cannot have zero length.
Source: mscorlib
TraceStack: at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
at Common.Properties.Resources.get_License() in E:\WORK\ProjectOne\Common\Properties\Resources.Designer.cs:line 146
at Project.ONE.Common.ProgressDialog.InitializeComponent() in E:\WORK\ProjectOne\Common\ProgressDialog.Designer.cs:line 100
at Project.ONE.Common.ProgressDialog..ctor(String caption) in E:\WORK\ProjectOne\Common\ProgressDialog.cs:line 60
at Start.CSCom.start() in E:\WORK\ProjectOne\Addin\CSCom.cs:line 326
at Start.Connect.ButtonStartClicked(IRibbonControl control) in E:\WORK\ProjectOne\Addin\Connect.cs:line 464.
-- SOLVED
As directed by Avi, I enabled the "First Chance Exception" and found the problem in the Assembly Resolve code below (Apparently this trying to load the assembly and failing to do so) :
currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);
.. .. ..
Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args){
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly, objExecutingAssemblies;
string strTempAssmbPath = "";
objExecutingAssemblies = Assembly.GetExecutingAssembly();
AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
//Loop through the array of referenced assembly names.
foreach (AssemblyName strAssmbName in arrReferencedAssmbNames)
{
//Check for the assembly names that have raised the "AssemblyResolve" event.
if (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
{
//Build the path of the assembly from where it has to be loaded.
//The following line is probably the only line of code in this method you may need to modify:
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"Software\ProjectONE\addin");
strTempAssmbPath = regkey.GetValue("DllLocation").ToString();
if (strTempAssmbPath.EndsWith("\\")) strTempAssmbPath += "\\";
strTempAssmbPath += args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
break;
}
}
//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempAssmbPath);
//Return the loaded assembly.
return MyAssembly;
}
I just removed the "Assembly Resolve" code completely since my target of moving the forms from one class library to another is to reduce the number of my solution dlls.
I believe this problem is still unique to my case but someone may find this useful.
Thanks.