Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:20:40+00:00 2026-05-24T20:20:40+00:00

The compiler complains on as typeOfState saying that typeOfState could not be found. Why

  • 0

The compiler complains on “as typeOfState” saying that typeOfState could not be found. Why is this? Is there a way to express what I am trying to accomplish?

public static readonly IDictionary<Type, string> StateDictionary = new Dictionary<Type, string>
{
    {typeof(SerializableDictionary<string, RadTabSetting>), "TabStates"},
    {typeof(SerializableDictionary<string, RadPaneSetting>), "PaneStates"},
    {typeof(SerializableDictionary<string, RadDockSetting>), "DockStates"},
    {typeof(SerializableDictionary<string, RadDockZoneSetting>), "DockZoneStates"},
    {typeof(SerializableDictionary<string, RadSplitterSetting>), "SplitterStates"},
    {typeof(SerializableDictionary<string, RadSplitBarSetting>), "SplitBarStates"},
    {typeof(SerializableDictionary<string, RadPageViewSetting>), "RadPageViewStates"},
    {typeof(GlobalSettings), "GlobalSettings"},
};

foreach (var item in StateManager.StateDictionary)
{
    string stateName = item.Value;
    Type typeOfState = item.Key;

    object stateSession = SessionRepository.Instance.GetSession(stateName) as typeOfState;

    dataToSave.Add(stateName, stateSession);
}

Cheers

EDIT: Okay. Understood that cannot use a variable as a type, even if the variable is of type “Type”

What are my options? Here’s full source:

[WebMethod]
public static bool Export()
{
    bool successful = false;

    try
    {
        HttpContext.Current.Request.ContentType = "text/xml";
        HttpContext.Current.Response.Clear();

        SerializableDictionary<string, object> dataToSave = new SerializableDictionary<string, object>();

        foreach (var item in StateManager.StateDictionary)
        {
            string stateName = item.Value;
            Type typeOfState = item.Key;

            object stateSession = SessionRepository.Instance.GetSession(stateName);

            dataToSave.Add(stateName, stateSession);
        }

        XmlSerializer serializer = new XmlSerializer(dataToSave.GetType());
        serializer.Serialize(HttpContext.Current.Response.OutputStream, dataToSave);

        successful = true;
    }
    catch (Exception exception)
    {
        _logger.ErrorFormat("Unable to serialize session. Reason: {0}", exception.Message);
    }

    return successful;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:20:41+00:00Added an answer on May 24, 2026 at 8:20 pm

    You cannot use a Type object with the as keyword. Check the documentation for its proper usage.

    To accomplish what I think you’re trying to do, perhaps look into Convert.ChangeType [MSDN].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This doesn't seem to work (compiler complains that Something 's getFoo() method doesn't implement
I was reading intro on gtest and found this part confusing: The compiler complains
When trying to create a category for NSInteger, the compiler complains that it Cannot
The compiler complains about this, after I activated all kind of warnings: For MyApp_Prefix.pch
The compiler complains about this code: HashMap<String,int> userName2ind = new HashMap<String,int>(); for (int i=0;
I have two classes that refer to each other, but obviously the compiler complains.
Why does the C# compiler not even complain with a warning on this code?
This might be iPhone specific, I'm not sure. The compiler doesn't complain when building
The compiler complains about this: int randomSort(id obj1, id obj2, void *context) { //
When I try to compile my program the compiler complains about this line in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.