将 Unity dll 引用添加到 Silverlight 4 项目
今天早上,我的 Silverlight 4 应用程序遇到了一个不寻常的问题。我一直是 IoC 框架的忠实粉丝,因此决定在我的项目中使用 Unity。但是当我将程序集添加到我的项目中时,我收到以下错误。
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 搜索或 Google 上都没有什么运气。
非常感谢任何帮助。
干杯---杰格
This morning I had an unusual issue with my Silverlight 4 app. I have been a big fan of IoC frameworks, so decided I will use Unity for my project. But as soon as I added the assembly to my project, I got this following error.
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:
Now if I remove the dll my app works absolutely fine. I have been scratching my head since morning and not having much luck with StackOverflow search or Google.
Any help is much appreciated.
Cheers---Jag
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请验证您实际上引用的是 Silverlight 程序集而不是桌面程序集。 Silverlight 版本中没有AllowPartiallyTrustedCallersAttribute 类。
你用的是Unity 2.0吗?如果是这样,DLL 的名称为“Microsoft.Practices.Unity.Silverlight.dll”。这是你添加的DLL吗?如果“.Silverlight”不在文件名中,那么您将引用桌面 dll。
Please verify that you're actually referencing the Silverlight assembly rather than the desktop one. The AllowPartiallyTrustedCallersAttribute class isn't in the Silverlight version.
Are you using Unity 2.0? If so, the DLL is named "Microsoft.Practices.Unity.Silverlight.dll". Is that the DLL you've added? If the ".Silverlight" isn't in the file name, then you're referencing the desktop dll instead.
本文可能提供一些有用的信息。它基本上是这样说的:
This article might provide some useful information. It basically says that:
进行干净的构建,然后进行完整的重建,为我解决了这个问题。
Doing a clean build followed by a full rebuild fixed this issue for me.