Bug in ProgramEntry.cs

This forum is for programmers who have questions about the source code.
Post Reply
BPalmer
Posts: 6
Joined: Wed Jun 28, 2017 7:05 pm
Location: United States

Bug in ProgramEntry.cs

Post by BPalmer » Sat Feb 13, 2021 4:16 pm

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; 
}

joes
Posts: 239
Joined: Tue Aug 13, 2019 12:41 pm

Re: Bug in ProgramEntry.cs

Post by joes » Tue Feb 16, 2021 9:29 am

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.
Joe Sullivan
Open Dental Software
http://www.opendental.com

User avatar
jordansparks
Site Admin
Posts: 5739
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Bug in ProgramEntry.cs

Post by jordansparks » Tue Feb 16, 2021 10:34 pm

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.
Jordan Sparks, DMD
http://www.opendental.com

BPalmer
Posts: 6
Joined: Wed Jun 28, 2017 7:05 pm
Location: United States

Re: Bug in ProgramEntry.cs

Post by BPalmer » Fri Feb 19, 2021 8:12 am

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:

joes
Posts: 239
Joined: Tue Aug 13, 2019 12:41 pm

Re: Bug in ProgramEntry.cs

Post by joes » Fri Feb 19, 2021 2:14 pm

We can remove the unused variable. I'll update you when the fix is released.
Joe Sullivan
Open Dental Software
http://www.opendental.com

BPalmer
Posts: 6
Joined: Wed Jun 28, 2017 7:05 pm
Location: United States

Re: Bug in ProgramEntry.cs

Post by BPalmer » Mon Feb 22, 2021 7:10 pm

Great, thank you

joes
Posts: 239
Joined: Tue Aug 13, 2019 12:41 pm

Re: Bug in ProgramEntry.cs

Post by joes » Tue Feb 23, 2021 8:23 am

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.
Joe Sullivan
Open Dental Software
http://www.opendental.com

Post Reply