Why does ExpandoObject not work as expected? [closed] - c#

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Currently, not even the simplest examples of using the 'ExpandoObject' work on my machine.
Both
dynamic obj = new ExpandoObject();
obj.Value = 10;
var action = new Action<string>((line) => Console.WriteLine(line));
obj.WriteNow = action;
obj.WriteNow(obj.Value.ToString());
(from this website) and
dynamic sampleObject = new ExpandoObject();
sampleObject.test = "Dynamic Property";
Console.WriteLine(sampleObject.test);
(from the MSDN examples) fail with a RuntimeBinderException. I presume I've misconfigured something, but I am at a loss about what it might be.
I am using .NET v4.0.30319 and Visual Studio 2010 SP1 Premium. Please ask for anything else you might need to know. =)

Deleting the hidden "SolutionName.suo" file in the solution directory fixed this problem for me.
I still have no clue why it occured, though.
Edit:
Andras Zoltan, who deleted his answer, guessed correctly. I have had "Break on all Exceptions" enabled and was being stupid. =)

The problem is simply that Console.WriteLine has too many overloads and so the dynamic part cannot be figured out correctly.
Put the output into a typed variable before or just cast it.
e.g.
dynamic sampleObject = new ExpandoObject();
sampleObject.test = "Dynamic Property";
Console.WriteLine((string)sampleObject.test);

Related

C# CodeDom Cant type in " [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I want to compile a code with codedom which should connect to my ftp server.
But I cant type in the credentials because of the ""...
Look here :
Temp.AppendLine(#"request.Credentials = new NetworkCredential("userid","userpassword");");
If I type " in the code, it automatic ends the content of the brackets...
Help?
You may need to escape the content by using double quotes, like this:
Temp.AppendLine(#"request.Credentials = new NetworkCredential(""userid"",""userpassword"");");
Temp.AppendLine(#"request.Credentials = new NetworkCredential(""userid"",""userpassword"");");
Escape the " with ""

C# Errors Need Fixing and Info [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
How do I fix the errors in this code?
PS3TMAPI.GetProcessList(0, out processIDs);
ulong uProcess = processIDs[0];
ProcessID = Convert.ToUInt32(uProcess);
PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
PS3TMAPI.ProcessContinue(0, ProcessID);
Info = "The Process" + ProcessID.ToString("") + " Has Been Attached !";
For this line PS3TMAPI.GetProcessList(0, out processIDs); I'm getting "the best overloaded method match for PS3TMAPI.GetProcessList(int, out uint[]) has some imvalid arguments"
Argument 2: cannot convert from out processIDs to out uint[]
For all the processIDs I'm getting doesn't exist in current context
And for all the ProcessID I'm getting doesn't exist in current context
I'm getting Info doesn't exist in current context
Also how do I do this in this video for example in bottom left hand corner the guy presses the button and the not connected in red turns green after it connects I connected a letterbox in my program but to let me know if it connected successfully I want to do that, in the video it's in the bottom left from 1:22 - 1:27 http://www.youtube.com/watch?v=uUI5IIhrj78
You need to post more (all?) of the relevant code to get any real help with this. Without more to go on the best you'll likely get is this.
processIDs is not a uint[] (see answer 3 below).
see answer to 1.
processIDs is declared elsewhere (outside this method) or not at all.
ProcessID is declared elsewhere (outside this method) or not at all.
Info is declared elsewhere (outside this method) or not at all.
you can fix several of the errors by adding
uint[] processIDs = null;
at the start
But I agree with Jon (duuh) that the question is not very clear.

Null exception when trying to use a list [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have StartingMap that inherits from Map. Here is what I am trying to do:
Map m_map;
List<Map> m_versions;
m_versions.add(new StartingMap(...)); // create null reference exeption
m_map= new StartingMap(...); // no error and load the map perfectly
Why do I get an error with the first one and not the second one ? I am doing the same thing.
You must instantiate m_versions, like
m_versions = new List<Map>();
you need to initialize the m_versions:
m_versions = new List<Map>();
before you can use it and add items to it.
You need to instantiate List before you add any items to the collection. In the second example you are just calling the constructor of StartingMap completely different things.
So before you can add any items to your list you need to:
m_versions = new List<Map>()

explicitly casting generics in C# 4 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Can anyone help me in casting generic collection in c# 4.
Here is the code snippet.
GridView1.DataSource = dataServiceColl.Select(t => t.product_desc="EdibileItem")
It is throwing up runtime error at the below line,
Gridview1.Databind();
Saying it is a HTTP Exception.
I think it should be a simple type cast.
Thanks,
Kris.
Use
t => t.product_desc=="EdibileItem"
HTTP Exception? That has nothing to do with casting.
More importantly, why are you assigning "EdibleItem" to t.product_desc here?
Select(t => t.product_desc="EdibileItem")
Did you meant == instead of =? If so, would a Where be more appropriate than a Select?
I think it all boils down to: what are you trying to achieve, exactly?

Scintilla custom syntax highlighting not working [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have a Scintilla control that I create in C#, and the syntax highlighting doesn't work. It sets the font correctly which tells me that the file is being loaded, but the syntax highlighting doesn't work at all:
Scintilla r = new Scintilla();
r.Dock = DockStyle.Fill;
r.ConfigurationManager.IsUserEnabled = true;
r.ConfigurationManager.CustomLocation = "langs.xml";
r.ConfigurationManager.Language = "rb";
r.Margins[0].Width = 40;
r.Indentation.UseTabs = true;
r.Indentation.IndentWidth = 4;
r.Indentation.ShowGuides = true;
r.Indentation.TabIndents = true;
r.Indentation.TabWidth = 4;
r.Indentation.SmartIndentType = SmartIndent.Simple;
and the configuration file is this:
http://codepad.org/DAjCrlPT
in langs.xml. (The code won't fit here.) Can someone tell me why this is not working?
Nevermind, my config file was wrong for some reason.

Categories