Could not load file or assembly office, Version=15.0.0.0 in .Net 8

Resolution for exception 'can Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' in .Net 8.
In today's article I will show you how you can overcome with error or exception 'can  Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified. in .NET core 8. This exception occurs when you try to perform any operation on excel or word document in .Net Core 8 or .Net Core 9 and you have added NuGet package Microsoft.Office.Interop.Excel in case of excel.

So, for this if you have installed Microsoft.Office.Interop.Excel nuget package. First you need to uninstall it from you package section. To resolve the issue, we need to install Com Component Interop.Microsoft.Office.Interop.Excel. to install follow the step. Right click on Dependencies folder and select "Add COM Reference" as shown below.

Add Com Ref

Ones we click on Add COM Reference below mention window will open. 

Reference Manager

Now in this window search for "Excel". In search result you will get com library reference.  Refer the below screenshot in this you need to select "Microsoft Excel 16.0 Object Library". You can select version as per you project requirement.

Excel Ref

Ones we have done with selection we will get Com Reference in your solution explorer. 

Com Ref folder

Now we have done your code will work and you will not get exception "can  Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. Now at the end we need to check the project file. You will get below mention reference in your Project file.
   <ItemGroup>
    <COMReference Include="Microsoft.Office.Interop.Excel">
      <WrapperTool>tlbimp</WrapperTool>
      <VersionMinor>9</VersionMinor>
      <VersionMajor>1</VersionMajor>
      <Guid>00020813-0000-0000-c000-000000000046</Guid>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>true</EmbedInteropTypes>
    </COMReference>
  </ItemGroup> 
Happy coding...... 😊

Post a Comment