Page 1 of 1

Bug in ProgramEntry.cs

Posted: Sat Feb 13, 2021 4:16 pm
by BPalmer
Our plugin has dependencies that will resolve with failures (not avoidable, blaming grpc due to its multi-platform features), the problem is that resolveArgs.Name will not always have commas so opendental will crash.

ProgramEntry.cs line 94 (at least in v19.4)

Below is code that would fix the issue, just checking to make sure that arrParts[] actually contains elements before continuing.

Could we please get this fixed and backport it? Thanks

Code: Select all

private static Assembly AssemblyResolveFailures(object sender,ResolveEventArgs resolveArgs) {
	string assemblyInfo=resolveArgs.Name;// e.g "Lib1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
	string[] arrParts=assemblyInfo.Split(',');
	if (arrParts.Length > 1) {
		string name = arrParts[0];
		Version version = Version.Parse(arrParts[1].Split('=')[1]);
		string fullName;
		if (name == "Newtonsoft.Json" && version.Major.In(7, 9)) {
			//OpenDentalCloud.dll references Dropbox.Api.dll which references Newtonsoft.Json.dll version 7.0.0.0. Sometimes it also says it can't find 
			//9.0.0.0.
			fullName = ODFileUtils.CombinePaths(AppDomain.CurrentDomain.BaseDirectory, "Newtonsoft.Json.dll");
		}
		else {
			return null;
		}
		return Assembly.LoadFile(fullName);
	}
	else
		return null; 
}

Re: Bug in ProgramEntry.cs

Posted: Tue Feb 16, 2021 9:29 am
by joes
Does our current stable version (20.4) cause any issues for your plugin in ProgramEntry? If not, I would advise your users to update to the latest stable version.

Re: Bug in ProgramEntry.cs

Posted: Tue Feb 16, 2021 10:34 pm
by jordansparks
Right. That entire method is gone as of 20.2. I could backport a 3 line fix, but I'm afraid to, because I have no way to test the necessary scenarios. I didn't write that section, so I don't understand it deeply enough. I don't want to destabilize it.

Re: Bug in ProgramEntry.cs

Posted: Fri Feb 19, 2021 8:12 am
by BPalmer
The problem still exists in 20.4, the method just got moved to CodeBase.ODInitialize.FixNewtonsoft. All assembly resolving errors application wide still go through this method, so the array out of bounds fatal error will still occur.

One possible 1-line fix:
This fix will still allow newtonsoft.json to resolve properly but will prevent any out of bound exceptions when other assembly resolving errors that aren't newtonsoft.json occur.

Code: Select all

...
string name =arrParts[0];
if (arrParts.Length <= 1) return null;
Version version=Version.Parse(arrParts[1].Split('=')[1]); //Crash happens on this line, index out of bounds
...
One fix option for >20.2 (and possibly other) if you decide not to backport:
Delete the commented out line, as the version variable isn't used

Code: Select all

...
string name =arrParts[0];
//Version version=Version.Parse(arrParts[1].Split('=')[1]); //Crash happens on this line, index out of bounds
string fullName;
...
Also one detail I noticed, in the comment in 20.4 above the method it says " you can call this method to force any failed loads of Newtonsoft to use the specified dll.". That isn't true because the method is called from ProgramEntry.cs, so it is already applied application-wide and doesn't need to be called ever again, so with FixNewtonsoft(), I dont see why it should be static or public.. Anyways, just my two cents and unsolicited advice. :mrgreen:

Re: Bug in ProgramEntry.cs

Posted: Fri Feb 19, 2021 2:14 pm
by joes
We can remove the unused variable. I'll update you when the fix is released.

Re: Bug in ProgramEntry.cs

Posted: Mon Feb 22, 2021 7:10 pm
by BPalmer
Great, thank you

Re: Bug in ProgramEntry.cs

Posted: Tue Feb 23, 2021 8:23 am
by joes
The unused version variable will be removed in the following versions: 20.2.51.0, 20.3.58.0, 20.4.51.0, 20.5.27.0
These versions will likely be released some time today.