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

[BUG] Type 'OAProjectItem' is not marked as serializable in VS2022 on files generation #4

Closed
5 of 10 tasks
psulek opened this issue May 24, 2022 · 2 comments
Closed
5 of 10 tasks
Assignees
Labels
bug Something isn't working

Comments

@psulek
Copy link
Owner

psulek commented May 24, 2022

Select category

  • LHQ Editor - Visual Studio Extension
  • ScaleHQ.WPF.LHQ - NuGet Package
  • ScaleHQ.AspNetCore.LHQ - NuGet Package
    (place x inside square brackets to mark category or multiple categories)

Version

2022.1

Visual Studio Edition

  • Visual Studio Community
  • Visual Studio Pro
  • Visual Studio Enterprise
    (place x inside square brackets to mark edition or multiple editions)

Visual Studio Version

  • 2015
  • 2017
  • 2019
  • 2022
    (place x inside square brackets to mark version or multiple versions)

Describe Problem

Generating files in VS2022 throws error:

Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProjectItem' in Assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.'

@psulek psulek added the bug Something isn't working label May 24, 2022
@psulek psulek self-assigned this May 24, 2022
@psulek
Copy link
Owner Author

psulek commented May 24, 2022

Found forum with same error:
http://vfrdtyky.blogspot.com/2019/04/visual-studio-serialization-error-when.html

possible fix:

The EnvDTE assemblies are COM interop assemblies. Your error can be avoided by creating a Runtime Callable Wrapper, which marshals calls to the COM object based off information in the interop-assembly. Microsoft has provided an extension method within the
Microsoft.VisualStudio.TextTemplating namespace:



<#@ template hostspecific="true" language="C#" #>

<#@ assembly name="EnvDTE" #>

<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>

<#

  IServiceProvider serviceProvider = (IServiceProvider)this.Host;

  EnvDTE.DTE dte = (EnvDTE.DTE) serviceProvider.GetCOMService(typeof(EnvDTE.DTE));

 #>



The GetCOMService(this IServiceProvider, Type type) extension method is the correct way to obtain the DTE COM object.



T4 templates run in a separate AppDomain, and I believe that is the reason your code is working despite the exception. IServiceProvider.GetService(typeof(DTE)) returns a transparent Proxy Object. This exception is because the proxy requires objects crossing an app domain be decorated with the Serializable attribute. You can confirm the DTE object in your code is a "transparent proxy" like this:



bool isProxy = RemotingServices.IsTransparentProxy(dte); 

@psulek psulek closed this as completed in dbdcb2b May 25, 2022
@psulek
Copy link
Owner Author

psulek commented May 25, 2022

fixed in Release v2022.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant