2012-05-24 90 views
3

我已经为某些Sharepoint WSS3功能制作了测试程序,但是我遇到了一个奇怪的例外。.NET DLLs冲突

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.0到.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为代表,而真正的异常消息是内部异常。

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> 

回答

5

3.5没有Microsoft.CSharp.dll,但很多时候它会自动添加到4.0项目中,而不需要它(除非您正在使用诸如动态关键字之类的东西,在这种情况下,您的项目需要为4.0),所以我会尝试删除这个参考。

重新版本4的system.dll,你说这个文件被找到并出现在你的参考文献中。 但是,如果您的项目是为3.5框架,那么您应该引用system.dll的2.0版本,而不是system.dll的框架4版本

同样,您需要确保没有其他dll是为框架4.

+0

我现在有比V2更高的项目的唯一DLL是System.Core运行在v3.5与我的项目相同。然而,例外依然存在。 – Amicable

+2

在这种情况下,我认为您可能需要在源文件夹中的每个文件中搜索Version = 4.0.0.0,以查看是否告诉您指向system.dll的内容。例如,它可能是一个.resx文件 – sgmoore

+0

搜索版本= 4.0.0.0显示了在我的App.Config和Form1.resx文件中引用了有问题的PKT的DLL。 我没想到能够以纯文本的方式找到它!活到老,学到老。 – Amicable

1

它看起来像你仍然有约4.0个组合在您的工具中使用。当你将目标切换到2.0-3.5时,你必须停止使用4.0程序集。不幸的是,由于您正在转向较旧版本的Framework,因此您将不得不将代码更改为不使用4.0-only功能。