Try our conversational search powered by Generative AI!

The type initializer for 'EPiServer.Security.PrincipalInfo' threw an exception

Vote:
 

I have created a new episerver project in visual studio 2008, imported all the files from our live server into it, built the project sucessfully, but am recieiving the following error which I am unsure how to resolve...

NullReferenceException: Object reference not set to an instance of an object.]
   EPiServer.Configuration.Settings.get_Instance() +36
   EPiServer.UriSupport.get_InternalUIUrl() +61
   EPiServer.UriSupport.get_UIUrl() +61
   EPiServer.UriSupport.ResolveUrlFromUIBySettings(String path) +34
   EPiServer.Security.PrincipalInfo..cctor() +178

[TypeInitializationException: The type initializer for 'EPiServer.Security.PrincipalInfo' threw an exception.]
   EPiServer.Security.PrincipalInfo.get_CurrentPrincipal() +0
   EPiServer.Security.VirtualRolePrincipal.VirtualRolePrincipal_PostAuthenticateRequest(Object sender, EventArgs e) +56
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
 

Any advice would be hugely welcome.  Thanks.

#51354
Jun 03, 2011 10:35
Vote:
 

My first guess would be a couple of EPiServer dll-files are missing from your bin folder. Could you compare your local bin-folder with the one on the server?

Frederik

#51356
Jun 03, 2011 10:43
Vote:
 

 Thanks for the advice Frederik - this was also my first thought, and having compared the dll's on the live site with my local site, there are none missing (had overwritten ddl's in local site anyhow, with ddl's from the live site). 

Any other suggestions?  Having the same connectivity on the local box as I do on the live server, and access to all the source project files for the live site, I would have expected this to be a fairy trouble free exercise, rather than a head banging, time consuming one :)

#51357
Jun 03, 2011 13:27
Vote:
 

Okay, next up is your web.config file, compare that to the one on the server. Also, do you get the same error message regardless which page you visit in your browser?

#51358
Jun 03, 2011 13:42
Vote:
 

Thanks again for the response Frederik.  I have updated the web.config, and its associated child config files, and am now receiving the following error:  (incidently, yes - the same error regardless of the page I render)

PageTypeBuilderException: There are multiple types with the same page type name. The name is [Standard] Content Page and the types are ContentPageData and ContentPageData.]

There is only one instance of the page type "[Standard] Content Page" (ContentPageData.cs), and only one copy of this class???  Not sure what the exception is pointing to? 

#51373
Jun 06, 2011 13:16
Vote:
 

Okay, if you open up the database table tblPageType you'll see a list of all the page types and their guid. You'll need the guid for [Standard] Content Page for PageTypeBuilder. In the attribute of your class (PageTypeBuilderAttribute) you'll need to specify the guid you copied from the database table.

Example:

[PageType("DF039718-0E0B-4D21-A2D1-DF3E4D104B5C", Filename = "/default.aspx", Name = "Startsiden")]

    

#51374
Jun 06, 2011 13:23
Vote:
 

thanks Frederik, really handy to know, and that fixed the page type call in question, and all the others bar one - What happens when you come across a Page Type that does not appear in the table?  For example, I am getting the same error message now, but the entry in the table does not exist for me to copy the guid from.

#51375
Jun 06, 2011 13:55
Vote:
 

If it's a new page type you can just specify any valid guid and it'll use that as the guid for the page type in EPiServer.

#51376
Jun 06, 2011 14:26
Vote:
 

thanks, makes perfect sense.  Now thats sorted, I am encountering this error...

Unable to map the type for the property SectionColour in ContentPageData to a suitable EPiServer CMS property.

Not sure which table holds the values for each of the Page Type's properties?

#51377
Jun 06, 2011 16:22
Vote:
 

Looks like you're missing a custom property in your code. Do you have any code for the SectionColour property that you could post?

#51392
Jun 07, 2011 11:49
Vote:
 

 

[PageTypeProperty(Type = typeof(PropertyDropDown), EditCaption = "Section Colour", HelpText = "The section background colour. PLEASE NOTE: this only affects pages at level 3 and below in the site hierarchy.", SortOrder = 90)]

public virtual stringSectionColour

{

get

{

string value = this.GetPropertyValue(page => page.SectionColour);if (value == null && ParentLink != null && (PageLink.ID != PageReference.StartPage.ID && EPiServer.DataFactory.Instance.GetPage(ParentLink) isContentPageData))

value = ((ContentPageData)EPiServer.DataFactory.Instance.GetPage(ParentLink)).SectionColour;return value;

}

 

}

I think the problem exists where there is a conflict.  If I hover over the call to ContentPageData in the above code, I get the message "The type <file> conflicts with the imported type <dll> using the type defined in <file>".  Not sure how to resolve that?

#51396
Jun 07, 2011 12:41
Vote:
 

Can you read the value of SectionColour by just using CurrentPage["SectionColour"]?

#51404
Jun 07, 2011 14:41
Vote:
 

If you mean to replace the code in the get method, with a call to CurrentPage["SectionColour"], no.  Intellisense does not provide CurrentPage, even if I create a new PageReference object.

#51407
Jun 07, 2011 15:37
Vote:
 

Yep, you need to do it in your .aspx file. Otherwise just use an auto get set property to see if you get any value at all.

#51416
Jun 07, 2011 18:12
Vote:
 

strangely, this morning the error has transferred to another custom property in another class, and I have made no changes whatsoever to any of the code since.  Now recieving...

Unable to map the type for the property ValueBorderColour in ValuePageData to a suitable EPiServer CMS property.

If I comment out the code in the ValuePageData class for ValueBorderColour (is just using empty get set properties), the error relating to SectionColour is rendered.

If I try to expose CurrentPage["SectionColour"] on page load of my .aspx file, I recieve the same error message.  If I strip the contents of the get property in SectionColour, and just return a string, I still get the same error message relating to SectionColour.

Btw, thanks for all your help with this...just want to be able to develop against the project. 

#51418
Jun 08, 2011 9:24
Vote:
 

Do you have the code for the custom property PropertyDropDown? (Not the PageTypeBuilder code, but the code for the custom property). If you click inside typeof(PropertyDropDown) and press F12 in Visual Studio you should be taken to the correct class.

#51450
Jun 08, 2011 19:50
Vote:
 

Hi Frederik, here is the code for the class...

using System;

using EPiServer.PlugIn;

///<summary>/// Custom PropertyData implementation.///</summary>

[Serializable]

[PageDefinitionTypePlugIn(DisplayName = "Drop Down Selector", SortIndex = 0)]

public class PropertyDropDown : EPiServer.Core.PropertyLongString

{

///<summary>/// Creates the property control.///</summary>///<returns>Property control implementing IPropertyControl.</returns>public override EPiServer.Core.IPropertyControl CreatePropertyControl()

{

return new PropertyDropDownControl();

}

}

#51464
Jun 09, 2011 11:44
Vote:
 

 

Hi Frederik, here is the code from the class...

using System;

using EPiServer.PlugIn;

///<summary>/// Custom PropertyData implementation.///</summary>

[Serializable]

[PageDefinitionTypePlugIn(DisplayName = "Drop Down Selector", SortIndex = 0)]

public classPropertyDropDown : EPiServer.Core.PropertyLongString

{

///<summary>/// Creates the property control.///</summary>///<returns>Property control implementing IPropertyControl.</returns>public override EPiServer.Core.IPropertyControl CreatePropertyControl()

{

returnnewPropertyDropDownControl();

}

 

}

 

thanks again.

#51465
Jun 09, 2011 11:48
Vote:
 
Could you post the code for PropertyDropDownControl as well please :)
#51467
Jun 09, 2011 13:35
Vote:
 

There are four classes in total (PropertyDropDown, PropertyDropDownControl, PropertyDropDownSettings, PropertyDropDownSettingsUI)

Here is the class code for each of the remaining 3...

- PropertyDropDownControl.cs

using System.Collections.Generic;

using System.Configuration;

using EPiServer.Core;

using EPiServer.Core.PropertySettings;

///<summary>/// PropertyControl implementation used for rendering PropertyDropDown data.///</summary>

[PropertySettings(typeof(PropertyDropDownSettings), UseGlobals = true)]

public class PropertyDropDownControl : EPiServer.Web.PropertyControls.PropertyStringControl

{

///<summary>/// Gets the PropertyDropDown instance for this IPropertyControl.///</summary>///<value>The property that is to be displayed or edited.</value>

public PropertyDropDown PropertyDropDown

{

get

{

return PropertyData as PropertyDropDown;

}

}

///<summary>/// Gets the drop down list.///</summary>///<value>The drop down list.</value>

protected System.Web.UI.WebControls.DropDownList DropDownList

{

get;set;

}

///<summary>/// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.///</summary>///<param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>

protected override void OnInit(System.EventArgs e)

{

base.OnInit(e);this.DropDownList = new System.Web.UI.WebControls.DropDownList();

}

///<summary>/// Creates the edit controls.///</summary>

public override void CreateEditControls()

{

this.DropDownList.Items.Add(string.Empty);

foreach (var item inthis.GetDropDownItems())

{

System.Web.UI.WebControls.

ListItem newListItem = new System.Web.UI.WebControls.ListItem() { Text = item.Key, Value = item.Value, Selected = item.Value.Equals(PropertyDropDown.Value) };this.DropDownList.Items.Add(newListItem);

}

this.ApplyControlAttributes(this.DropDownList);this.Controls.Add(this.DropDownList);

}

///<summary>/// Applies the edit changes.///</summary>publicoverridevoid ApplyEditChanges()

{

if (this.DropDownList.SelectedItem != null && !string.IsNullOrEmpty(this.DropDownList.SelectedValue))this.SetValue(this.DropDownList.SelectedItem.Value);elsethis.SetValue(null);

}

///<summary>/// Gets the drop down items.///</summary>///<returns>Dictionary collection of items.</returns>

private Dictionary<string, string> GetDropDownItems()

{

Dictionary<string, string> selectorItems = newDictionary<string, string>();

PropertyDropDownSettings settings = (PropertyDropDownSettings)PropertyData.GetSetting(typeof(PropertyDropDownSettings));

if (!string.IsNullOrEmpty(settings.AppSettingsKey))

{

string classString = ConfigurationManager.AppSettings[settings.AppSettingsKey];

string[] classStrings = classString.Split(',');

foreach (var item in classStrings)

{

string[] keyValue = item.Split(':');

if(keyValue.Length > 1) selectorItems.Add(keyValue[0], keyValue[1]);

else if(keyValue.Length == 1) selectorItems.Add(keyValue[0], keyValue[0]);

}

}

else

selectorItems.Add("No source has been set.", string.Empty);

return selectorItems;

}

}

}

//----------------------------------------------------------------------------------------------------------------------------------------------------

- PropertyDropDownSettings.cs

using EPiServer.Core.PropertySettings;///<summary>

/// Class representing the settings for the drop down property.///</summary>

[PropertySettingsUI(AdminControl = typeof(PropertyDropDownSettingsUI))]

public class PropertyDropDownSettings : PropertySettingsBase

{

///<summary>/// Gets or sets the app settings key.///</summary>///<value>The app settings key.</value>

public string AppSettingsKey { get; set; }///<summary>/// Gets the default values.///</summary>///<returns>IPropertySettings instance.</returns>

public override IPropertySettings GetDefaultValues()

{

return new PropertyDropDownSettings() { AppSettingsKey = string.Empty };

}

}

}

//--------------------------------------------------------------------------------------------------------------------------------

- PropertyDropDownSettingsUI.cs

using System.Web.UI.WebControls;using EPiServer.Core.PropertySettings;///<summary>/// Class representing the settings user interface for the dropdown property.///</summary>

public class PropertyDropDownSettingsUI : PropertySettingsControlBase

{

private TextBox appSettingsKey;

private Label appSettingsLabel;///<summary>/// Loads the settings UI.///</summary>///<param name="settings">The settings.</param>publicoverridevoid LoadSettingsUI(IPropertySettings settings)

{

this.EnsureChildControls();this.appSettingsKey.Text = ((PropertyDropDownSettings)settings).AppSettingsKey;

}

///<summary>/// Updates the settings.///</summary>///<param name="settings">The settings.</param>

public override void UpdateSettings(IPropertySettings settings)

{

this.EnsureChildControls();

((PropertyDropDownSettings)settings).AppSettingsKey = this.appSettingsKey.Text;

}

///<summary>/// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.///</summary>

protected override void CreateChildControls()

{

base.CreateChildControls();

this.appSettingsKey = newTextBox() { ID = "appSettingsKey" };

this.appSettingsLabel = newLabel() { Text = "AppSetting Key : ", AssociatedControlID = this.appSettingsKey.ID };

Controls.Add(this.appSettingsLabel);

Controls.Add(this.appSettingsKey);

}

}

}

I know I have said it before, but I really am hugely appreciate of your help Frederik.

#51473
Jun 09, 2011 14:45
Vote:
 

Hi Jon

The code seems to look fine. A couple of suggestions.

  1. Make sure the dll with the Drop Down Selector code uses the same version of EPiServer as your main project
  2. Make sure the dll with the Drop Down Selector code is in your web folders bin folder
  3. Comment out the code for the SectionColour property
  4. Go to admin mode and Edit Custom Property Types
  5. Check that the Drop Down Selector property is listed there
  6. Open up your page type in admin mode and check what property type SectionColour is set to
  7. Go to edit mode and check if you can edit the page and get a value back (with CurrentPage["SectionColour"])

Hope this helps.

Frederik

#51506
Jun 10, 2011 14:19
Vote:
 

Hi Frederik,

So I get to point 4 (having covered 1, 2 and 3), and further exceptions appear relating to additonal classes - once these are commented, I recieve the following error stack...

[ArgumentException: An item with the same key has already been added.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +51
   System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +7590101
   System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +11
   PageTypeBuilder.PageTypeResolver.AddPageType(Int32 pageTypeID, Type pageTypeType) +74
   PageTypeBuilder.Synchronization.PageTypeSynchronizer.AddPageTypesToResolver(List`1 pageTypeDefinitions) +189
   PageTypeBuilder.Synchronization.PageTypeSynchronizer.SynchronizePageTypes() +237
   PageTypeBuilder.Initializer.Initialize(InitializationEngine context) +109
   EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +421
   EPiServer.Framework.Initialization.InitializationEngine.Initialize(HostType hostType) +176
   EPiServer.Framework.Initialization.InitializationModule.StaticInitialization(HostType hostType) +257
   EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +89
   EPiServer.Global..ctor() +73
   ASP.global_asax..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\gloucestershirenhs\eac8e516\105e7174\App_global.asax.hydzsgrx.0.cs:0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +221
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +289

#51512
Jun 10, 2011 17:07
Vote:
 

Have all your page types specified a GUID in the PageTypeAttribute?

#51514
Jun 10, 2011 19:39
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.