Having trouble when using Newtonsoft.Json.dll externally. Entry points can not be found - json.net

A cad program called NX has to run a VB code in a specific project. Therefore I can not utilize nuget to install any library. I should call a dll and its methods inside the code.
Declare Auto Function GenerateJsonText Lib "D:\Lib\Nevtonsoft.Json.dll" Alias "SerializeObject" (ByVal inputObject As Object) As String
in order to call this:
Dim serializedText As String = GenerateJsonText(p)
here "p" is an object that is not detailed here.
When I run this cod I am getting an error :.... SerializeObject entry point has not been found in Newtonsoft.Json.dll
here you can find the namespace:
namespace definitions

Related

A Dictionary with a tuple as key could not be compiled

I keep having this error within a line of my code and I can't seem to fix it.
error BC30182: Type expected.
error BC30638: Array bounds cannot appear in type specifiers.
Here is my code:
Dim upload As Dictionary(Of (Long, Long, Long), Long)
It is located in Page_Prerender . The LangVersion for :default, latest or 16.9 could not be set also. (the value 'default' is invalid for option 'langversion'). The error occurs in vs2019 and vs2022 community version. However it runs fine on LinqPad5 and other VB project. I deleted all my obj files and rebooted :(. Maybe I have to delete some other object files in appdata or elsewhere?
I tried to compile it in previous version of visual studio, deleted obj files, changed langversion.

How to use "&" in CIL .data-declarations

I am writing a compiler targeting the common intermediate language and want to use .data-declarations for globals. I mean section II.16.3.1 of the Spec.
How can I use what is described as "Address of label"? The following does assemble using .NET-Core's ilasm:
.assembly extern mscorlib
{
.ver 4:0:0:0
}
.assembly 'string'
{
}
.module 'string'
.data hello_world_data = { int8(72), int8(101), int8(108), int8(108), int8(111), int8(32), int8(87), int8(111), int8(114), int8(108), int8(100), int8(33), int8(0) }
.field static int8 hello_world at hello_world_data
.data addr_of_data = &(hello_world_data)
.field static int8* hello_world_ptr at addr_of_data
.method public static default int32 main () cil managed {
.entrypoint
ldc.i4.0
ret
}
But when I try to execute the code above, I get the following error message (using .NET-Core on Linux):
Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/home/lou/uni/proj/stuff/tests/test-global-arrays/string.exe'. An attempt was made to load a program with an incorrect format.
File name: '/home/lou/uni/proj/stuff/tests/test-global-arrays/string.exe'
[1] 12019 abort (core dumped) dotnet string.exe
Any ideas/help?
If this is important for you, I would suggest filing an issue in the https://github.com/dotnet/runtime repo.
I assume the reason this doesn't work outside Windows is because these directives generate data with relocations (places within the executable that need to be fixed up with a real address once the executable is loaded into memory). Since the format of the executables in .NET is based on the Windows PE format, the relocation is processed by Windows when it loads the executable.
Outside Windows, CoreCLR ships with a small "Windows loader emulator" that loads the .NET executables the way Windows would load them. But it probably misses the handling for these relocations. The IL format doesn't generate relocations otherwise.
But these relocations are going to be problematic in many places (I fully expect e.g. tools like the IL Linker to miss them and damage them, I assume Mono doesn't have handling for the these either, they are going to be problematic for AOT compilation, etc.).

Replicating a java -jar execution through rJava

I have a java file that I would normally execute by doing
java -jar jarname.jar arguments
I want to be able to run this file from R in the most system agnostic way possible. My current pipeline partially relies on rJava do identify JAVA_HOME and run the jar by doing
# path for the example file below
pathToJar = 'pdftk-java.jar'
# start up java session
rJava::.jinit()
# find JAVA_HOME
javaPath = rJava::.jcall( 'java/lang/System', 'S', 'getProperty', 'java.home' )
# get all java files
javaFiles = list.files(javaPath,recursive = TRUE,full.names = TRUE)
# find java command
java = javaFiles[grepl('/java($|\\.exe)',javaFiles)]
# run the jar using system
system(glue::glue('{shQuote(java)} -jar {shQuote(pathToJar)} arguments'))
This does work fine but I was wondering if there was a reliable way to replicate execution of a jar through rJava itself. I want to do this because
I want to avoid any possible system dependent issues when finding the java command from JAVA_HOME
I already started an rJava session just to get the JAVA_HOME. I might as well use it since .jinit isn't undoable
I not that familiar with what calling a jar through -jar does and I am curious. Can it be done in a jar independent way? If not what should I look for in the code to know how to do this.
This is the file in I am working with. Taken from https://gitlab.com/pdftk-java/pdftk/tree/master
Executing JAR file is (essentially) running class file that is embedded inside JAR.
Instead of calling system and executing it as external application, you can do following:
make sure to add your JAR file to CLASSPATH
rJava::.jaddClassPath(pathToJar)
check inside JAR file what is the main class. Look into META-INF/MANIFEST.MF file to identify the main class. (In this case com.gitlab.pdftk_java.pdftk)
instantiate class inside R.
newObj = rJava::.jnew('com/gitlab/pdftk_java/pdftk')
run the class following way: http://www.owsiak.org/running-java-code-in-r/
Update
Running JAR file (calling main method of Main-class) is the same things as calling any other method inside Java based class. Please note that main method takes array of Strings as argument. Take a look here for sample: http://www.owsiak.org/running-jar-file-from-r-using-rjava-without-spawning-new-process/
newObj$main(rJava::.jarray('--version'))
For this specific case if you look at the source code for this class, you'll see that it terminates the session
public static void main(String[] args) {
System.exit(main_noexit(args));
}
This will also terminate your R session. Since all main function does it to call main_noexit then exit, you can replace main with main_noexit in the code above.
newObj$main_noexit(rJava::.jarray('--version'))

Namespaces in Imports field not imported from: All declared Imports should be used

I am working on my R package. I am getting this error:
Namespaces in Imports field not imported from:
‘kableExtra’ ‘ranger’
All declared Imports should be used.
I get this error with devtools::check_rhub() i.e. on linux and windows platform. When I check my package locally (mac os) with devtools::check() all checks gets passed successfully.
I looked deeper into the imports of my description file, currently I am doing:
Imports:
ranger(>= 0.10.1),
Metrics(>= 0.1.3),
kableExtra(>= 0.9.0)
I am using functions from ranger and kableExtra using :: like ranger::function_name, kableExtra::function_name since there are just one or two functions I need.
I am not doing importFrom in Namespace file. Because, like I said, there are just 1 or 2 functions I need to borrow.
Why am I getting this error ? What am I missing ?
I fixed the problem with this workaround:
Add the name of the package in Namespace file with importFrom.
Doesn't matter if you are borrowing just one function from a package using ::, if the package name is mentioned in the Imports or Depends, it will raise an error.

System.AccessViolationException with Sqlite.Connection.LoadExtension()

I have an old 2005 VB.NET application that requires a Sqlite update for JSON functions.
I have downloaded and installed "sqlite-netFx20-setup-bundle-x86-2005-1.0.109.0.exe". I removed the Reference to the older version, and re-referenced to this new version. I compiled a run the program - all seemed to be okay.
Using an online example for JSON, put the following code behind a TestButton:-
jsondb.SQL = "CREATE TABLE user (name, phone)"
ExecuteSQLiteCommand(jsondb)
jsondb.SQL = "INSERT INTO user (name, phone) values('oz', json('{""""cell"""":""""+491765"""", """"home"""":""""+498973""""}'))"
ExecuteSQLiteCommand(jsondb)
When the "INSERT" is executed, I get "json function not found".
After more research, I found that I had to enable the json extensions with:-
mySQLdb.Connection.Open()
mySQLdb.Connection.EnableExtensions(True)
mySQLdb.Connection.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init")
Initially, the .LoadExtension failed because the "SQLite.Interop.dll" module was not found.
I found a copy of this module in "sqlite-netFx20-binary-Win32-2005-1.0.109.0.zip" and copied it into the Sqlite install directory, and changed the .LoadExension method to:-
mySQLdb.Connection.LoadExtension("C:\Program Files\System.Data.SQLite\2005\bin\SQLite.Interop.dll", "sqlite3_json_init")
Now the .LoadExension method raises an exception "System.AccessViolationException".
Does anyone know how I can resolve this issue?
Thanks in advance.
It seems that because I have the Sqlite Reference attribute CopyLocal=true, then the folder location for System.Data.SQLite.dll and SQLite.Interop.dll need to be the same.
Changing the .LoadExtension to:-
mySQLdb.Connection.LoadExtension(My.Application.Info.DirectoryPath & "\SQLite.Interop.dll", "sqlite3_json_init")
Fixed this.

Resources