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

Unhandled exception. System.Reflection.CustomAttributeFormatException: 'AllowMultiple' property specified was not found. #113009

Open
AlexKuai opened this issue Feb 28, 2025 · 7 comments
Assignees
Labels
area-System.Reflection needs-author-action An issue or pull request that requires more info or actions from the author. needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration

Comments

@AlexKuai
Copy link

AlexKuai commented Feb 28, 2025

Description

My operating environment is the virtual machine Anolis OS 8.9 (Linux x64), Basic image using aspnet: 9.0. I cross compile an arm64 architecture image using Docker Buildx and start container testing using the following command.

docker run -d -p 8080:8080 -e ASPNETCORE_URLS= http://0.0.0.0:8080 -v /home/zytek/publish/appsettings.json:/ home/zytek/app/appsettings.json -v /home/zytek/publish/Logs:/home/zytek/app/Logs -v /home/zytek/publish/config.json:/home/zytek/app/wwwroot/app/config.json -v /etc/localtime:/etc/localtime:ro --name=data-analytics-platform --platform=linux/arm64 mirrors.ziyitek.cn/library/data-analytics-platform:latest-arm64

The following is a detailed stack:
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at InvokeStub_AttributeUsageAttribute.set_AllowMultiple(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr) --- End of inner exception stack trace --- at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr)
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder1 derivedAttributes)
--- End of inner exception stack trace ---
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder1 derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.Attribute.InternalGetAttributeUsage(Type type)
at System.Attribute.InternalParamGetCustomAttributes(ParameterInfo param, Type type, Boolean inherit)
at Microsoft.AspNetCore.Mvc.ModelBinding.ModelAttributes.GetAttributesForParameter(ParameterInfo parameterInfo, Type modelType)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreateParameterDetails(ModelMetadataIdentity key)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreateCacheEntry(ModelMetadataIdentity key)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.GetMetadataForParameter(ParameterInfo parameter, Type modelType)
at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.CreateParameterModel(ParameterInfo parameterInfo)
at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory.CreateApplicationModel(IEnumerable1 controllerTypes) at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors() at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context) at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection() at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize() at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.GetChangeToken() at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration1..ctor(Func1 changeTokenProducer, Action1 changeTokenConsumer, TState state)
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers(IEndpointRouteBuilder endpoints)
at ZyTek.Framework.API.ApiRegister.UseFramework(WebApplication app) in /home/zytek/src/ZyTek.Framework.API/ApiRegister.cs:line 125
at ZyTek.DataAnalyticsPlatform.WebAPI.Host.Program.Main(String[] args) in /home/zytek/src/ZyTek.DataAnalyticsPlatform.WebAPI.Host/Program.cs:line 1

The Docker information of the host machine is as follows:
[zytek@anolis ~]$ docker info
Client:
Version: 27.4.1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.20.0
Path: /home/zytek/.docker/cli-plugins/docker-buildx

Server:
Containers: 2
Running: 2
Paused: 0
Stopped: 0
Images: 6
Server Version: 27.4.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: false
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 88bf19b2105c8b17560993bee28a01ddc2f97182
runc version: v1.2.3-0-g0d37cfd
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 5.10.134-16.2.an8.x86_64
Operating System: Anolis OS 8.9
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.609GiB
Name: anolis.slave01
ID: 5fb6542b-df47-4eac-8c71-0b06ddc7aa2c
Docker Root Dir: /data/docker_storage
Debug Mode: false
Experimental: false
Insecure Registries:
mirrors.ziyitek.cn
127.0.0.0/8
Registry Mirrors:
https://docker.1ms.run/
https://docker.xuanyuan.me/
Live Restore Enabled: true
Product License: Community Engine

Execute commands inside the container:
zytek@ac0380e33582:~/app$ dotnet --info

Host:
Version: 9.0.2
Architecture: arm64
Commit: 80aa709
RID: linux-arm64

.NET SDKs installed:
No SDKs were found.

.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Reproduction Steps

app.UseStaticFiles();

app.UseCors();
app.UseMiddleware<IpWhitelistMiddleware>();
app.UseMiddleware<ExceptionHandlingMiddleware>();

if (!app.Environment.IsDevelopment())
{
    app.UseHttpsRedirection();
    app.UseHsts();
}

app.UseAuthentication();
app.UseAuthorization();

app.UseResponseCompression();

app.MapHub<NotificationHub>("/notificationHub");
app.UseMiddleware<PerformanceLogMiddleware>();
app.MapControllers();
app.UseSwaggerApiDoc();

Expected behavior

execute normally

Actual behavior

execute normally

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 28, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 28, 2025
@huoyaoyuan
Copy link
Member

Do you use any trimming method? What is the configuration?

@ericstj ericstj removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 5, 2025
@ericstj
Copy link
Member

ericstj commented Mar 5, 2025

Agree with @huoyaoyuan that this could be caused by trimming. Could you let us know if this is used? Also is it 100% repro or only sometimes?

Also CC @steveharter in case it looks like a problem with reflection invoke.

@ericstj ericstj added the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 5, 2025
@AlexKuai
Copy link
Author

AlexKuai commented Mar 6, 2025

Do you use any trimming method? What is the configuration?

I checked all csproj files in the project and did not use any PublishTrimmed configuration

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 6, 2025
@AlexKuai
Copy link
Author

AlexKuai commented Mar 6, 2025

Agree with @huoyaoyuan that this could be caused by trimming. Could you let us know if this is used? Also is it 100% repro or only sometimes?

Also CC @steveharter in case it looks like a problem with reflection invoke.

I checked all csproj files in the project and did not use any PublishTrimmed configuration.

In the environment I described, this error is 100% likely to recur.

@huoyaoyuan
Copy link
Member

Can you share a simplified repro project for the issue?

Is your deployed assembly file broken? You can inspect with tools like ILSpy and check if anything is broken.

@steveharter
Copy link
Member

This looks similar to #108919 where type metadata seems to get corrupted when stopping the application. This is also an AspNetCore case.

@AlexKuai could this be happening when the app is closing, or with a debugger attached?

@steveharter steveharter added needs-author-action An issue or pull request that requires more info or actions from the author. needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed untriaged New issue has not been triaged by the area owner labels Mar 7, 2025
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Reflection needs-author-action An issue or pull request that requires more info or actions from the author. needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

5 participants