xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
486 stars 172 forks source link

Issue while upgrading to .net8 #574

Open Ruchitha9177 opened 3 weeks ago

Ruchitha9177 commented 3 weeks ago

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.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?

andyward commented 3 weeks ago

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 commented 3 weeks ago

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

Ruchitha9177 commented 3 weeks ago

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

andyward commented 3 weeks ago

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)

Ruchitha9177 commented 3 weeks ago

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.

net8.0 enable enable true True true

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 commented 3 weeks ago

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

andyward commented 3 weeks ago

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.

Ruchitha9177 commented 3 weeks ago

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?

andyward commented 3 weeks ago

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)

Ruchitha9177 commented 2 weeks ago

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.

andyward commented 2 weeks ago

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 commented 1 week ago

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

Ruchitha9177 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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..

andyward commented 1 week ago

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.

Ruchitha9177 commented 1 week ago

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?

andyward commented 1 week ago

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