不久前,我不得不展示我们 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()
我以前从未见过此异常,并且其中的链接无处可去。它只是在构建机器上而不是在我的开发箱上,所以我正在经历一个反复试验的过程,以查看两者之间的任何差异。
知道为什么会发生这种情况吗?
干杯,安德烈。