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

Could not load file or assembly 'Microsoft.CodeAnalysis' #6512

Open
TehWardy opened this issue Aug 16, 2020 · 28 comments
Open

Could not load file or assembly 'Microsoft.CodeAnalysis' #6512

TehWardy opened this issue Aug 16, 2020 · 28 comments
Assignees

Comments

@TehWardy
Copy link

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.

    public static class Execute
    {
        [FunctionName("Execute")]
        public static async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Execute")]HttpRequestMessage req)
        {
            var json = await req.Content.ReadAsStringAsync();
            var request = (json.Contains("$type")
                ? JsonConvert.DeserializeObject(json, ObjectExtensions.JSONSettings)
                : JsonConvert.DeserializeObject<ScriptRequest<dynamic>>(json)) as ScriptRequest;

            return await new ScriptRunner(Log).Run(request.code, request.Imports, request.args, Log);
        }

        void Log(LogLevel level, string message) => Console.WriteLine(message);
    }

Looking at the logged output from the ctor in the following "ScriptRunner" class I see that it outputs ...

Loaded: Microsoft.CodeAnalysis.CSharp.Scripting, Version=3.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Then I get:

Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

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?

using Core.Objects;
using Core.Objects.Dtos.Workflow;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Workflow
{
    internal class ScriptRunner : IScriptRunner
    {
        internal static Assembly[] references;

        public ScriptRunner(LogEvent log)
        {
            try
            {
                if (references == null)
                {
                    // some of the stack might not have been loaded, lets make sure we load everything so we can give a complete response
                    // first grab what's loaded
                    var loadedAlready = AppDomain.CurrentDomain
                            .GetAssemblies()
                            .Where(a => !a.IsDynamic)
                            .ToList();

                    // then grab the bin directory
                    var thisAssembly = Assembly.GetExecutingAssembly();
                    var binDir = thisAssembly.Location
                        .Replace(thisAssembly.ManifestModule.Name, "");
                    log(WorkflowLogLevel.Debug, $"Bin Directory: {binDir}");

                    // from the bin, grab our core dll files
                    var stackDlls = Directory.GetFiles(binDir)
                        //.Select(i => i.ToLowerInvariant())
                        .Where(f => f.EndsWith("dll"))
                        .ToList();

                    loadedAlready.ForEach(a => log(WorkflowLogLevel.Info, $"Loaded: {a.FullName} "));

                    // load the missing ones
                    var toLoad = stackDlls
                        .Where(assemblyPath => loadedAlready.All(a => a.CodeBase.ToLowerInvariant() != assemblyPath.ToLowerInvariant()))
                        .Where(a => !a.Contains("api-ms-win"))
                        .ToArray();
                    foreach (var assemblyPath in toLoad)
                    {
                        try 
                        {
                            var a = Assembly.LoadFile(assemblyPath);
                            loadedAlready.Add(a);
                            log(WorkflowLogLevel.Info, $"Loaded: {a.FullName} ");
                        } 
                        catch (Exception ex) 
                        {
                            log(WorkflowLogLevel.Warning, $"Unable to load assembly {assemblyPath} because: " + ex.Message); 
                        }
                    }

                    references = loadedAlready.ToArray();
                }
            }
            catch (Exception ex)
            {
                log(WorkflowLogLevel.Warning, "Script Runner may not have everything it needs, continuing anyway despite exception:\n" + ex.Message);
            }
        }

        public async Task<T> BuildScript<T>(string code, string[] imports, Action<WorkflowLogLevel, string> log)
        {
            try
            {
                var referencesNeeded = references.Where(r => r.GetExportedTypes().Any(t => imports.Contains(t.Namespace)));
                var options = ScriptOptions.Default
                    .AddReferences(referencesNeeded)
                    .WithImports(imports);

                if (log != null)
                {
                    var message = $"\nImports\n  {string.Join("\n  ", imports)}\n\nReferences Needed\n  {string.Join("\n  ", referencesNeeded.Select(r => r.FullName))}";
                    log(WorkflowLogLevel.Debug, message);
                }

                return await CSharpScript.EvaluateAsync<T>(code, options);
            }
            catch (Exception ex)
            {
                log(WorkflowLogLevel.Error, "Script failed to compile.");
                log(WorkflowLogLevel.Error, ex.Message);

                if (ex is CompilationErrorException cEx)
                    log(WorkflowLogLevel.Error, $"Source of the problem:\n{cEx.Source}");

                return default;
            }
        }

        public async Task<T> Run<T>(string code, string[] imports, object args, Action<WorkflowLogLevel, string> log)
        {
            try
            {
                var referencesNeeded = references.Where(r => r.GetExportedTypes().Any(t => imports.Contains(t.Namespace)));
                var options = ScriptOptions.Default
                    .AddReferences(referencesNeeded)
                    .WithImports(imports);

                if (log != null)
                {
                    var message = $"\nImports\n  {string.Join("\n  ", imports)}\n\nReferences Needed\n  {string.Join("\n  ", referencesNeeded.Select(r => r.FullName))}";
                    log(WorkflowLogLevel.Debug, message);
                }

                return await CSharpScript.EvaluateAsync<T>(code, options, args, args.GetType());
            }
            catch (NullReferenceException ex)
            {
                var typeAndCall = $"(({ex.TargetSite.DeclaringType.Name})object).{ex.TargetSite.Name}";
                var data = new List<string>();

                foreach (var k in ex.Data.Keys) data.Add($"{k}: {ex.Data[k]}");

                throw new Exception(ex.Message + $"\nContext: {ex.Source}\nTarget: {typeAndCall}\n{string.Join("\n", data)}");
            }
            catch (CompilationErrorException ex)
            {
                throw new Exception($"Compilation failed:\n{ex.Message}\n{string.Join(Environment.NewLine, ex.Diagnostics)}");
            }
        }

        public Task Run(string code, string[] imports, object args, Action<WorkflowLogLevel, string> log)
            => Run<bool>(code + ";return true;", imports, args, log);
    }
}
@jeffhollan jeffhollan transferred this issue from Azure/Azure-Functions Aug 17, 2020
@ghost ghost assigned brettsam Aug 17, 2020
@brettsam
Copy link
Member

@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.

@TehWardy
Copy link
Author

This is an extract from a workflow engine implementation I built.
It's a ton more complex than what's here.
Net result is that anything I try to do with Roslyn inside an azure function just seems to result in this issue.

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.
If you have specific questions about particular libs though by all means ask and I'll give you numbers.
Or if you want to give me a list I can do that too.

@brettsam
Copy link
Member

Are you using Functions v2 or v3? I'm able to repro against v2 -- and if I switch to using <PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.5.0" />, it works. Are you able to use that package?

I suspect there's something going on with our assembly unification code here -- I'll keep investigating.

@TehWardy
Copy link
Author

Raw source for the functions app project file ...

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <LangVersion>latest</LangVersion>
    <ApplicationIcon />
    <OutputType>Library</OutputType>
    <StartupObject />
  </PropertyGroup>
  <ItemGroup>
    <None Remove="host.json" />
    <None Remove="nuget.config" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="host.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="nuget.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\Back End\B2B\Core.B2B.Objects\Core.B2B.Objects.csproj" />
    <ProjectReference Include="..\..\Back End\Framework\Core.Connectivity\Core.Connectivity.csproj" />
    <ProjectReference Include="..\..\Back End\Framework\Core.Objects\Core.Objects.csproj" />
    <ProjectReference Include="..\..\Back End\Framework\Workflow\Workflow.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Properties\PublishProfiles\" />
  </ItemGroup>
</Project>

The ScriptRunner class above is in this project which is referenced as "....\Back End\Framework\Workflow\Workflow.csproj" above ...

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup Label="Globals">
    <SccProjectName>%24/CLX2020/v3/Back End/Framework/Workflow</SccProjectName>
    <SccProvider>{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}</SccProvider>
    <SccAuxPath>https://corporatelinx.visualstudio.com</SccAuxPath>
    <SccLocalPath>.</SccLocalPath>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="nuget.config" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="nuget.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.7.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\B2B\Core.B2B.Objects\Core.B2B.Objects.csproj" />
    <ProjectReference Include="..\Core.Connectivity\Core.Connectivity.csproj" />
    <ProjectReference Include="..\Core.Objects\Core.Objects.csproj" />
  </ItemGroup>
</Project>

Hopefully these lend some key light on the subject.

@TehWardy
Copy link
Author

@jeffhollan Thanks for getting ball rolling on this one, hopefully @brettsam will have it cracked soon.
This has been a thorn in my side for some time.

@jlb399byu
Copy link

jlb399byu commented Aug 18, 2020

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.

@brettsam
Copy link
Member

I think there's two issues here:

  1. Our latest Sdk versions will "clean" your output folder for assemblies that we don't think you need. But it can be too aggressive. We have an issue ([ExtensionsMetadataGenerator] Improve configuration for cleaning build output #5894) to make this more configurable, but for now you can turn it off completely by adding the property <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> to your csproj file. This will leave all assemblies in your bin folder.

  2. Functions run inside of a custom AssemblyLoadContext and when you use AppDomain.Current, you're using the wrong context. If you're doing custom assembly loading, you can get the correct load context with something like:

    var thisAssembly = typeof(FunctionClass).Assembly;
    var loadContext = AssemblyLoadContext.GetLoadContext(thisAssembly);
    

    From there you can load assemblies directly into the correct AssemblyLoadContext. Note that some of the members on AssemblyLoadContext are slightly different than AppDomain, but you should be able to figure it out. Examples: GetAssemblies() -> Assemblies and Assembly.LoadFile() -> loadContext.LoadFromAssemblyPath()

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...

@TehWardy
Copy link
Author

Ah nice one :)
I knew it would be something simple ...
I also pulled some bits in to the project with the function (it was separated on to another project but I figured you would just have the one) and that cracked it!

getting this now ....

Error:: Fetch Source Data:: Script failed to compile.
Error:: Fetch Source Data:: Could not load type 'Microsoft.AspNetCore.Http.Authentication.AuthenticationManager' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.1.7.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Not sure if it's related yet ... still digging through it.
It's been a long day had to rebuild my computer (upgraded the board, cpu, and got one of those fancy pci based raid cards for holding 4 nvme drives ... fast as!!!)

Not quite sure what's using that exactly yet ... didn't think I was using that particular part of the framework for this code.

@brettsam
Copy link
Member

Did you change Assembly.LoadFile() line to loadContext.LoadFromAssemblyPath()? I saw that exception as well until I changed that load call.

@TehWardy
Copy link
Author

Where did you get that from ?
For me it says "Assembly does not contain a definition for LoadFromAssemblyPath"

@brettsam
Copy link
Member

use the loadContext you found above, not Assembly.

@TehWardy
Copy link
Author

hmmm same error ...

public ScriptRunner(LogEvent log)
{
    try
    {
        if (references == null)
        {
            var loadCtx = AssemblyLoadContext.GetLoadContext(typeof(Execute).Assembly);

            // some of the stack might not have been loaded, lets make sure we load everything so we can give a complete response
            // first grab what's loaded
            var loadedAlready = loadCtx.Assemblies
                    .Where(a => !a.IsDynamic)
                    .ToList();

            // then grab the bin directory
            var thisAssembly = typeof(Execute).Assembly;
            var binDir = thisAssembly.Location
                .Replace(thisAssembly.ManifestModule.Name, "");
            log(WorkflowLogLevel.Debug, $"Bin Directory: {binDir}");

            // from the bin, grab our core dll files
            var stackDlls = Directory.GetFiles(binDir)
                //.Select(i => i.ToLowerInvariant())
                .Where(f => f.EndsWith("dll"))
                .ToList();

            loadedAlready.ForEach(a => log(WorkflowLogLevel.Info, $"Loaded: {a.FullName} "));

            // load the missing ones
            var toLoad = stackDlls
                .Where(assemblyPath => loadedAlready.All(a => a.CodeBase.ToLowerInvariant() != assemblyPath.ToLowerInvariant()))
                .Where(a => !a.Contains("api-ms-win"))
                .ToArray();
            foreach (var assemblyPath in toLoad)
            {
                try 
                {
                    var a = loadCtx.LoadFromAssemblyPath(assemblyPath);
                    loadedAlready.Add(a);
                    log(WorkflowLogLevel.Info, $"Loaded: {a.FullName} ");
                } 
                catch (Exception ex) 
                {
                    log(WorkflowLogLevel.Warning, $"Unable to load assembly {assemblyPath} because: " + ex.Message); 
                }
            }

            references = loadedAlready.ToArray();
        }
    }
    catch (Exception ex)
    {
        log(WorkflowLogLevel.Warning, "Script Runner may not have everything it needs, continuing anyway despite exception:\n" + ex.Message);
    }
}

Did I miss something in what you said here?

@brettsam
Copy link
Member

Can you double-check what your loadContext is? It should be of type FunctionAssemblyLoadContext. I just tried again and I get that exact exception when I'm loading the file into the wrong context with Assembly.LoadFile() so it feels like that's still happening for you.

@TehWardy
Copy link
Author

TehWardy commented Aug 18, 2020

image
image

It looks like it's loaded everything though as I might expect.

@brettsam
Copy link
Member

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 AssemblyLoadContext.All; -- do you have 2?

And where does the exception get thrown in your code? When you figure out referencesNeeded in Run<T>?

@TehWardy
Copy link
Author

image

yup 2 :)

@TehWardy
Copy link
Author

TehWardy commented Aug 19, 2020

Yeh that's the spot ...

public async Task<T> BuildScript<T>(string code, string[] imports, Action<WorkflowLogLevel, string> log)
{
    try
    {
         /// this line here
        var referencesNeeded = references.Where(r => r.GetExportedTypes().Any(t => imports.Contains(t.Namespace)));
        var options = ScriptOptions.Default
            .AddReferences(referencesNeeded)
            .WithImports(imports);
       ....

the exact exception is ...

Method 'AuthenticateAsync' in type 'Microsoft.AspNetCore.Http.Authentication.Internal.DefaultAuthenticationManager' from assembly 'Microsoft.AspNetCore.Http, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

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'm not directly referencing that dependency at all, I guess something in the Http Stack is ... I do have Signalr in this so that I can get realtime feedback on the function in my web pages as it runs, maybe that needs it in some form.

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.

@TehWardy
Copy link
Author

Ok this seems to be the line causing that exception not the one above it ...

var options = ScriptOptions.Default
        .AddReferences(referencesNeeded)
        .WithImports(imports);

@brettsam
Copy link
Member

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?

@TehWardy
Copy link
Author

Yeh the logging stuff is Signalr based callbacks to the UI.
I think I have something I can send you, i've been pulling out the relevant bits for a while.

@TehWardy
Copy link
Author

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 ...

{
  "$type": "Core.Objects.Dtos.Workflow.WorkflowRequest`1[[System.Object, System.Private.CoreLib]], Core.Objects",
  "Api": "https://dev.corporatelinx.com/Api/",
  "FlowId": "9b5364cd-baa4-486d-65c8-08d81120879c",
  "InstanceId": "a01d46f4-8911-462c-9d5a-2aeab39e7841",
  "AuthToken": "68ff785ec1c541d6bd90ebb3d966a3dc955843d01fd4410c9fcb38aa73fd4b07"
}

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.
Stick a breakpoint in Engine/ScriptRunner around line 94

@brettsam
Copy link
Member

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).

@TehWardy
Copy link
Author

TehWardy commented Aug 21, 2020

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 ...

  • Functions not doing what I expect with roslyn calls
  • some usages on my part of roslyn arn't completely right (this mornings issue)
  • wrapping calls don't always log exactly what's being compiled and run (user friendliness reasons)

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).
Just thought i'd mention that in case it caused any confusion.

@TehWardy
Copy link
Author

TehWardy commented Aug 21, 2020

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 ...

public async Task<T> BuildScript<T>(string code, string[] imports, Action<WorkflowLogLevel, string> log)
{
    try
    {
        var referencesNeeded = references.Where(r => r.GetExportedTypes().Any(t => imports.Contains(t.Namespace)));
        var options = ScriptOptions.Default
            .AddReferences(referencesNeeded)
            .WithImports(imports);

Changed to ...

public async Task<T> BuildScript<T>(string code, string[] imports, Action<WorkflowLogLevel, string> log)
{
    try
    {
        var referencesNeeded = references.Where(r => 
        {
            try
            {
                return r.GetExportedTypes().Any(t => imports.Contains(t.Namespace));
            }
            catch { return false; }
        });
        var options = ScriptOptions.Default
            .AddReferences(referencesNeeded)
            .WithImports(imports);

... so the exception i silently throw away there is still happening but at least I know exactly where it is.
It appears to be some usage of or looping through the results from GetExportedTypes() that causes the problem.

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 ...
I swallow the problem and the rest of the code seems to run fine.
I guess it's somewhat of a hack though and still an issue that an exception is thrown at all but at least I can work around it.

@brettsam
Copy link
Member

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?

@brettsam
Copy link
Member

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:

  1. Skip loading anything with AspNetCore in the assembly name? Not sure if you ever need these -- but even skipping loading the SignalR ones may help.
  2. Add an ASP.NET Core framework reference, which will update all of your references to 3.1 versions rather than the 2.1 that they're transitively pulling in now from the Functions SDK: <FrameworkReference Include="Microsoft.AspNetCore.App" />

For some reason it seems that the build calculates Microsoft.AspNetCore.Http.dll should be 2.1, but it seems that something in SignalR depends on types in the 3.1 version. Since this is such a rare scenario I likely won't investigate too deeply unless it becomes a bigger problem.

Let me know if either of those help your scenario!

@TehWardy
Copy link
Author

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.
Other than asking all the types "what namespace are you in" I wasn't sure how to achieve this, this is the sort of feedback that comes from the community too ...
https://stackoverflow.com/questions/1549198/finding-all-namespaces-in-an-assembly-using-reflection-dotnet

Since i'm ignoring all the dynamic assemblies this should work (according to the docs at least) ...
https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getexportedtypes?view=netcore-3.1

... oddly it does in a simple console app, but as soon as we add in the Functions framework it doesn't.

This ...

For some reason it seems that the build calculates Microsoft.AspNetCore.Http.dll should be 2.1, but it seems that something in SignalR depends on types in the 3.1 version. Since this is such a rare scenario I likely won't investigate too deeply unless it becomes a bigger problem.

... Is a common issue I have hit lately, I don't understand Microsofts resolution / referencing practices.
I assumed that if I depend on the latest version of everything then it's dependencies should also be the latest, but it seems that under the bonnet, multiple things that depend on the same assembly require different versions.

Is there way to force consistency without having to crawl the tree and find everything manually then reference it?

@DadvDadv
Copy link

DadvDadv commented Apr 9, 2021

Hi,
I have the same error with trying using report services sdk. If i look on the bin\Debug\netcoreapp3.1\bin it's missing the Microsoft.CodeAnalysis.dll

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?

FunctionApp1.zip

@v-anvari v-anvari added this to the Triaged milestone Sep 13, 2021
@fabiocav fabiocav removed this from the Triaged milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants