今天早上我遇到了一个与我的Silverlight 4应用程序不同寻常的问题。我一直是IoC框架的忠实粉丝,因此决定将Unity用于我的项目。但只要我将程序集添加到我的项目中,就会出现以下错误。向Silverlight 4项目添加Unity dll参考
System.Windows.Markup.XamlParseException occurred
Message=Could not load type 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
StackTrace: at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
at MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
at MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
InnerException:
现在,如果我删除DLL我的应用程序工作绝对没问题。自从早上起,我一直在挠头,并没有太多的运气与StackOverflow搜索或谷歌。
任何帮助,非常感谢。
干杯---捷豹
您是否使用Unity for Silverlight(http://msdn.microsoft.com/en-us/library/ff678312.aspx)?我在Prism框架内使用Unity(http://compositewpf.codeplex.com/),我从来没有遇到过这个问题。 – Murven 2010-10-28 13:31:38
是的,我正在使用适用于Silverlight的Unity 2.0。我实际上已将dll更改为Laurent Bugnion示例中使用的dll,并且它似乎工作正常。显然,新Unity dll存在问题。但我只是感到惊讶没有人面临这个问题!希望我不在这里愚蠢:-) – Jag 2010-10-28 14:00:25
看看这是否有所帮助:http://stackoverflow.com/questions/2914017/problem-with-conversion-of-existing-project-to-silverlight-4/9167878#9167878 – 2012-02-06 21:59:43