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 System.CodeDom #186

Closed
swASO opened this issue Oct 31, 2018 · 8 comments · Fixed by #322
Closed

Could not load file or assembly System.CodeDom #186

swASO opened this issue Oct 31, 2018 · 8 comments · Fixed by #322
Assignees
Labels
area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)

Comments

@swASO
Copy link

swASO commented Oct 31, 2018

Describe the bug
I Updated from 0.3.1-beta to 0.5-beta and we got a exception in all our services ( linux/windows )

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.CodeDom, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.CodeDom, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at flowfact.services.attributes.ServiceRegister.<>c__DisplayClass3_0.<FindTypesByAttribute>b__1(Assembly s)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator2.ToList()
   at flowfact.services.attributes.ServiceRegister.FindTypesByAttribute(Type[] types)
System.IO.FileNotFoundException: Could not load file or assembly 'System.CodeDom, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.CodeDom, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'System.CodeDom, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

File name: 'System.CodeDom, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

Runtime environment (please complete the following information):

  • Instrumentation mode: manual
  • Tracer version: 0.5.0-beta
  • OS: Linux / Docker image ( microsoft/dotnet:2.1-runtime-deps-stretch-slim )
  • CLR: .Net Core 2.1

Additional context
i dont know what the exact problem is, but i think this lines below does produce the error
with 0.3.1-beta everythings works fine ( already did the downgrade ), with 0.5-beta i can reproduce the exception above

private static List<(Type Type, object[] CustomAttributes)> FindTypesByAttribute(params Type[] types)
{
    try
    {
        var allTypes = AppDomain.CurrentDomain.GetAssemblies()
            .Where(s => !s.FullName.StartsWith("Microsoft") && !s.FullName.StartsWith("System."))
            .Select(s => s.GetTypes()
                .Select(type => (Type: type, CustomAttributes: type.GetCustomAttributes(true)))
                .Where(z => z.CustomAttributes.Length > 0 && z.CustomAttributes.Any(t => types.Any(i => i == t.GetType())))
            );

        return allTypes.SelectMany(s => s).ToList();
    }
    catch (Exception ex)
    {
        Logger.Error(ex);
    }
    return null;
}
@lucaspimentel
Copy link
Member

Thanks for reporting this, @swASO. To narrow down the issue to a specific release, can you test with release 0.4.1? That was the last release before 0.5.0.

@swASO
Copy link
Author

swASO commented Oct 31, 2018

v0.5.0 -> 👎
v0.4.1 -> 👎
v0.4.0 -> 👎
v0.3.2 -> 👍
v0.3.1 -> 👍

@lucaspimentel
Copy link
Member

@swASO: Thanks for the code sample. We were able to reproduce the issue.

@lucaspimentel lucaspimentel added type:bug area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) and removed status:needs-investigation labels Nov 1, 2018
@lucaspimentel
Copy link
Member

It looks like the error is caused by a MsgPack.Cli dependency. In v0.4.0, we updated the MsgPack.Cli NuGet reference from 0.9.2 to 1.0.0 (see #158). MsgPack.Cli has a reference to System.CodeDom 4.4.0 which is not included in the nuspec file, so it doesn't show up in their NuGet package.

This issue in their repo seems to be related.

In the short term, you can avoid the exception by skipping the MsgPack assembly in the LINQ query:

var allTypes = AppDomain.CurrentDomain
                        .GetAssemblies()
                        .Where(s => !s.FullName.StartsWith("Microsoft") &&
                                    !s.FullName.StartsWith("System.") &&
                                    !s.FullName.StartsWith("MsgPack"))   // skip MsgPack
                        .Select(s => s.GetTypes()

@lucaspimentel
Copy link
Member

lucaspimentel commented Nov 1, 2018

You can repro the issue with minimal code and no reference to Datadog assemblies:

string assemblyString = "MsgPack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2625990d5dc0167";
Type[] types = Assembly.Load(assemblyString).GetTypes();

@lucaspimentel
Copy link
Member

I created this PR so it can be fixed in the next release of their library.

@swASO
Copy link
Author

swASO commented Nov 2, 2018

workaround works! thanks

@lucaspimentel
Copy link
Member

I'm closing this since there is nothing else for us to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants