I'm currently getting the following error using the Json.NET/Newtonsoft.JSON library:
Missing method System.Numerics.BigInteger::Parse(string,IFormatProvider) in assembly
/usr/lib/mono/gac/System.Numerics/4.0.0.0__b77a5c561934e089/System.Numerics.dll,
referenced in assembly ~/dev/Mono/Mercury/Mercury/bin/Debug/Newtonsoft.Json.dll
This occurs every time that the Json retrieved from the couchDB database has a numeric value field. I discovered from searching that the method that the library is calling from System.Numerics isn't yet implemented in Mono.
The problem is that Json.NET is a dependency for another library that I'm using (WDK.API.CouchDB [3]).
Is there any way I can circumvent this without tweaking the source of any of the libraries? Any Suggestions?
PS: I'm using Mono 3.0.6 and MonoDevelop 4.0.8, on Linux. I just started learning C# and this is my first project with it. I tried to search the topic on the web with no fruitful result.
Thanks
[3] code.google.com/p/skitsanoswdk
To fix this you can add a reference to System.Numerics and then set its property Copy Local to true.
Use a 4.5 version of Json.NET until Mono fix it.
Have you tried any other method for converting strings to ints? I usually use Convert.ToInt32(//string) or if you want huge ints, then use Convert.ToInt64(//string)
Otherwise, check out. The TryParse() function is pretty handy:
http://www.dotnetperls.com/convert-string-int
If the method is not implemented, the best thing to do is implement it. Mono is an open source project. As such, if you cannot wait for the developers to implement something, you should step up and implement it, and send a pull request with your change.
Related
I am working with a project in .Net 2.0, this must stay in .Net 2.0 I have no way around this as this is what the customer wants.
I am trying to create a string that is going to url encode this
HttpUtility.UrlEncode(key);
However, I get the message
HttpUtility does not contain a definition for UrlEncode
Looking at MSDN here https://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode(v=vs.80).aspx I see that this should be easily possible.
I have my using statement bringing in System.Web and it is in my references too.
Any ideas on what I need to do?
If you are having trouble with system.web use the alternate method as shown in this blog. Html-and-Uri-String-Encoding-without-SystemWeb
Sounds like a dumb question I know, but bear with me :-) I'm currently creating a PoSh module which contains a few custom commands. I had already written a PoSh Advanced Module previously to do what I want to do, but I've decided it's time to take the plunge and learn C# !
One of my commands needs to create an instance of a class which is contained in a third party SDK assembly. That assembly is not contained in the GAC. In my PoSh Advanced Function previously, I would query a registry key to confirm that the SDK was installed (and get the path to it), then I would use System.Reflection.Assembly.LoadFile to load the assembly.
In my C# version, my plan was to do something similar. I've managed to query the registry, confirm that the assembly exists etc and even load it. However, because the assembly isn't referenced in Visual Studio, it just throws loads of intellisense errors when I try to instantiate a class from that assembly. I initially suspected I might need to use something from the Activator class to get around this, but I've been through all the methods there and couldn't find anything that might help.
After a bit more pondering, I wondered if perhaps my approach is wrong, and maybe I shouldn't be doing the "manual" loading but instead allow .net handle all that for me, eg by adding a reference to the assembly. In that case however, how do I reference an assembly in VS without knowing where (or even if) it will be installed on the target/invoking machine ?
Or, if my original approach is correct, how do instantiate the class "manually" (or otherwise) without VS being so unhappy. I did consider adding a "temporary" reference to the assembly on my machine, but I think I'd have to remove that again before doing the retail build. And I'd also have to add temporary using directives I guess.
I have googled this quite a bit, but haven't found anything that might help me at all. So I'd really appreciate any guidance anybody can provide. Maybe I should be looking at something else entirely, like App Domains ?
Thanks in advance
After loading assembly use CreateInstance method and store result in dynamic type variable:
dynamic test = assembly.CreateInstance("Full.Type.Name");
You'll not get intellisense, but compiler will assume that this variable supports any operation. Beware, invalid operations will result in errors only at runtime.
Before I put my question, I want to say that I have already searched on stackoverflow and several other websites about the problem, but the answers I found were not very satisfying in detail.
My problem is, I need to get a JSON data from an attribute in a HTML tag. I thought that it would be easier to achieve this using Python, and it was quite easy in fact. The code works like a charm. The problem is, I need to use this function in a C# class, so I need to use IronPython. When I import to code to my C# project and use IronPython to run call it, I get an error telling me 'No module named lxml'. According to other questions and posts on the internet on this topic, it is because lxml is not compatible with IronPython.
So I was wondering if it is possible to somehow make it compatible using some other libraries, or by using a replacement for IronPython. I would also very appreciate if you could direct me to any information about libraries I can use instead of lxml.
Here is the piece of code I use the lxml library:
tree = html.fromstring(page.content)
# Get the data-items value from the html
dt = tree.xpath('//*[#id="list-container"]/div[3]/div//table/#data-items')
Also I wonder if xml.etree.ElementTree is compatible with IronPython, and if it is, is there any way I can use both the xpath method and ElementTree instead of lxml and its functions
I am converting some old C# code, and it has a CountDownLatch using a package called Spring.Threading.Helpers. The odd thing is that I can't find this package on Google - so a) is it still supported? And, if so, where is it documented? b) What I really want to do is wait for a count to get to zero, but interrupt every so many msecs. Would it just be simpler to set up another thread, and do WaitOnes on an Event specifying an interval? TIA
It looks like it is part of spring.net - www.springframework.net - so my better question is: is spring.net a standard part (?) of Microsoft Visual C#?
Writing some test scripts in IronPython, I want to verify whether a window is displayed or not. I have the pid of the main app's process, and want to get a list of window titles that are related to the pid.
I was trying to avoid using win32api calls, such as FindWindowEx, since (to my knowledge) you cannot access win32api directly from IronPython. Is there a way to do this using built-in .net classes? Most of the stuff I have come across recommends using win32api, such as below.
.NET (C#): Getting child windows when you only have a process handle or PID?
UPDATE: I found a work-around to what I was trying to do. Answer below.
As of IronPython 2.6 the ctypes module is supported. This module provides C compatible data types, and allows calling functions in DLLs. Quick example:
import ctypes
buffer = ctypes.create_string_buffer(100)
ctypes.windll.kernel32.GetWindowsDirectoryA(buffer, len(buffer))
print buffer.value
The article below shows how to access the win32api indirectly from IronPython. It uses CSharpCodeProvider CompileAssemblyFromSource method to compile an assembly in memory from the supplied C# source code string. IronPython can then import the assembly.
Dynamically compiling C# from IronPython
It's like asking if you can swim without going in to the water. If you need information from windows, the only option is to use the win32api. There are lots of examples to find on how to do so.
If you don't like this answer, just leave a comment in your question and I will remove this answer, so your question will remain in the unanswered questions list.