Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breaking dll rename of SharpZipLib - issue #2095 #2118

Merged
merged 4 commits into from
Jun 19, 2018
Merged

Fix breaking dll rename of SharpZipLib - issue #2095 #2118

merged 4 commits into from
Jun 19, 2018

Conversation

iJungleboy
Copy link
Contributor

Summary

Fixes #2095 by registering an assembly-resolver that is used by .net when an assembly isn't found. So if something tries to get SharpZipLib.dll and fails, this resolver will kick in and tell .net that it's in the new assembly ICSharpCode.SharpZipLib.

I also added a readme.md explaining it some more, and the "register assembly handler" must happen very early, which is why I needed to put it into the application start.

Copy link
Contributor

@tpluscode tpluscode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this solution. Very clean 👍

I suppose we could revert #2019 once this is merged?

}
catch
{
/* ignore */
Copy link
Contributor

@tpluscode tpluscode Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what circumstances is an exception here possible? Swallowing it will mean that the redirect will not fire, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is to ensure that if anything at all goes wrong when registering this, it won't break DNN.

{
// only check for access to old SharpZipLib
if (!args.Name.StartsWith(OldName))
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add braces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that the DNN convention? or your personal preference? just to be sure...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a DNN convention, given that no official conventions exist. It is however a sensible choice always to add curly brackets and also a StyleCop inspection, enabled by default I think

/// </summary>
public static void RegisterSharpZipLibRedirect()
{
if (AlreadyRun) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add braces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DNN convention?

@bdukes
Copy link
Contributor

bdukes commented Jun 13, 2018

@tpluscode it doesn't look like #2019 was ever merged

@tpluscode
Copy link
Contributor

Oh, true. Good :)

private static Assembly Handler(object sender, ResolveEventArgs args)
{
// only check for access to old SharpZipLib
if (!args.Name.StartsWith(OldName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add StringComparison.Ordinal as second parameter to StartsWith

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is using StartsWith instead of Equals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will do. I think I originally used the name without DLL, so equals should be ok. i'll change it.

Copy link
Contributor Author

@iJungleboy iJungleboy Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that it needs starts with, because the real string looks something like this SharpZipLib, Version=0.81.0.1407, Culture=neutral, PublicKeyToken=null.

I get this error, if I use equals (because the mapping then fails):

image

/// final solution taken from https://raw.githubusercontent.com/2sic/2sxc/master/2sxc%20Dnn/Dnn920/SharpZipLibRedirect.cs
/// read the readme.md in this folder for more info
/// </remarks>
public class SharpZipLibRedirect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not real excited about this being public, seems like it will confuse folks that there's a DotNetNuke.Services.Zip namespace that doesn't have anything useful for them inside of it. Should this just live next to (or inside of) DotNetNukeHttpApplication?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, internal would be better if we can

Copy link
Contributor Author

@iJungleboy iJungleboy Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok great suggestion! I found that I can make it internal

@@ -0,0 +1,11 @@
# Zip Services in DNN

DNN uses SharpZipLib as the zip system of choice. Because of this, it is bundled with DNN.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that this be included as comments in the SharpZipLibRedirect class, rather than as a markdown document.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer markdown - because often explanations will need multiple code files, but I'll put the same info into the class file as well - ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the project I would ONLY have this in the code comments. Multi-line XML comments can support HTML formatting and will be automatically built into the documentation. THis is used universally across the entire solution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchelsellers ok, I just moved all the docs into code-comments only

@iJungleboy
Copy link
Contributor Author

Thanks for the thorough review! I'm updating everything as discussed, after testing I'll republish...

@iJungleboy
Copy link
Contributor Author

Changes made and published, pls re-check, thx!

@ohine
Copy link
Contributor

ohine commented Jun 15, 2018

I'm guessing we need to update this function as well with both assembly names? or change the StartsWith to Contains? Right @bdukes?

bool canScan = !(assemblyName.StartsWith("clientdependency.core") || assemblyName.StartsWith("countrylistbox")
|| assemblyName.StartsWith("icsharpcode") || assemblyName.StartsWith("fiftyone")
|| assemblyName.StartsWith("lucene") || assemblyName.StartsWith("microsoft")
|| assemblyName.StartsWith("newtonsoft") || assemblyName.StartsWith("petapoco")
|| assemblyName.StartsWith("sharpziplib") || assemblyName.StartsWith("system")
|| assemblyName.StartsWith("telerik") || assemblyName.StartsWith("webformsmvp")
|| assemblyName.StartsWith("webmatrix") || assemblyName.StartsWith("solpart")
);

@iJungleboy
Copy link
Contributor Author

@tpluscode @bdukes @ohine I believe I did everything you guys asked for. Ok for now, or anything still pending?

/// </remarks>
internal class SharpZipLibRedirect
{
internal static bool AlreadyRun { get; private set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I notice this changed from public to internal. But does it really have to be accessible from anywhere? I'd expect such property to be private

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave it in for debugging - in case this is ever questioned. But I can change it if that is preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion here. Let's leave it as is

@bdukes
Copy link
Contributor

bdukes commented Jun 15, 2018

Good catch @ohine, I'd just add both

@iJungleboy
Copy link
Contributor Author

@bdukes and @ohine I don't understand that part about the other code. Should I do something there? I've never used/seen that code before.

@ohine
Copy link
Contributor

ohine commented Jun 17, 2018

@iJungleboy I've never seen that code either, I was researching the SQL dependency issue (#2116) and stumbled across that function in the process. We should add both of the assembly names to that function. If you can do it in this pull request that would be great, if not I'll start up another pull request with that change.

@iJungleboy
Copy link
Contributor Author

@ohine I would rather not touch that - I don't know anything about it and it's not related to the sharpziplib issue directly - ok?

I believe we've covered everything - shall we finish the pull @bdukes and @tpluscode ?

@mitchelsellers
Copy link
Contributor

I think that we need determine WHY those DLL's are excluded from the scanning process before we fully implement this. For a DLL to be explicitly listed here my guess is that there was an issue.

@ohine or @bdukes any idea on how we might track this down?

@ohine
Copy link
Contributor

ohine commented Jun 19, 2018

Maybe @ashishpd might know some history on that function/class and it's purpose in the platform?

private bool CanScan(Assembly assembly)
{
string[] ignoreAssemblies = new string[]
{
"DotNetNuke.Authentication.Facebook",
"DotNetNuke.Authentication.Google",
"DotNetNuke.Authentication.LiveConnect",
"DotNetNuke.Authentication.Twitter",
"DotNetNuke.ASP2MenuNavigationProvider",
"DotNetNuke.DNNDropDownNavigationProvider",
"DotNetNuke.DNNMenuNavigationProvider",
"DotNetNuke.DNNTreeNavigationProvider",
"DotNetNuke.SolpartMenuNavigationProvider",
"DotNetNuke.HttpModules",
"DotNetNuke.Instrumentation",
"DotNetNuke.Log4Net",
"DotNetNuke.Modules.Groups",
"DotNetNuke.Modules.Html",
"DotNetNuke.Modules.HtmlEditorManager",
"DotNetNuke.Modules.MobileManagement",
"DotNetNuke.Modules.PreviewProfileManagement",
"DotNetNuke.Modules.RazorHost",
"DotNetNuke.Modules.Taxonomy",
"DotNetNuke.Modules.UrlManagement",
"DotNetNuke.RadEditorProvider",
"DotNetNuke.Services.Syndication",
"DotNetNuke.Web.Client",
"DotNetNuke.Web.DDRMenu",
"DotNetNuke.Web.Razor",
"DotNetNuke.Web.Mvc",
"DotNetNuke.WebControls",
"DotNetNuke.WebUtility",
};
//First eliminate by "class"
var assemblyName = assembly.FullName.ToLowerInvariant();
bool canScan = !(assemblyName.StartsWith("clientdependency.core") || assemblyName.StartsWith("countrylistbox")
|| assemblyName.StartsWith("icsharpcode") || assemblyName.StartsWith("fiftyone")
|| assemblyName.StartsWith("lucene") || assemblyName.StartsWith("microsoft")
|| assemblyName.StartsWith("newtonsoft") || assemblyName.StartsWith("petapoco")
|| assemblyName.StartsWith("sharpziplib") || assemblyName.StartsWith("system")
|| assemblyName.StartsWith("telerik") || assemblyName.StartsWith("webformsmvp")
|| assemblyName.StartsWith("webmatrix") || assemblyName.StartsWith("solpart")
);
if (canScan)
{
//Next eliminate specific assemblies
if (ignoreAssemblies.Any(ignoreAssembly => assemblyName == ignoreAssembly.ToLowerInvariant()))
{
canScan = false;
}
}
return canScan;
}

Copy link
Contributor

@mitchelsellers mitchelsellers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. @ohine is going to create a secondary PR to fix the identified issue

@mitchelsellers mitchelsellers merged commit eea53e5 into dnnsoftware:development Jun 19, 2018
@ohine ohine modified the milestone: 9.2.1 Jun 20, 2018
@ohine
Copy link
Contributor

ohine commented Jun 21, 2018

Created PR #2126 with the fix to the CanScan function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dependencies to old SharpZipLib don't get resolved properly
5 participants