Search code examples
c#winformsvisual-studio-2022.net-8.0

Issue with converting a C# project from .NET 4.8 to .NET 8.0


I've got a C# project that I started 4 or 5 months ago. I started it on Visual Studio 2022 and the project uses C# and Windows Forms.

I worked on it a little bit and left it. Now I've come back to it. I wanted to continue coding, but I stumbled upon the problem where I see this error:

feature default interface implementation is not available in c# 7.3

I found I've been using an older .NET 4.8 version. I changed the target framework in my .csproj file by adding <TargetFramework>net8.0</TargetFramework> and also <LangVersion>latest</LangVersion>, as well as removing the older TargetFramework.

Then I had a problem with "duplicate compile items", so I added <EnableDefaultCompileItems>false<\EnableDefaultCompileItems> and <EnableDefaultEmbeddedResourceItems>false<\EnableDefaultEmbeddedResourceItems>.

Now, I no longer get that problem, but sadly I have other issues I can't resolve.

Firstly, I get these two messages:

The file does not support code parsing or generation because it is not contained within a project that supports this code

I also have almost 200 errors that all look like this:

The type or namespace does not exist in the namespace (are you missing an assembly reference)

(I've seen this link, but my framework is indeed 8.0).

The type name could not be found in the namespace. This type has been forwarded to assembly... Consider adding a reference to that assembly.

All the problems seem to be related to Forms, since all the errors I've clicked so far point me to a line like this:

private System.Windows.Forms.DataGridViewTextBoxColumn totalSpacesDataGridViewTextBoxColumn;

I assume it has something to do with the 2 messages that are telling me I have a problem with 2 of the forms. I also tried to add references, but that didn't work.

Does anyone know how to fix this?

Realistically, it's not that much of a problem to start the project again, but I don't want to do the forms all over again, since it took some time.

Edit: Since the initial post, I've read and tried things from the comments. After adding <TargetFramework>net8.0-windows</TargetFramework> and <UseWindowsForms>true</UseWindowsForms> I no longer get this problem

The file does not support code parsing or generation because it is not contained within a project that supports this code

I don't get the other issue with Forms, but now I get it on other parts of the code AirportSystemDataSet and AirportSystemDataSetTableAddapter. Example:

The type or namespace namespace AirportSystemDataSet could not be found (are you missing a using directive or an assembly reference?)

Finally, I also get this warning

Failed to create the wrapper assembly for type library "{215d64d2-031c-33c7-96e3-61794cd1ee61}". Type library 'System_Windows_Forms' was exported from a CLR assembly and cannot be re-imported as a CLR assembly.

Edit 2.0(Answer to the questions): I managed to get my project to run.

The issue with the dataset was fixed by commenting out code refering to and deleting all components that were datasets. After that my forms no longer showed errors.

In order to fix the other issue I needed to remove this block of code from the .csproj file:

<COMReference Include="System_Windows_Forms">
    <Guid>{215d64d2-031c-33c7-96e3-61794cd1ee61}</Guid>
    <VersionMajor>2</VersionMajor>
    <VersionMinor>0</VersionMinor>
    <WrapperTool>tlbimp</WrapperTool>
</COMReference>

I also had some errors regarding duplicate assemblies which I also just commented out. I tried to run the project and it worked.


Solution

  • I managed to find an answer to my question from the comments and google searches. Here is explanation on what I did, in case other people have similar problems. First problem:

    The file does not support code parsing or generation because it is not contained within a project that supports this code

    In order to get rid of this error I had to add these tags in order ot upgrade the project properly:

    <TargetFramework>net8.0-windows</TargetFramework> 
    <UseWindowsForms>true</UseWindowsForms>
    

    This also fixed the problem with namespaces that was related to Forms. Second problem, which was similar for the Forms namespace problem, but for dataset objects:

    The type or namespace does not exist in the namespace (are you missing an assembly reference)

    The type name could not be found in the namespace. This type has been forwarded to assembly... Consider adding a reference to that assembly.

    In order to fix this problem I had to remove and comment out any dataset related code. After that if I tried to add anything data related it didn't have the same problems. I assume that the problem was occuring because of changes in the components with the new releases. Then the other issue that was occuring was this:

    Failed to create the wrapper assembly for type library "{215d64d2-031c-33c7-96e3-61794cd1ee61}". Type library 'System_Windows_Forms' was exported from a CLR assembly and cannot be re-imported as a CLR assembly.

    In order to fix this, I had to open the .csproj file and remove this code:

    <COMReference Include="System_Windows_Forms">
        <Guid>{215d64d2-031c-33c7-96e3-61794cd1ee61}</Guid>
        <VersionMajor>2</VersionMajor>
        <VersionMinor>0</VersionMinor>
        <WrapperTool>tlbimp</WrapperTool>
    </COMReference>
    

    I also had some errors regarding duplicate assemblies which I also just commented out. I tried to run the project and it worked.