-
Notifications
You must be signed in to change notification settings - Fork 289
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
Do not use reflection only if it would fail #821
Conversation
Looks safe enough, I don't think anyone really understands how this reflection mess works :/ |
Do not use reflection only if it would fail
That's what I thought. But apparently none of the builds work anymore. Has this been broken before my change, or do we have an amazing test suite that catches subtle reflection load bugs? |
Running
|
Humm, I'll have to have a better look |
@tpetricek, @ovatsus This sounds exactly like the problem there was in another project. The solution might be as simpe as using Appdomain.Applypolicy. More back-and-forth with reasoning and more links to relevat subject matter can be read from here. |
@veikkoeeva This is cool, I didn't know this existed. I'll see if that fixes the issue instead of my ugly hack :-). |
@tpetricek You are welcome. I'd like to take the chance and point out there is some variation in the rules depending on the platform and now that CoreCLR is coming. From the aforementioned link, some of interest could be: |
Use ApplyPolicy with ReflectionOnlyLoad based on name (improve #821)
I guess https://stackoverflow.com/questions/29789850/fsharp-data-issues-with-fsharp-core-on-prod-server was the same issue - right? |
@weismat Debugging would tell for sure. The error message would the same if there were a failure to apply a policy (binding redirect) and factually the right assembly would in the probing path. I'd be inclined to answer: yes. |
@weismat It sounds like the same issue, but I'm a bit puzzled why this would be happening - because you would not typically have/load the |
I am typical just moving the bin/xxx dir content from my dev to my prod machine. |
I was tying to use F# Data on Azure with Suave using a setup similar to the one in the recent Scot Hanselman's blog. The peculiar thing here is that this is just loading
app.fsx
using FAKE/F# Compiler Service and running it from the source code (which I quite like because it is super simple).The problem here is that we are now running the design time component of F# Data on a machine that does not have anything installed and so it was failing to load
FSharp.Core.dll
version 4.3.0.0. I was running this via FAKE which has correct binding redirects and I had 4.3.1.0 in the folder, but it was still failing.The code was failing here (1) after we loaded the
FSharp.Data.dll
assembly usingReflectionOnlyLoad
here (2). Now, the problem is thatReflectionOnlyLoad
ignores binding redirects - and furthermore, (I think that) once it loads the assembly in (2), it does not give us any chance to fix the situation when it fails to get a type from it in (1).So, this PR tests checks if we would be able to run the code in (2) using assembly loaded with the reflection only method - if yes, then it does not change anything. If getting a type would fail later, then it falls back to the
Assembly.Load
approach (which uses binding redirect and worked fine for me).NOTE: I don't really understand how this works, so I'm not sure what consequences the change has. But I hope the check only applies in situations where the current approach will fail, so I hope it is OK!