System.MissingMethodException: Method 'Newtonsoft.Json.JsonConvert.SerializeObject' not found - json.net

I have a Xamarin.Forms PCL project, and in it we are using JSON.NET to Serialize and deserialize. This works for 3 of our developers. On our 4th developers computer, anything that uses the deserialize function works fine, however if a line runs that uses Serialize, he gets the error:
System.MissingMethodException: Method 'Newtonsoft.Json.JsonConvert.SerializeObject' not found.
I'm having trouble figuring out how:
1) One method cant be found from a library, even though another one is working fine from the same library
2) How this is happening only on one developers machine?
We are using nuget to manage packages, and he has tried force reinstalling the latest version of json.net with no luck.
Does anyone have any idea what might fix this?

Related

WPF Caliburn.Micro uses wrong platform provider

In my ShellViewModel PlatformProvider.Current results in a XamlPlatformProvider as expected. In another ViewModel navigated to in a Frame PlatformProvider.Current results in a DefaultPlatformProvider.
Furthermore if I trigger a function in the ShellViewModel I can see that PlatformProvider.Current still results in a XamlPlatformProvider, so that ViewModel isn't affected.
This results in errors on Caliburn.Micro.Execute.OnUIThread and other platform specific calls such as using a BindableCollection.
It started happening after updating a large project to Caliburn.Micro version 4.0.173 from version 3.2.0.
I've been unable to reproduce the error in a smaller test project, so I can not show meaningful code.
I've tried replacing the whole bootstrapper with a minimal one and still see the error.
EDIT:
Creating a UI component from code within Caliburn.Micro.Execute.BeginOnUIThread gives the error:
"The calling thread must be STA, because many UI components require this".
Altering a BindableCollection gives the error:
"This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
The above scenarios work if I wrap them in a Application.Current.Dispatcher.Invoke which indicates that Caliburn.Micro fails to use the Dispatcher/UI thread.
I'm using C# on .NET Framework 4.8.
The second ViewModel, which was throwing errors was in a second project that included the NuGet package Caliburn.Micro.Core instead of Caliburn.Micro. Updating both to the same version solved the issue.
I had used NuGets Consolidate function to update Caliburn.Micro in the whole solution and had missed Caliburn.Micro.Core.

Difference between Newtonsoft Json DynamicValueProvider and ReflectionValueProvider?

I'm in the process of porting a Asp.Net Core Website targeting the full framework to a website that targets Asp.Net Core 3.
In that process I have hit a snag. The website references the Newtonsoft 11.0.3 NuGet package and among other things uses the Newtonsoft.Json.Serialization.DynamicValueProvider class.
Interestingly that class exists when targeting the full framework but does not exist when targeting netcoreapp3.1 and so Visual Studio is producing compilation errors stating that the class doesn't exist. At first that seemed crazy to me, but I checked the source code for the class and sure enough it contains the following conditional compilation statement wrapped around the whole class
#if HAVE_REFLECTION_EMIT
Apparently the netStandard 2.0 dll in the NuGet package that my netcoreapp3.1 project would use causes the conditional compilation statement to not include the DynamicValueProvider class.
So I did some poking around in the Newtonsoft.Json.Serialization namespace and I see that there is a ReflectionValueProvider class available that does not contain such conditional compilation and is available when targeting netcoreapp3.1
I've looked at the source code for both the DynamicValueProvider class and the ReflectionValueProvider class and I'm unclear on the difference. Both appear to get or set the value of a property or member type based on the MemberInfo passed in into the constructor. Both appear to use reflection to accomplish their work. As I mentioned, apparently DynamicValueProvider needs reflection Emit ability and ReflectionValueProvider does not. Emit ability apparently is used to Emit IL as best I can tell.
So I wonder if perhaps the two are drop in replacements for each other except that maybe DynamicValueProvider might be faster since it apparently leverages IL Emitting. But that's just a hunch. I'd prefer to have a more concrete understanding of the differences between the two classes before I start swapping the one for the other in this existing codebase as a way to get to .Net Core 3.
Can you provide me with better insight into the differences between the DynamicValueProvider
class and the ReflectionValueProvider class, or at least confirm my hunch?
We had updated Newtonsoft.Json from 9.* to 12.0.3 version, and observed performance degradation on paths that includes json serialization. All paths lead to DynamicValueProvider. Fortunately, we had global descendant for DefaultContractResolver, and I was able to overload CreateMemberValueProvider method to return ReflectionValueProvider.
For now we are continue testing the new version, but I can say that from performance perspective ReflectionValueProvider works faster than DynamicValueProvider.
I think there is a correlation with the fact that NetStandard 2.0 is also used to build Xamarin.Forms applications for iOS which require an AOT compilation.
As written here:
Limitations of Xamarin.iOS
"Since applications using Xamarin.iOS are compiled to static code, it is not possible to use any facilities that require code generation at runtime."
and
"No Dynamic Code Generation.
The System.Reflection.Emit is not available"
For example, this is a System.Text.Json limitation that actually cannot be used in Xamarin.Forms projects for iOS. More info here.
System.Text.Json Serializer does not appear to work on Xamarin iOS

.Net Core 3 Asking for Namespace that already exists

Hoping someone can help, ive just updated some nuget packages (from .net core preview to 3) ran a build and now get an error saying:
The type name 'SqlConnection' could not be found in the namespace. This type has been forwarded to assembly Consider adding a reference to that assembly.
As you can see from the image below i have got the names in there. but i believe the grey means that it doesnt think its using it? and im getting the error.
Any ideas on how to fix the issue?
Thanks

.NET Core - Project compiles and run, reSharper shows lots of errors on "FileStream" and "MemoryStream" objects

I have a .NET Core project which compiles and runs without errors.
However, ReSharper (version 2017.1.2) throws up a number of errors throughout the project, mostly related to stream objects.
For example:
Cannot convert source type 'System.IO.MemoryStream' to target type 'System.IO.Stream'
and when reading a stream
Module 'System.Private.CoreLib, Version=4.0.0.0 {snip}' should be referenced
I think it's related to the latter error, however as everything runs it's just frustrating that I can't track it down.
Or should I just get ReSharper to ignore these errors?
It's a known issue in ReSharper 2017.1.3 https://youtrack.jetbrains.com/issue/RSRP-464676.

Using nAnt to build projects containing EDMX

I've been working on training myself in the ways of using nAnt over the past few days, and have stumbled across an issue. During the development process, I've been using the new tools, like Entity Data Model, for database access.
When you go to try to build a library/executable that contains the Edmx product, you cannot embed the required files from visual studio. Now, I realize that I can do an exec task inside of nAnt and call msbuild for the particular project file, but I am trying to keep this to be completely nAnt build for now, so I'm in a heavy struggle to get things to work.
I did some searching to find a way ot handle this, and came across this Inline C# class that is supposed to do the trick. My problem is that I do not see how you call this in the target stack in order to get it to do its job. Can anyone shed some light on this? It would be of some great help.
Ok... so I'm a bit further along with this. I have since found that the code the gentleman has posted needs to be under the task for which it is meant to be run for. I'm even getting the *.ssdl, *.csdl, and *.msl files rendering into the directory... cool beans.
nwo i'm getting something interesting coming through... I've got reference via a "references" tag to System.Data.Entity, but I keep getting the following compile error:
error CS0234: The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Any suggestions?
OK!!!
Got it! I had to edit the NAnt.exe.config file and add the System.Data.Entity.dll file into the Framework element for the .net framework 3.5!!!
I may wind up building a 3.5 SP1 entry, and if someone can give me a good area to post it, I'd be good to go.

Resources