dotnet / dotnet/winforms

Assembly.GetType Throws Exception When Using ControlDesigner in Netcore using Microsoft SDK

Open
#11,566 7 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
area-VSDesigner
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### Environment

Visual Studio - Version 17.10.1
Edition - Windows 11 Enterprise
Version - 23H2
OS build - 22631.3737

### .NET version

Net8.0, Net7.0, Net6.0

### Did this work in a previous version of Visual Studio and/or previous .NET release?

It works without the [Microsoft.Winforms.Designer.SDK](https://www.nuget.org/packages/Microsoft.WinForms.Designer.SDK). It works properly in netframework.

### Issue description

We are implementing smart tags for .NET Core controls and have installed the [Microsoft.WinForms.Designer.SDK](https://www.nuget.org/packages/Microsoft.WinForms.Designer.SDK). However, when attempting to call the Assembly.GetCallingAssembly() method and subsequently the Assembly.GetType() method, a **System.Reflection.ReflectionTypeLoadException** is thrown.

**Below code causes the exception**
`Assembly callingAsm = Assembly.GetCallingAssembly();`
`Type[] asmTypes = callingAsm.GetTypes();`

**Sample** - [ControlDesigner_Exception.zip](https://github.com/user-attachments/files/15911992/ControlDesigner_Exception.zip)

**Exception Image**
![image](https://github.com/dotnet/winforms/assets/124787498/3320f448-2285-4834-951c-f4fda19e5fd4)

### Steps to reproduce

1.Drag and drop the control CustomButton control from the Toolbox.
2.Run the sample.

Expected behavior: - Need to run without exception.

### Diagnostics

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.