【发布时间】:2011-01-15 12:39:09
【问题描述】:
我正在 Visual Studio 2010 中对 Silverlight 4 进行单元测试。
问题是我无法使用添加到测试项目的资源。
在测试运行期间,当我尝试访问这样的资源时:
[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 的引用,它是一个 .net Framework 4.0 程序集,而不是 Silverlight 程序集。
我的问题是:现在可以在 ResourceManager 的帮助下在 Silverlight 测试项目中使用资源吗?如果是,那应该怎么做?
这是一个示例test project
【问题讨论】:
标签: silverlight unit-testing resources