无法加载文件或程序集'TranslationFormsApplication.TranslationForm.SavedData>'或其中一个依赖项

时间:2011-12-20 14:20:29

标签: c# class .net-assembly

我收到了这个错误

  

无法加载文件或程序集   'TranslationFormsApplication.TranslationForm.SavedData>'或其中一个   依赖。参数不正确。 (HRESULT的例外情况:   0x80070057(E_INVALIDARG)

当我在C#中调试我的代码时。 SavedData是另一个类中的类名。

以下是示例代码

namespace TranslationFormsApplication 
{  
   partial class TranslationForm 
   { 
       private class SavedData 
       { 
          public SavedData(int id, string s, string t) 
          { 
             index = id; 
             source = s; 
             translation = t; 
          } 
          private int m_index; 
          public int index { get { return m_index; } set { m_index = value; } 
       } 
   } 
}

我尝试打开表单设计器时的错误堆栈如下所示:

at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.VisualStudio.Platform.VsAppDomainManager.d__1.MoveNext()
at Microsoft.VisualStudio.Platform.VsAppDomainManager.InnerResolveHandler(String name)
at Microsoft.VisualStudio.Platform.VsAppDomainManager.ResolveHandler(Object sender, ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)

我查看了x86 / Debug /文件夹,确实没有TranslationFormsApplication.TranslationForm.SavedData文件。

由于我使用Windows 7,我知道我们应该清理临时的ASP.net文件 C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ 和所有其他版本 还有 C:\ WINDOWS \ Microsoft.NET \框架\ 而且还在 C:\ Users \用户名\应用程序数据\ TMP \

我已经这样做了,实际上我找不到“临时ASP.NET文件”。我也删除了bin / Debug和obj86 / Debug文件夹,但它没有帮助。

所有对类的访问都在TranslationForm类中完成。以下是示例:

  

private Dictionary textIndexes;

    private void InitializeComponent()
    {

             this.textIndexes = new Dictionary<int,SavedData>();
    }   

    private void accept_Click(object sender, System.EventArgs e)
    {
        SavedData data;
        if (textIndexes.ContainsKey(selectedIndex))
        {
            data = textIndexes[selectedIndex];
            data.source = sourceEdit.Text;
            data.translation = transEdit.Text;            
        }
        else
        {
            data = new SavedData(selectedIndex, sourceEdit.Text, transEdit.Text);
            textIndexes.Add(selectedIndex, data);
        }
    } 

    private void saveTrainingFiles()
    {
        foreach (KeyValuePair<int, SavedData> line in textIndexes)
        {
             SavedData data = line.Value;

              sw.WriteLine(data.source);
              sw2.WriteLine(data.translation);
        }
        textIndexes.Clear();
    }

当我将代码更改为使用tuple而不是使用SavedData类时,我收到以下警告:

  

警告1给定的程序集名称或代码库无效。 (来自HRESULT的异常:0x80131047)

我尝试打开FormDesigner时的错误堆栈是:

1.   Hide Call Stack 

at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
at System.Reflection.AssemblyName..ctor(String assemblyName)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.GetRuntimeType(String typeName)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.GetType(String typeName)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.GetType(String typeName)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.GetType(IDesignerSerializationManager manager, String name, Dictionary`2 names)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.FillStatementTable(IDesignerSerializationManager manager, IDictionary table, Dictionary`2 names, CodeStatementCollection statements, String className)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at   Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at   Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)  

我想这与.NET的版本控制以及64位机器有关。有没有想过如何使用和不使用类来解决它?

1 个答案:

答案 0 :(得分:0)

[SavedData类应公开访问,如TranslationFormsApplication.TranslationForm.SavedData

public class SavedData

[UPDATE]:

另一方面,你的代码不应该是:

namespace TranslationFormsApplication 
{  
partial class TranslationForm 
{ 
   public class SavedData 
   { 
      public SavedData(int id, string s, string t) 
      { 
         index = id; 
         source = s; 
         translation = t; 
      } 
      private int m_index; 
      private string m_source; 
      private string m_translation; 

       public int index { get { return m_index; } set { m_index = value; } }
       public string source { get { return m_source; } set { m_source = value; } }
       public string translation { get { return m_translation; } set { m_translation = value; } }
   } 
} 
}