我正在为Visual Studio 2010中的Silverlight 4进行单元测试。从Silverlight测试项目访问项目资源时出错
问题是我无法使用添加到测试项目中的资源。
在试运行时,我尝试访问这样的种源:
[TestClass]
public class Class1
{
[TestMethod]
public void Test1()
{
// here I have an exception
Debug.WriteLine(Properties.Resources.String1);
,我得到一个异常:
System.TypeLoadException: Unable to load type "System.Runtime.Versioning.TargetFrameworkAttribute" from assembly "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
堆栈跟踪
System.ModuleHandle.ResolveMethod(Int32 methodToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
System.ModuleHandle.ResolveMethodHandle(Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
System.Reflection.CustomAttributeData..ctor(Module scope, CustomAttributeRecord caRecord)
System.Reflection.CustomAttributeData.GetCustomAttributes(Module module, Int32 tkTarget)
System.Reflection.CustomAttributeData.GetCustomAttributes(Assembly target)
System.Resources.ResourceManager.GetNeutralResourcesLanguage(Assembly a, UltimateResourceFallbackLocation& fallbackLocation)
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
SilverlightClassLibraryTestProject1.Properties.Resources.get_String1() in D:\Work\Temp\SilverlightClassLibraryTestProject1\SilverlightClassLibraryTestProject1\Properties\Resources.Designer.cs: line 68
SilverlightClassLibraryTestProject1.Class1.Test1() in D:\Work\Temp\SilverlightClassLibraryTestProject1\SilverlightClassLibraryTestProject1\Class1.cs: line 13
我可以请参阅由Visual Studio创建的Silverlight测试项目包含对Microsoft.VisualStudio.QualityTools.UnitTestFramework的引用w这是一个.NET Framework 4.0程序集,而不是Silverlight。
我的问题是:现在可以在ResourceManager的帮助下使用Silverlight Test项目中的资源吗?如果是,那么应该做什么?
下面是一个简单test project
我已经重新上传一个测试项目,其他位置。 –
我正在创建一个Silverlight类库测试项目,并且引用了Microsoft.VisualStudio.QualityTools.UnitTestFramework程序集。 它有TestClassAttribute和TestMethodAttribute。如果您的Silverlight测试项目中没有Microsoft.VisualStudio.QualityTools.UnitTestFramework,那么我认为您无法使用[TestClass]等。 –
请注意我已经添加了一个资源文件到项目中,问题是我在测试运行期间无法使用添加的资源 –