我已经为某些 Sharepoint WSS3 功能制作了测试程序,但遇到了一个奇怪的异常(exception)。

public XmlNode GetListsCollection()
{
    XmlNode nodeLists;

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

    return nodeLists = lists.GetListCollection();
}

//这里出现异常 (Settings.Designer.cs)
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.WebServiceUrl)]
[global::System.Configuration.DefaultSettingValueAttribute("http://uk-tr-dsf/_vti_bin/Lists.asmx")]
public string SharepointWeb_ShareLists_Lists {
    get {
        return ((string)(this["SharepointWeb_ShareLists_Lists"]));
    }
}

当我将项目从 .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 是一个委托(delegate),真正的异常消息是内部异常。
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 项目)
假设这是原因,我是否正确? .NET 4 下是否有适用于框架的版本?
我查看了 C:\Program Files\Reference Assemblies\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>

在 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>

最佳答案

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

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

同样,您需要确保没有其他 dll 用于框架 4。

关于c# - .NET DLL 冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10741522/

10-17 02:02