我为一些Sharepoint WSS3功能制作了测试程序,但我遇到了一个奇怪的例外。
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
是委托,而真正的异常消息是内部异常。
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下是否有Frameworks版本?
我查看了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>
答案 0 :(得分:5)
没有适用于3.5的Microsoft.CSharp.dll,但通常它会自动添加到4.0项目而不需要它(除非您使用的是动态关键字之类的东西,在这种情况下您的项目需要为4.0),所以我会尝试删除此引用。
对于system.dll的第4版,您说此文件已找到并存在于您的参考文献中。 但是,如果您的项目是针对3.5框架的,那么您应该引用system.dll的2.0版本而不是system.dll的框架4版本
同样,您需要确保其他dll都不适用于框架4。
答案 1 :(得分:1)
看起来您的工具中仍然使用了一些4.0程序集。将目标切换到2.0-3.5时,必须停止使用4.0程序集。不幸的是,由于您要迁移到旧版本的Framework,因此您可能需要将代码更改为不使用仅4.0的功能。