"Could not load type" Error
See original GitHub issueI’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 .dll
s 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:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
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
And you’ll be good 👍
Thanks again for your help @jburzynski !
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!