C# .NET DLL冲突

C# .NET DLL冲突,c#,.net,sharepoint,.net-3.5,C#,.net,Sharepoint,.net 3.5,我已经为一些Sharepoint WSS3功能编写了测试程序,但遇到了一个奇怪的异常 public XmlNode GetListsCollection() { XmlNode nodeLists; ShareLists.Lists lists = new ShareLists.Lists(); // <--- Exception causing line lists.Credentials = CredentialCache.DefaultCredentials

我已经为一些Sharepoint WSS3功能编写了测试程序,但遇到了一个奇怪的异常

public XmlNode GetListsCollection()
{
    XmlNode nodeLists;

    ShareLists.Lists lists = new ShareLists.Lists(); // <--- Exception causing line
    lists.Credentials = CredentialCache.DefaultCredentials;

    return nodeLists = lists.GetListCollection();
}
System.IO.FileNotFoundException
           Message=Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
当我将项目从.NET 4更改为.NET 3.5时发生此错误,这是修复“PlatformNotSupportException”所必需的

所以我不能把它改回去

System.Configuration.ConfigurationErrorsException was unhandled
  Message=An error occurred creating the configuration section handler for applicationSettings/SharepointWeb.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. (C:\Working\SharepointPlugin\SharepointWeb\bin\Debug\SharepointWeb.vshost.exe.Config line 5)
  Source=System.Configuration
  BareMessage=An error occurred creating the configuration section handler for applicationSettings/SharepointWeb.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
  Filename=C:\Working\SharepointPlugin\SharepointWeb\bin\Debug\SharepointWeb.vshost.exe.Config
  Line=5
  Stacktrace: ... omitted
我意识到这个
ConfigurationErrorsException
是一个委托,真正的异常消息是内部异常

public XmlNode GetListsCollection()
{
    XmlNode nodeLists;

    ShareLists.Lists lists = new ShareLists.Lists(); // <--- Exception causing line
    lists.Credentials = CredentialCache.DefaultCredentials;

    return nodeLists = lists.GetListCollection();
}
System.IO.FileNotFoundException
           Message=Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
现在,我的参考资料中已经找到并清楚地显示了该文件,但是缺少了
Microsoft.CSharp
(因为它是一个.NET 3.5项目) 我认为这是原因,对吗?是否有.NET4下的框架版本? 我在
C:\Program Files\Reference Assembly\Microsoft\Framework\.NETFramework\
中查找过,但没有找到等效版本


解决方案:

这些都必须改变

在resx文件中:

  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>

System.Resources.ResXResourceReader,System.Windows.Forms,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter,System.Windows.Forms,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089
在app.config中:

<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="SharepointWeb.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
</configSections>


看起来您的工具中仍然使用了一些4.0程序集。将目标切换到2.0-3.5时,必须停止使用4.0程序集。不幸的是,由于您正在迁移到较旧版本的框架,因此在某些情况下,您必须更改代码,使其不使用仅4.0版的功能。

3.5版没有Microsoft.CSharp.dll,但通常它会自动添加到4.0项目中,而不需要它(除非您使用动态关键字之类的东西,在这种情况下,您的项目需要是4.0),所以我会尝试删除此引用

对于system.dll的第4版,您说此文件已在引用中找到并存在。 但是,如果您的项目是针对3.5 framework的,那么您应该参考system.dll的2.0版本,而不是system.dll的framework 4版本


同样,您需要确保其他DLL都不适用于framework 4。

我现在拥有的项目高于V2的唯一DLL是System.Core,它在v3.5上运行,与我的项目相同。但是异常仍然存在。在这种情况下,我认为您可能需要在源文件夹中的每个文件中搜索Version=4.0.0.0,以查看这是否告诉您什么指向system.dll。例如,它可能是一个.resx文件,搜索版本=4.0.0.0时显示了dll,在我的App.Config和Form1.resx文件中引用了有问题的PKT。我没想到能在纯文本中找到它!Live and learn。