Answered by:
TypeLoadException - AllowPartiallyTrustedCallersAttribute in Silverlight 4

Question
-
I am tried to create a Silverlight application using Code Dom, A generated output is a Silverlight application. There is no issue while compilation, but while running it gives an error:
XamlParseException occurred [Line: 0 LineNumber=0] InitializeComponent(); of App.xaml.cs
Detailed Issue:
System.Windows.Markup.XamlParseException occurred
Message= [Line: 0 LineNumber=0]
LinePosition=0
StackTrace:
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at PresentationLayer.App.InitializeComponent()
at PresentationLayer.App..ctor()
InnerException: System.TypeLoadException
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()
I tried with Silverlight application creation with/ without web host option using VS2010 and found no issues in this case;
But issue occurs [with/ without web host] when Silverlight Application generated by Code Dom.
I also check there is no entry of [assembly: AllowPartiallyTrustedCallers] in AssemblyInfo.cs of Host environment. I added [assembly: AllowPartiallyTrustedCallers] including using System.Security;
Issue still exists.
Thanks in Advance for providingsolution if any.
- I already ref this links:
http://forums.silverlight.net/t/230360.aspx
- Edited by Swapnil Shirbhate Wednesday, May 16, 2012 4:15 AM
Answers
-
If this is a silverlight question, best posted to http://forums.silverlight.net/ I don't think you are going to get help with silverlight questions in this forum.
Community Forums Program Manager
- Proposed as answer by Naomi N Thursday, May 10, 2012 7:46 PM
- Marked as answer by Ed Price - MSFTMicrosoft employee Wednesday, May 23, 2012 10:29 PM