【发布时间】:2011-02-17 23:06:44
【问题描述】:
不久前,我不得不展示我们 Silverlight 应用程序的当前版本。经过一番谷歌搜索后,以下代码给了我想要的结果:
var fileVersionAttributes = typeof(MyClass).Assembly.
GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false) as AssemblyFileVersionAttribute[];
var version = fileVersionAttributes[0].Version;
这在我们的 .NET 3.5 Silverlight 3 环境中非常有用。但是,我们最近升级到 .NET 4 和 Silverlight 4。我们刚刚完成构建机器的工作,发现此代码的单元测试抛出以下异常:
Exception Message:
System.TypeLoadException: Error 0x80131522. Debugging resource strings are unavailable. See http://go.microsoft.com/fwlink/?linkid=106663&Version=3.0.50106.0&File=mscorrc.dll&Key=0x80131522
at System.ModuleHandle.ResolveType(ModuleHandle module, Int32 typeToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.Module.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, RuntimeMethodHandle& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, Type caType)
at System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at MyCode.VersionTest()
我以前从未见过此异常,其中的链接无处可去。它只是在构建机器上而不是在我的开发机器上,所以我正在经历一个反复试验的过程,看看两者之间有什么区别。
知道为什么会发生这种情况吗??
干杯, 安德烈。
【问题讨论】:
标签: c# continuous-integration silverlight-4.0 typeloadexception assemblyversionattribute