XbimEssentials icon indicating copy to clipboard operation
XbimEssentials copied to clipboard

Issue while upgrading to .net8

Open Ruchitha9177 opened this issue 1 year ago • 18 comments

I've tried attempting my project to .NET8 using Xbim.Essentials 6.0.445.

I'm facing issue while opening the file using IFCStore.open();

        string ifcFilePath = @"C:\Users\rkondrol\Downloads\ifc\sample.ifc";
        using (FileStream fileStream = new FileStream(ifcFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            var schemaVersion = GetSchemaVersion(fileStream);
            IfcStore store = IfcStore.Open(fileStream, StorageType.Ifc, schemaVersion, XbimModelType.MemoryModel);
         }

GetSchemaVersion is to just check if its supported format or not like IFC2*3, IFC4 and its showing proper value. Here store value is coming as null. Exception is coming as below...

System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.ServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'. at Xbim.Common.Configuration.XbimServices.<Rebuild>b__18_0() at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy`1.CreateValue() at Xbim.Common.Configuration.XbimServices.get_ServiceProvider() at Xbim.Ifc.IfcStore..ctor() at Xbim.Ifc.IfcStore.Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimEditorCredentials editorDetails, XbimDBAccess accessMode, ReportProgressDelegate progDelegate, Int32 codePageOverride)

image

In output window Microsoft.Extensions.Logging.Abstractions.dll'. Cannot find or open the PDB file. Exception thrown: 'System.MissingMethodException' in System.Private.CoreLib.dl

Any help on this? Is there anything that i'm missing?

Ruchitha9177 avatar Aug 20 '24 13:08 Ruchitha9177

Can you share your csproj? Or at least the package references so we can see what versions of xbim you're picking up (include all dependencies)

It's looking like a clash of Microsoft.Extensions.Logging versions where there may have been breaking changes.

andyward avatar Aug 20 '24 15:08 andyward

I've just tried it with xbim Essentials 6.0.445 (latest from Nuget) and 6.0.475-develop from Myget-develop

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xbim.Essentials" Version="6.0.445" />
  </ItemGroup>

</Project>

... and was able to open the IfcStore correctly (in net8) using exactly the same code.

My guess is you have an incompatible version of M.E.Logging included (perhaps transitively via another package).

Hint: Check what's loaded in Visual Studio using Debug->Windows->Modules

andyward avatar Aug 20 '24 15:08 andyward

Thanks for your response, Yeah, I just tried with console application and there it is working fine. But when loading my whole solution then I'm facing this issue. I could see M.E.Logging version 8.0.0 and 8.0.1 in some other project of same solution. Will that be the issue for this exception? If we resolve this conflict, then do you think this issue will be resolved? or is this exception is because of some other issue? Below are snaps for reference.

image image

Ruchitha9177 avatar Aug 20 '24 15:08 Ruchitha9177

Can you supply the actual csproj or at least the PackageReferences section? (in text form - not a screenshot)

The difference between 8.0.0 and 8.0.1 should not be an issue - MS won't be making breaking changes in patch versions. More likely to be an old 2.0, 1.1 ME.Logging sneaking in somewhere in another 3rd party library. Are you referencing any Revit API assemblies? (Have seen this cause the same issue)

andyward avatar Aug 20 '24 16:08 andyward

We use central package system, so we don't provide version in csproj instead we do we do in other way. But Xbim Essentials I'm using 6.0.445. Below is my project called IFCReader.csproj where I've referring two other projects called Logging, Clipper Helper.

<PropertyGroup>
	<TargetFramework>net8.0</TargetFramework>
	<ImplicitUsings>enable</ImplicitUsings>
	<Nullable>enable</Nullable>
	<EnableDynamicLoading>true</EnableDynamicLoading>
	<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
	<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
	<PackageReference Include="Xbim.Essentials" />
</ItemGroup>

<ItemGroup>
	<ProjectReference Include="..\..\..\..\HxGN.PPM.Interop.Logging\Logging.csproj" />
	<ProjectReference Include="..\..\..\..\..\ClipperHelper\ClipperHelper.csproj" />
</ItemGroup>

In logging project, we use both netcore3.1 and net6 so earlier it worked fine. Now I'm upgrading net6 to net8 and netcore3.1 remains same. Let me know if you need anything else.

Below is Logging.csproj in which we are using NLog.Web.AspNetCore version 5.3.12

net8.0;netcoreapp3.1 true

Ruchitha9177 avatar Aug 20 '24 17:08 Ruchitha9177

image This is image talking about different versions of logging project i.e., netcoreapp3.1 and net8

Ruchitha9177 avatar Aug 20 '24 17:08 Ruchitha9177

Not sure I can really help you without access to some code. The fact netcoreapp3.1 uses an older version seems a red herring- the issue is in net8 right?

Did you see my suggestion:

Hint: Check what's loaded in Visual Studio using Debug->Windows->Modules

i.e you can Check where the Logging assemblies are loading from and their versions, when debugging the net8 app.

andyward avatar Aug 20 '24 22:08 andyward

Could you please let me know what version of system.private.corelib you are loading? I mean which .NET runtime version are you using? Can you quickly check?

I observed one difference. When i referred my actual project from console application it used 8.0.7 version, and I didn't see any issues. But when im debugging from my original project where 8.0.8 runtime is being loaded and issue is coming.

image

Below image using 8.0.8 and I'm seeing exception.

image

Could you please check if you are using which version runtime?

Ruchitha9177 avatar Aug 21 '24 10:08 Ruchitha9177

I have C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.5\System.Private.CoreLib.dll - but I guess I've not updated VS in a while

I also see you're building under Linux / WSL somehow.

If you look in your net8 build folder I suspect you have a stray version of Microsoft.Extension.Logging*.dll somehow - perhaps via the Nlog package. Have you tried adding Microsoft.Extension.Logging 8.0.x as an explicit dependency on your project?

I'm sorry I can't offer much else at this 'arms length' - given this looks like a commercial product perhaps reach out to me by email and we can look at some more formal support to help investigate. (email on my profile)

andyward avatar Aug 21 '24 17:08 andyward

Yeah, correct I'm building project under Linux. Through console application I'm able to do IfcStore.Open without any issues. But from Linux project it is failing somehow.

I have tried adding Microsoft.Extension.Logging 8.0.x as an explicit dependency on my project and no luck.

Ruchitha9177 avatar Aug 23 '24 04:08 Ruchitha9177

If we're to help you're going to need to create some kind of minimal viable reproduction of the issue so we can narrow it down. As it is I think we've shown xbim Essentials is working in .net8 runtime fine. It's something in your environment that's causing this issue (e.g. assuming it works if you re-target net3.1/net6 again?)

Try to rule in / out a Linux issue Try to add all the packages you're using into the console app and see if you can reproduce / identify the package conflicting.

andyward avatar Aug 23 '24 10:08 andyward

@Ruchitha9177 Did you make any resolution on this? Can we close?

andyward avatar Aug 30 '24 13:08 andyward

Hi, no we are still struggling with the issue... But seems like the below two dependencies causing issue which xbim is referring internally Microsoft.Extensions.DependencyInjection 8.0.0 Microsoft.Extensions.DependencyInjection.Abstractions 8.0.1 This difference is somehow causing the conflict is what we are suspecting. Other projects are forcing Microsoft.Extensions.DependencyInjection.Abstractions to 8.0.1. Did you know anything on this?

Ruchitha9177 avatar Aug 30 '24 14:08 Ruchitha9177

Hi, you can close this...By forcefully making Microsoft.Extensions.DependencyInjection.Abstractions 8.0.0 throughout project worked.

Could you please help me to understand why it is not working with 8.0.1? Its working with 8.0.0 but not 8.0.1? With .net6 the same worked but net8 its showing issue with 8.0.1 Thanks!

Ruchitha9177 avatar Aug 30 '24 14:08 Ruchitha9177

Hi,

Could you please help me to understand why Microsoft.Extensions.DependencyInjection.Abstractions is not working with 8.0.1? Its working with 8.0.0 but not 8.0.1? With .net6 the same worked but net8 it shows issue with 8.0.1 which we are unable to understand..

Ruchitha9177 avatar Sep 02 '24 08:09 Ruchitha9177

Could you please help me to understand why Microsoft.Extensions.DependencyInjection.Abstractions is not working with 8.0.1? Its working with 8.0.0 but not 8.0.1? With .net6 the same worked but net8 it shows issue with 8.0.1 which we are unable to understand..

Honest answer: I don't know - hard to say without access to a project with the issue. The original problem you hit looks like a MissingMethodException building the xbim DI service provider - which indicates an incompatible dependency/ breaking change in interface.

Here's a theory: We're using ME.DependencyInjection & Abstractions 8.0.0 internally in xbim.Common (note we multi-target net6 and net8). If you've a third party dependency bringing in a different version ME.DependencyInjection.Abstractions it must be causing issues when resolving some types. But 8.0.1 and 8.0.0 should be compatible so there's something strange going on.

andyward avatar Sep 02 '24 08:09 andyward

Did you or your team get any chance to use or test with "Microsoft.Extensions.DependencyInjection" 8.0.0 "Microsoft.Extensions.Logging.Abstractions" 8.0.1? Could you please check at your end with these versions of 8.0.0 and 8.0.1? Just to see if you are also facing this issue or not?

Ruchitha9177 avatar Sep 02 '24 09:09 Ruchitha9177

No I couldn't reproduce. See https://github.com/andyward/xbim.net8.tests/tree/main/xbim.net8.testproject

If you can get a version of this repo to break please share.

When run I get:

warn: Xbim.Ifc.IfcStore[0]
      Using DI version 8.0.0.0 - File version 8.0.324.11423
info: Xbim.Ifc.IfcStore[0]
      Found 75 products

andyward avatar Sep 02 '24 10:09 andyward

Closing until we get a repro. We're using in net8 fine

andyward avatar Mar 28 '25 10:03 andyward