CodeEffects exception with .net core 3.1 and running in docker container - codeeffects

After the upgrade from .net core 2.2 to 3.1 (without changing codeffects related code or library versions) we have problems when loading the xml into the rule editor (in the backend), but only when running the application in a docker container (which is based on mcr.microsoft.com/dotnet/aspnet:3.1.11 image). When running exactly the same code from Visual Studio everything is fine. Like it is also if we revert to the .net core 2.2 version of the app.
The problem is on loading the existing rule xml into the rule editor:
editor.LoadRuleXml(ruleXml);
or this way
editor.Rule = CodeEffects.Rule.Models.RuleModel.Create(ruleXml, type);
The exception is:
CodeEffects.Rule.Common.InvalidRuleException: Invalid rule XML. Input string was not in a correct format. (#125) at CodeEffects.Rule.Formats.Ce.FillRule(List`1 list, XmlNode ruleXml, XmlDocument sourceXml, GetRuleDelegate ruleDelegate, Type sourceObject) at CodeEffects.Rule.Formats.Ce.LoadXml(XmlDocument rule, XmlDocument source, GetRuleDelegate ruleDelegate, Type sourceObject) at CodeEffects.Rule.Core.RuleLoader.LoadXml(XmlDocument rule, XmlDocument source, RuleFormatType format, GetRuleDelegate getRuleDelegate, Type sourceObject) at CodeEffects.Rule.Core.RuleLoader.LoadXml(String xmlRule, XmlDocument sourceXml, GetRuleDelegate ruleDelegate, Type sourceObject) at CodeEffects.Rule.Web.RuleEditor.LoadRuleXml(String ruleXml, GetRuleDelegate ruleDelegate) at CodeEffects.Rule.Web.RuleEditor.LoadRuleXml(String ruleXml)
Logging the xml that we pass to the load method shows that the xml is as it should be, so like it was stored in the db, and this same xml otherwise works fine, just not when the app is running in a docker based on .net core 3.1.
Unfortunatelly there is no inner exception that would point us closer to the source of the problem. And since it can be only reproduced when running in docker container, we are running out of ideas.
Our version of CodeEffects.Rule.Editor.Web.Core library is quite old, 5.0.7.6, but the same problem persists even if we upgrade to the latest 5.0.38.4.
Any idea what could be the problem?

Related

Quartz 2.6.2 and .NET Core? - Error "Could Not Initialize DataSource"

I'm using an older version of Quartz.NET (v2.6.2) with .NET Core (or possibly .NET5). I'm getting an error when attempting to use the StdSchedulerFactory.GetScheduler. All my configuration settings are within my appsettings.json where I populate a NameValueCollection with these values and inject them into my classes with DI.
["quartz.scheduler.instanceId"] = "instance_one",
["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz",
["quartz.threadPool.threadCount"] = "5",
["quartz.jobStore.misfireThreshold"] = "60000",
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
["quartz.jobStore.useProperties"] = "false",
["quartz.jobStore.dataSource"] = "default",
["quartz.jobStore.tablePrefix"] = "QRTZ_",
["quartz.dataSource.default.provider"] = "SqlServer-20",
["quartz.dataSource.default.connectionString"] = quartzConn
I am using the StdSchedulerFactory like this, where Settings.Properties is that NameValueCollection which contains all the config settings:
var factory = new StdSchedulerFactory(Settings.Properties);
var scheduler = factory.GetScheduler();
On the GetScheduler method, the error, "Could Not Initialize Datasource: default" is thrown.
The crazy thing is this code works fine in a Framework 4.x project that uses a regular web.config to supply the configuration settings. Also, when I change to use Quartz 3.X with my code above, with configurations in the appsettings.json works fine. Seems that me mixing and matching both versions is causing an issue where Quartz doesn't know how to retrieve some value?
Is there a way to manually build my scheduler and not use the factory?
Thanks!
I've had to go back to Framework 4 and Quartz 2.6 to get them to play nicely together. I can only get Quartz 3.x to work with .NET Core/5. Stepping through the source code with dotPeek, Quartz 2.6 is using ConfigurationManager to pull web.config details that don't exist in Core/5. At this point I don't remember if I tried to add my own web.config file to this project or not, but I've since moved on.

Unexpected behaviour from Gson

I developed a small application that stores data coming from a device: I chose to store data in JSON format, and the serialization/deserialization of the data works just fine, even if it involves some custom types created by me...but only I work in the IDE (Eclipse, for that matter).
When I export a runnable JAR file though, the deserialization of the data encounters some kind of problem, because the software always throws this exception:
Caused by: java.lang.UnsupportedOperationException: Cannot allocate class LocalDateTime
at com.google.gson.internal.UnsafeAllocator$4.newInstance(UnsafeAllocator.java:104)
at com.google.gson.internal.ConstructorConstructor$14.construct(ConstructorConstructor.java:225)
... 88 common frames omitted
I thought I'd encounter problems with custom types, not a built-in one. At this point, I discovered two things:
if I use a full JRE 9 to run the JAR file, the exception is not thrown: I double checked the modules included in the custom JRE I created with Jlink.exe, and everything is included correctly. I still want to use a smaller JRE, so I did not investigate further yet (I guess this explains why in the IDE it works perfectly)
I added a custom deserializer to the Gson object (see below), with which I simply manually converted the JSON string into a valid data, and that avoided the exception on the LocalDateTime class...but the exception reappeared simply on another class, this time a custom-made one.
At this point, I guess I can simply add a deserializer for each data type that causes problem, but I'm wondering why the issue won't happen with a full JRE, and why a smaller JRE causes this, even if all the modules required are included. Maybe it's worth mentioning also that I added no custom serializer to the Gson object that saves the data, it is all serialized as per Gson default.
LocalDateTime deserializer:
#Override
public LocalDateTime deserialize(JsonElement json, java.lang.reflect.Type type,
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject joDate = json.getAsJsonObject().get("date").getAsJsonObject();
JsonObject joTime = json.getAsJsonObject().get("time").getAsJsonObject();
//JSON example: {"date":{"year":2019,"month":1,"day":9},"time":{"hour":6,"minute":14,"second":1,"nano":0}
return LocalDateTime.of(joDate.get("year").getAsInt(),
joDate.get("month").getAsInt(),
joDate.get("day").getAsInt(),
joTime.get("hour").getAsInt(),
joTime.get("minute").getAsInt(),
joTime.get("second").getAsInt(),
joTime.get("nano").getAsInt());
}
}
Jdeps.deps modules list:
com.google.gson
java.base
javafx.base
javafx.controls
javafx.fxml
javafx.graphics
org.slf4j
After the answer I received, I opened an issue here.
TL;DR
You need a runtime image (e.g. full JDK or something built with jlink) that includes the module jdk.unsupported.
Full Answer
GSON wants to create instances of classes it deserializes without calling any constructors (so nothing gets initialized without GSON saying so). This can't normally be done, but sun.misc.Unsafe offers a way to do this with the method allocateInstance. To that end, GSON needs an instance of sun.misc.Unsafe. The topmost frame in the call stack is from UnsafeAllocator, which uses common trickery to get Unsafe.
The problem is, sun.misc.Unsafe is in module jdk.unsupported, which is present in a full JDK but you won't usually find in runtime images.
When creating your runtime image with jlink, make sure to include the option --add-modules jdk.unsupported and you should be good to go.
Arguably, GSON should declare an optional dependency on jdk.unsupported with requires static.
I have faced the same issue when packing compose a desktop application.
update build.gradle file, add an unsupported module.
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "admin"
packageVersion = "1.0.0"
modules("java.sql")
modules("jdk.unsupported")
}
}
}

JSON Parser -java.lang.NoSuchFieldError: defaultReader

I am using a JSON parser to extract the value and I am using the following jar
json-path-2.1.0, and I am getting the following error when I invoke the use case deployed as webservice on weblogic server
I wrote a small main program to extract the value from the json string and it works fine, but the server version of the use case is giving the issue. I am not sure if there are any other jars part of my ear can negatively impact this
SEVERE: defaultReader
java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
Stumbled about the same problem.
The reason why it does not work is not the JDK 8.
The reason why you encounter this issue, is the fact that weblogic 12.2.1.X is bundling some old version of json-smart.
On my machine this would be found here:
jar:file:/C:/dev/WLS_12_2_1_2_0/oracle_common/modules/net.minidev.json-smart.jar!/net/minidev/json/JSONValue.class
Now if you are using a library like json-path that depends on json-smart, then by default the container will load the required class using one of its built-in modules.
The blowup you have, seems to be that the JSONValue class that your json-path depends on seemed to have this defaultReder field.
Here is a snipet of the clode that is blowing up.
public JsonSmartJsonProvider() {
this(JSONParser.MODE_PERMISSIVE, JSONValue.defaultReader.DEFAULT_ORDERED);
}
That
JSONValue.defaultReader
Seems not to be valid on weblogs older system class loader class.
You can tell the container to use what you are packing by putting into your weblogic.xml deployment descriptor something like this:
<wls:prefer-application-packages>
<wls:package-name>net.minidev.json.*</wls:package-name>
</wls:prefer-application-packages>
I am having quite a bit of trouble getting weblogic to swallow the fine-grained instruction above.
I found myself to force weblogic to swallog all that goes into the web-inf folder instead doing:
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
I would have rather not be using a hammer like the web-inf-classes, but I am dancing with the weblogic system classloader when I do not go coarse grained...
Regards.
I too was facing this issue, It turned out some other library was using json-smart's older version, and it was getting precedence over json-path's json-smart dependency. Removing the other jar solved the issue. Or you can also downgrade your json-path's version to appropriate version such that it support json-smart's older version.
Looks like JsonParser jar is present in JVM 1.8 version and it seems to have more precedence over the JsonParser class available in Json-path.jar. Apparently the us case doesn't work in 12.2.1 version of the weblogic server but it works fine in 12.1.3
I had the same problem but I use Gradle so I had to add:
compile group: 'net.minidev', name: 'json-smart', version: '2.3' to my dependencies.

Sonar Unit tests report parameter - sonar.junit.reportPath vs sonar.java.junit.reportPath

I found that my Sonar instance 5.1 or 5.1.1 (with latest sonar-runner 2.x) stopped showing part of the Unit test info (Unit test widget) on the project's dashboard.
The properties I had were (in Gradle's sonarRunner > sonarProperties section):
property "sonar.junit.reportsPath", "build/test-results/UT"
property "sonar.surefire.reportsPath", "build/test-results/UT"
To fix it, I had to include the following properties as well:
property "sonar.java.junit.reportsPath", "build/test-results/UT"
property "sonar.java.surefire.reportsPath", "build/test-results/UT"
Just FYI: All my Unit tests reports go under build/test-results/UT folder, all Integration Tests result files go unedr build/test-results/IT folder and etc.
I'm wondering if this is due to Gradle version that I'm using (2.3) or is it due to a later version of SonarQube (4.5+) as I have both SQ 5.1 and 5.1.1 instance.
I know SonarQube team started Multi language support since SonarQube version 4.12
Since SonarQube 4.2, it is possible to run an analysis on a multi-language project.
Now, it raises a question. For Getting the same Unit test info for Groovy based projects, do I need to use:
property "sonar.groovy.junit.reportsPath", "build/test-results/UT"
property "sonar.groovy.surefire.reportsPath", "build/test-results/UT"
something like that if my project has Groovy code instead of java?
Searching "**sonar.java.junit.reportPath"** with using double quotes shows No results found in Google and it forces me to try and see google results if I can run the search again without using " double quotes (for this property).
Doing the same in SonarQube site "search box" shows:
No results found for sonar.java.junit.reportPath. Please try one of the following suggestions:
Though in Gradle, inside
sonarRunner task {
.. inside ..
sonarProperties {
... section ... where I define various sonar props..
}
...
}
I can define both sonar.junit.reportPath, sonar.java.junit.reportPath and similarly, sonar.surefire.reporPath and sonar.java.surefire.reportPath and while running sonarRunner task in Gradle, it doesn't error out. Thus it makes me believe that the property variables are valid.
There are also issues with running sonarRunner or stand alone sonar-runner command for a mixed Java and Groovy based project (i.e. source code in Java but tests in Groovy). Setting sonar.language=java,grvy didn't help. I posted this question on stackoverflow but so far I have no perfect result/answer on how to get a full fledged sonar dashboard up and running for a Groovy projects like I get for a Java project.
Groovy project - Sonar - Publish project and Unit + Integration Test code coverage data
PS: I have tried various values for setting sonar.. variables (as far a sonar source, tests, etc, etc properties are concerned, which they have mentioned on their site's docs section)
The only valid property to use as of now is sonar.junit.reportsPath which will tell the java sonarqube plugin where to import your result of unit tests.
For groovy, this is work in progress, see : http://jira.sonarsource.com/browse/SONARGROOV-2
All the other properties you mentioned do not exist and are not taken into account.

Microsoft Azure dll throws an exception in .NET 4.0

I have developed on EXE project(use for startup task) and use following dlls of Microsoft Azure ,
It's work very well in .Net framework 3.5 but in my case i need to use system.runtime.serialization to serialize class as json string as per following way
public static string Serialize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new
System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
string retVal = Encoding.Default.GetString(ms.ToArray());
ms.Dispose();
return retVal;
}
For this i need to change framework to 4.0 but at that time i got exception from Azure dlls
like
The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
I think all Microsoft's dlls are with backward compatibly so what's going wrong in this matter?
I should find another way to serialize to json string?
OR
I should to change Azure's dlls to latest version?
Thanks in Advance.
If you write a console app in .NET4 and want to use the RoleEnvironment then you’ll get an error:
The type initializer for ‘Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment’ threw an exception.
To get around this, just add a “useLegacyV2RuntimeActivationPolicy” to the startup tag generated in the default app.config:
<startup useLegacyV2RuntimeActivationPolicy="true">
This is because Microsoft.WindowsAzure.ServiceRuntime.dll is a mixed mode assembly. The useLegacyV2RuntimeActivationPolicy attribute is required for referencing any mixed mode assembly, not only the Windows Azure ones.
One thing you might want to check is target framework for your .Net project in Visual Studio. By default when you create a project in VS using .Net framework, it uses ".Net Framework 4 Client Profile". Try changing it to ".Net Framework 4" and see if that helps.