question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Could not load type" Error

See original GitHub issue

I’m attempting to load types from a 4.72 framework project using the dotnet-typegen cli tool.

So, I guess my first question right off the bat is, can I do that? It worked for the first few .dlls I threw at it. And it was preferable to the older legacy package manager console tool, because then I could run it in my npm scripts.

Assuming I can use the dotnet-typegen tool for 4.72 projects, here’s my situation:

First, I had this in my tgconfig.json:

{
    "assemblies": [
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Api.dll",
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Domain.dll",
    ],
    "externalAssemblyPaths": [
        "./RES/bin/net472/RES.dll"
    ],
    "enumStringInitializers": true,
    "outputPath": "./RES.Web/frontend/src/types",
    "singleQuotes": true,
    "propertyNameConverters": [],
    "filenameConverters": [],
    "clearOutputDirectory": true
}

I run dotnet-typegen generate and everything worked great, I got this output:

Generated [x].ts
Generated [y].ts
Generated [z].ts
...yada yada and then...
Files for project "." generated successfully.

Boom, everything was great. But then I actually wanted to add an enum from our core library, so I added a single TSExportEnum attribute and I moved the dll from externalAssemblyPath to my assemblies list, like so:

{
    "assemblies": [
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Api.dll",
        "./Res.Proposals.Api/bin/Local/net472/RES.Proposals.Domain.dll",
        "./RES/bin/net472/RES.dll"
    ],
    "enumStringInitializers": true,
    "outputPath": "./RES.Web/frontend/src/types",
    "singleQuotes": true,
    "propertyNameConverters": [],
    "filenameConverters": [],
    "clearOutputDirectory": true
}

And suddenly we got problems.

Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
Could not resolve assembly: System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 in any of the searched directories: C:\Users\apv\.nuget\packages\; C:\Program Files\dotnet\sdk/NuGetFallbackFolder; C:\Program Files\dotnet\shared
GENERIC ERROR: Could not load type 'System.ServiceModel.ServiceContractAttribute' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType
attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
   at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo element)
   at TypeGen.Core.Extensions.TypeExtensions.HasExportAttribute(Type type, IMetadataReader reader) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Extensions\TypeExtensions.cs:line 26
   at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at TypeGen.Core.Generator.Services.GenerationSpecProvider.GetGenerationSpec(IEnumerable`1 assemblies) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator\Services\GenerationSpecProvider.cs:line 28
   at TypeGen.Core.Generator.Generator.Generate(IEnumerable`1 assemblies) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator\Generator.cs:line 305
   at TypeGen.Cli.Program.Generate(String projectFolder, String configPath) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 137
   at TypeGen.Cli.Program.Main(String[] args) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 70

I don’t know why it’s trying to resolve all of those Version=0.0.0.0 packages, first of all. I searched my solution for them, and I can’t find any such dependency. I even have the following reference in my .csproj

<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />

The biggest problem is the final error, which totally kills the script though. could not load type. That System.ServiceModel.ServiceContract is building just fine, so I don’t know why the typegen script is choking on it 🤷‍♂

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Aaron-Poolcommented, Oct 29, 2019

Nevermind, once I realized that, I was able to figure out the problem myself. For anyone in the future using this, if you’re getting an error about a assembly not being found, make sure it’s not coming from GAC, and, if it is, add

"externalAssemblyPaths": [
    "C:/windows/Microsoft.Net/assembly"
]

And you’ll be good 👍

Thanks again for your help @jburzynski !

0reactions
jburzynskicommented, Oct 29, 2019

No problem, glad I could help with something 😃 I’m happy it got resolved and you managed to find a solution, and thanks for posting it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parser Error Message: Could not load type 'sometype'
means that a type could not be loaded. (In this case, "type" refers to Inventory1.Global ). Types are located in compiled DLLs. So,...
Read more >
[Solved] Parser error: Could not load type
aspx.cs" to CodeFile="TestCert.aspx.cs". This change is required when you change project type from website to webapplication or vice versa.
Read more >
Parser Error Message: Could not load type - Ajay Matharu
This occurs because of the Application DLL not having been formed. asp.net will look in the Global Assembly Cache, and then in the...
Read more >
Parser Error: Could not load type...
This typically means that you do not have a Virtual Directory set up for your application. It can also occur when an application...
Read more >
Why do i get error message 'Could not load type' whenever ...
Your code-behind files for either your .aspx or the global.aspx page have not been complied. Use Visual Studio .NET's 'Build | Build Solution'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found