Problem with conversion of existing project to Silverlight 4

半腔热情 提交于 2020-01-04 09:38:50

问题


We have a working Silverlight 3 project. After changing the target framework to Silverlight 4 the application won't start anymore. It throws an exception in the following line in the generated InitializeComponent() method:

System.Windows.Application.LoadComponent(this, new System.Uri("/SLAppMain;component/App.xaml", System.UriKind.Relative));

Here is the exception (note the inner exception):

System.Windows.Markup.XamlParseException occurred
  Message= [Line: 0 Position: 0]
  LineNumber=0
  LinePosition=0
  StackTrace:
       bei System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
  InnerException: System.TypeLoadException
       Message=Der Typ 'System.Security.AllowPartiallyTrustedCallersAttribute' konnte nicht aus der mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e -Assembly geladen werden.
       StackTrace:
            bei System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
            bei System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            bei System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
            bei 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)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
            bei System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
            bei System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
            bei MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
            bei MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
       InnerException: 

The problem is that the type System.Security.AllowPartiallyTrustedCallersAttribute is not contained in the Silverlight version of mscorlib.dll.

I have no idea how to fix this nor where to look for causes. Has anyone encountered this problem? What could possibly cause this error?


回答1:


the AllowPartiallyTrustedCallersAttribute class does not exist in SL 4 (neither in mscorlib, nor anywhere else) and did not exist in SL 3 either. So there must be more than just the conversion from SL 3 to SL 4 to this I guess - is AllowPartiallyTrustedCallersAttribute used in your code somewhere?

Cheers, Alex

EDIT: Actually, you might want to take a look into your app's AssemblyInfo.cs (in the Properties folder). Perhaps the attribute is used there like

[assembly: AllowPartiallyTrustedCallers(true)]

. You could then simply remove it and see what happens...




回答2:


Do you use Unity for silverlight in your project ? I had exactly the same problem yesterday, and the error disappeared when I de-referenced unity




回答3:


This walk through REALLY helped me with the same issue http://code.msdn.microsoft.com/RiaServices/Release/ProjectReleases.aspx?ReleaseId=5122




回答4:


Doing a clean build followed by a full rebuild fixed this issue for me.




回答5:


Dependencies with the same name will be quietly overwritten and packaged into a XAP after the compilation, so make sure that different target platforms of your projects don't build into the same output folder.



来源:https://stackoverflow.com/questions/2914017/problem-with-conversion-of-existing-project-to-silverlight-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!