今天早上我遇到了一個與我的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