Sudden Problems With Dynamic Not Working On (Only) My Machine - c#

My basic setup is this:
//caller
dynamic thingThatEndsUpBeingAJObject = JsonConvert.DeserializeObject(await httpClientResponse.Content.ReadAsStringAsync());
var parsedThing = Parse(thingThatEndsUpBeingAJObject);
//elsewhere...
private async Task<ParsedThing> Parse(dynamic json)
{
dynamic referenceToThingIWant = json.ThingIWant;
return new ParsedThing{ SomeProp = referenceToThingIWant; }
}
...where I end up getting a RuntimeBinderException on the reference to json.ThingIWant.
Oddly, if I put a watch on:
((JObject)json)["ThingIWant"]
I can see darn well that it's there!
Even more perplexing is that the code runs fine on everyone else's machine (and I believe it ran fine on mine till days ago)!
What on earth could cause such a strange quirk?!?
I've gone as far as restarting the computer, FWIW.
Specific error/stack trace is:
'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'ThingIWant'
at Microsoft.CSharp.RuntimeBinder.RuntimeBinderController.SubmitError(CError pError)

Related

ActivityNotFoundException for unknown reasons

I'm starting to learn Xamarin, and I'm stuck in this problem. There is an exception thrown
Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=Chris...
https://www.removeddit.com/r/greentext/comments/a9rwbb/anon_goes_to_christmas_dinner/eclyp8c
Background: I'm developing a small personal project that opens removeddit in a browser automatically from my phone through reddit.
The issue is it throws the exception when I run the code below. That probably would have been my mistake and I haven't googled enough. But surprisingly when I copy-paste and override the output link with the URI produced by the three lines of code in pre-processing, as observed in the debug line, the browser opens up with the right webpage.
Current Code that doesn't work:
//Let's call it pre-processing
string outputLink = inputLink.Substring(inputLink.LastIndexOf(' '));
outputLink = outputLink.Replace("reddit", "removeddit");
outputLink = outputLink.Trim();
Log.Info("DebugTag", outputLink);
Uri uri = Uri.Parse(outputLink);
var intent = new Intent(Intent.ActionView, uri);
StartActivity(intent);
Replacement code that makes it work in place of pre-processing:
string outputLink = "https://www.removeddit.com/r/greentext/comments/a9rwbb/anon_goes_to_christmas_dinner/eclyp8c"
I absolutely have no idea what the mistake might be and I'm completely baffled.
EDIT: Added exception I'm observing.

Getting MissingMethodException when using Manatee.trello to get list of users

I have the following code which is intended to fetch a list of all the user of an organisation.
public static IEnumerable<Member> ListTrelloUsers()
{
var serializer = new ManateeSerializer();
TrelloConfiguration.Serializer = serializer;
TrelloConfiguration.Deserializer = serializer;
TrelloConfiguration.JsonFactory = new ManateeFactory();
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
TrelloAuthorization.Default.AppKey = ApplicationKey;
TrelloAuthorization.Default.UserToken = GrandToken;
var myOrganization = Member.Me.Organizations.FirstOrDefault().Id; //Exception thrown here.
var orgToAddTo = new Organization(myOrganization);
return orgToAddTo.Members.AsEnumerable();
}
But I'm getting a
System.MissingMethodException
thrown on
RestSharp.IRestRequest RestSharp.RestRequest.AddFile(System.String, Byte[], System.String)
So why is this exception thrown and what should the correctly working code look like?
Clarifications
I will also accept working C#/ASP.Net MVC code that isn't based on Manatee.Trello as an answer. (Including pure API-calls.)
I have tried using the Organisation ID directly as
var orgToAddTo = new Organization(OrganisationId);
but that just caused the same exception to be thrown later when I make a call to the method's returned object (e.g. using Count()).
UPDATE: I tried setting the build to Release instead of Debug and now the (same) exception is instead thrown at
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
This is an issue with RestSharp that I reported quite some time ago, though they deny that it's a problem. If you're using .Net 4.5+, you can try the Manatee.Trello.WebApi package instead of Manatee.Trello.RestSharp.
TrelloConfiguration.RestProvider = new WebApiClientProvider();
Here's my Trello card for tracking the issue. This and this are the RestSharp issues I created.
I have been able to recreate this as well, but have received no help from them to resolve it.
Apperently, the class with missing method is located in an assembly, which differ from the one, which you used while compiling the project. Double check and make sure both at compiling and at execution you use the same assembly with the aforementioned class.
That is my best clue based on the info you've provided.
basically, check project references and make sure, you use correct ones for the class-holding assembly.

Unit test throwing NullReferenceException

I've been trying to run a test on a method that loads data from an xml file and returns it as a list, however, I keep getting a NullReferenceException when it runs. I've checked and my filepath is fine.
[TestCase(1)]
public void firstTest(int num)
{
var studentList = StudentListGenerator.CreateStudentList(#"../../TestReport/TestData.xml");
Assert.IsTrue(studentList.Count() > num);
}
The stack trace points back to a line of code in my CreateStudentList method that works just fine if I insert it directly into the test itself (the method as a whole works well when I run it normally).
String xData = File.ReadAllText(filePath);
var x = new XmlSerializer(typeof (Report));
Report dataConverted = (Report) x.Deserialize(new StringReader(xData));
// the last line is where the stack trace ends
Anyone have a guess as to where I'm going wrong?
EDIT:
Here's a link to some of the StudentListGenerator class, which contains the CreateStudentList method: https://gist.github.com/jekrch/eecdd1c8de8a11268be0
And here's the full stacktrace:
at PFdata.Dashboard.Data.StudentListGenerator.CreateStudentList(String
filePath) in
C:\Users\CodeCamp\Desktop\StudentDataDashboard\StudentDataDashboard\Dashboard.Data\StudentListGenerator.cs:line
41 at DashboardTests.StudentDataCalcTests.firstTest(Int32 num) in
C:\Users\CodeCamp\Desktop\StudentDataDashboard\DashboardTests\StudentDataCalcTests.cs:line
22 Result Message: System.NullReferenceException : Object reference
not set to an instance of an object.
So the stacktrace on the original error was misleading. The real source of the NullReferenceException in the CreateStudentList method that I was testing was the following line:
Application.Current.Properties["reportMonth"] = reportMonth;
The problem was that the Application class was not being instantiated by the test. So the solution was to simply instantiate the application at the beginning of the test like so,
var app = new Application();
I got the idea to try this from a comment by Ben Raupov regarding a question about a similar issue. Many thanks to Unicorn2 for helping me factor out a number of other possibilities.

Application changes not taking effect

I have made a change to a method used in a Functiod in a mapping file but it seems the new code is not taking effect, ever.
I have deployed properly, started the application, restarted related host instance (actually all host instances I could find) and still, the old code seems to execute.
Here's the, simple, method:
public string RemoveNonNumericChars(string stIn, int maxLength)
{
string strOut;
try
{
strOut = Regex.Replace(stIn, "[^0-9]", "");
System.Diagnostics.EventLog.WriteEntry("BizTalk Server 2009", strOut);
return strOut.Substring(0, maxLength);
}
catch
{
return string.Empty;
}
}
I added the writing to EventLog line to see that this code is indeed being executed, but I don't get anything in "Application" event logs.
I do NOT get an empty string being returned, so it really does seem like the old code that's being executed prior to me fixing the method.
What am I missing exactly ?
Thank you.
For some reason, the script is not able to correctly retrieve the Build Config selected in Visual Studio, it's taken from Debug when I'm actually trying to build it for a Test environment. I should have known, thanks anyways.

NUnit is not failing test with dynamic keyword of .Net 4.0

I am using NUnit with Visual Studio Express Edition 2010 for C#, Now, normally test works fine. But whenever I try to use Massive.cs, which is open source api to access database. Test fails from that file only. Now, if I run the application, api is working fine. I have created a different library file to access data base.
I seriously don't understand the error. It is just giving error that object reference is not set to an object. But if I run the code, it works fine. I am using dynamic keyword as shown in link of api above. Does that making problem with NUnit ?
Is there any other way to test in this type of Scenarios?
Here are the further details of the code,
Test class is like this
dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });
var items = item.All();
Assert.AreEqual("Maggi", items.FirstOrDefault().Name);
Now, I have put test here. Which gives error like shown in image,
Now if I run code in console application, then code is working fine, code snippet is given below
dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });
var result = item.All();
foreach (var i in result)
{
Console.WriteLine(i.Name + i.Description);
}
Console.Read();
Here, code is working and same thing is not working with NUnit Test. Please have a look and help me out. Please let me know if any further information is needed from my side.
Most probable explanation is that you haven't set up your connection string in the test project.
If you are using NUnit, just put it in app.config of your test project.
Solved... There is a issue with NUnit Testing. It was not taking config file pefectly. So, I made two changes. Changes I have done in Project setting.
First change is to change Application Base to bin\debug just give application base as this and then config file to .config to .exe.config and things are up and running. :)

Categories

Resources