Silverlight 4.0 向Silverlight 4项目添加Unity dll引用
今天早上,我的Silverlight 4应用程序出现了一个不寻常的问题。我一直是IoC框架的忠实粉丝,所以我决定在我的项目中使用Unity。但是,当我将程序集添加到我的项目中时,我得到了以下错误Silverlight 4.0 向Silverlight 4项目添加Unity dll引用,silverlight-4.0,unity-container,Silverlight 4.0,Unity Container,今天早上,我的Silverlight 4应用程序出现了一个不寻常的问题。我一直是IoC框架的忠实粉丝,所以我决定在我的项目中使用Unity。但是,当我将程序集添加到我的项目中时,我得到了以下错误 System.Windows.Markup.XamlParseException occurred Message=Could not load type 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'ms
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搜索或谷歌方面运气不太好
非常感谢您的帮助
干杯---Jag可能会提供一些有用的信息。它基本上说:
“在一个系统中使用统一的局限性
部分信任的环境就是你
无法使用注册和使用映射
RegisterType方法,其中
目标类是internal(C#),Friend
(Visual Basic.NET)、专用(C#)或
专用(Visual Basic.NET)。”
请确认您实际引用的是Silverlight程序集,而不是桌面程序集。AllowPartiallyTrustedCallersAttribute类不在Silverlight版本中
您正在使用Unity 2.0吗?如果是这样,DLL将命名为“Microsoft.Practices.Unity.Silverlight.DLL”。这就是你添加的DLL吗?如果文件名中没有“.Silverlight”,则您正在引用桌面dll。在执行干净的生成后再进行完整的重新生成为我解决了此问题。您是否使用Unity for Silverlight()?我在Prism框架()中使用Unity,我从来没有遇到过这个问题。是的,我在Silverlight中使用Unity 2.0。实际上,我把dll改成了Laurent Bugnon的示例中使用的dll,它似乎工作得很好。很明显,新的Unity dll有问题。但是我很惊讶没有人面对这个问题!!!希望我不是在这里傻:-)看看这是否有帮助:嗨,达米安,谢谢你的回复。我还没有写任何统一代码。我所做的就是添加引用,应用程序就会启动:-(