-
Notifications
You must be signed in to change notification settings - Fork 442
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
Could not load file or assembly 'Microsoft.CodeAnalysis' #6512
Comments
@TehWardy -- could you share your project file? I'm trying to set up a repro and want to make sure I'm using the same packages that you are. |
This is an extract from a workflow engine implementation I built. If it helps we use Microsoft teams so i'd happily do a meeting and show you what i'm dealing with but ripping this out might be a bit of a task given all the moving parts. Assume i'm using the lastest of everything published to nuget ... I updated all our project references just yesterday across the entire solution. |
Are you using Functions v2 or v3? I'm able to repro against v2 -- and if I switch to using I suspect there's something going on with our assembly unification code here -- I'll keep investigating. |
Raw source for the functions app project file ...
The ScriptRunner class above is in this project which is referenced as "....\Back End\Framework\Workflow\Workflow.csproj" above ...
Hopefully these lend some key light on the subject. |
@jeffhollan Thanks for getting ball rolling on this one, hopefully @brettsam will have it cracked soon. |
I'm having this same issue with Microsoft.Xrm.Sdk.dll... I call JsonConvert.DeserializeObject() and I get the missing assembly error. I put in code right in front of this call to get all the appdomain assemblies and see it clearly in the list, same version, same id that is shown in the error. No other duplicate assembly in there. I also instantiate an instance of a class in the assembly right in front of this call and that does not fix it either. This is a new solution I made which uses the package reference version instead. I had no problems with this before in a previous project. I am having this issue with another project that started in just the past few days. All after I upgrade to the latest vs. |
I think there's two issues here:
I did these two things and I was able to get around the assembly loading errors. Give these a try and let us know if it works... |
Ah nice one :) getting this now ....
Not sure if it's related yet ... still digging through it. Not quite sure what's using that exactly yet ... didn't think I was using that particular part of the framework for this code. |
Did you change |
Where did you get that from ? |
use the |
hmmm same error ...
Did I miss something in what you said here? |
Can you double-check what your loadContext is? It should be of type |
Seems like something else is going on so there must be part of the repro that I'm missing. Can you list your LoadContexts with And where does the exception get thrown in your code? When you figure out |
Yeh that's the spot ...
the exact exception is ...
Regardless of weather that's true or not ... i'm a bit confused as to why the code above results in that being thrown. I noticed from a quick look on Nuget the latest version of that assembly is 2.2.2 ... not that I think it would matter as such. |
Ok this seems to be the line causing that exception not the one above it ...
|
Sorry, been pulled into an incident so may be slower to respond today -- any chance you could put a smaller repro project somewhere (even in a gist) that I could grab and run? That would help. My much smaller repro (just with a function calling your ScriptRunner) gets past that point, so there's some gap between what I've got and what you've got. For example, here's my repro that works okay (note I removed your logging b/c I don't have the LogEvent type, but I think that's okay) -- maybe you can try and see if it works for you? |
Yeh the logging stuff is Signalr based callbacks to the UI. |
Ok so I pushed an extraction of the core guts of this code to https://github.com/TehWardy/ScrapHeap Fire it up then call the "Execute" function in the normal way (postman or whatever) with this body ...
The idea behind this is that the back end serves up an array of activities that get linked up with the "problem code" using roslyn based dynamically compiled functions. |
Well, good news is that I'm now able to repro -- I'll need to do some more debugging tomorrow to see what's happening in your case. I wonder if something your workflow execution is doing is causing the load context to change (that could explain why I wasn't able to repro in my sample). |
Hey @brettsam I have been made aware this morning of a bug in some related code i'll just pushing the fixes to our servers then i'll update the above shared repo. I think there's a combination of problems here ...
I've patched the latter two resolving issues in the console version of this this morning but I still think there's something strange that i'm missing about how functions handles AppDomains / Assembly Loading Contexts. Despite these changes the project still behaves the same way, the console app version works (as already mentioned). |
I think there's something in the namespace selection that causes it, somehow triggers type loading in a way that causes a problem for the compiler ...
Changed to ...
... so the exception i silently throw away there is still happening but at least I know exactly where it is. Are there specialised conditions under which that call cannot be made that apply "specifically to Azure functions" as this same code runs through fine without this need to silently swallow this "edge case". If I do this ... |
When you run GetExportedTypes() I believe it force-loads all the public types in that assembly. If something is missing, this is when you'd see it, even if you never intended to use that API at all. I suspect that this is why ignoring it lets things work as you were never using that API anyway. I'm still investigating this to see if I can understand what's happening -- did you happen to update your repro? |
Okay, I now understand what's happening and have a very reduced-down repro. The issue was with the SignalR assemblies. As soon as I added them I was able to repro this by loading assemblies and trying to get all ExportedTypes, it blew up on me. There's a couple nicer workarounds you can take:
For some reason it seems that the build calculates Let me know if either of those help your scenario! |
Yeh I did update my repro, it was a minor fix and didn't affect this problem though. It's loading the types but really I need the namespace lists to compute the references for the script execution args I have to provide to roslyn. Since i'm ignoring all the dynamic assemblies this should work (according to the docs at least) ... ... oddly it does in a simple console app, but as soon as we add in the Functions framework it doesn't. This ...
... Is a common issue I have hit lately, I don't understand Microsofts resolution / referencing practices. Is there way to force consistency without having to crawl the tree and find everything manually then reference it? |
…Azure/azure-functions-host#6512 to be able to properly load Microsoft.CodeAnalysis
Hi, I try a lot of thing to add the dll in this folder but no luck for now. If i had it manualy it works. Couldn't find how to tell the Azure Function to add it on is "special" bin folder. Can someone help please? |
So I built a simple script runner class to take an arbitrary block of C# code and run it by using Roslyns scripting API's.
This functionality works everywhere except in my azure functions app for some reason.
Looking at the logged output from the ctor in the following "ScriptRunner" class I see that it outputs ...
Then I get:
I'm using the latest version from nuget (without ticking the include previews option) of all dependencies.
So given that it can both see it but not see it at the same time and as a console app this runs fine I figure this must a functions runtime issue?
The text was updated successfully, but these errors were encountered: