sharpcompress icon indicating copy to clipboard operation
sharpcompress copied to clipboard

VB.NET in VS2017 - Referencing .NET 5.0 in the Framework 2.1 DLL

Open RepeatSoftware opened this issue 3 years ago • 14 comments

Using with VB.NET and tried using:

sharpcompress-master\src\SharpCompress\bin\Debug\netstandard2.0

sharpcompress-master\src\SharpCompress\bin\Debug\netstandard2.1

Code:

    Dim ws_FileName As String = "D:\Comics\Comic1.cbr"

    If DoesFileExist(ws_FileName) Then
    Else
        MsgBox("Cannot find file: " & ws_FileName)
        Exit Sub
    End If

    Dim ws_UnzipFolder As String = GetFolderNameFromCompletePath(ws_FileName)

    Dim archive As SharpCompress.Archives.IArchive = SharpCompress.Archives.ArchiveFactory.Open(ws_FileName, Nothing)

    For Each Entry As IArchiveEntry In archive.Entries
        If Not Entry.IsDirectory Then
            Console.WriteLine(Entry.Key)
            Entry.WriteToDirectory(ws_UnzipFolder, New ExtractionOptions With
                                  {.ExtractFullPath = True, .Overwrite = True})
        End If
    Next

At the "Dim archive " line, I get:

Import of type 'Stream' from assembly or module 'System.Runtime.dll' failed.

and I run the file, I get:

namespace SharpCompress.Common { public class OptionsBase { ///

/// SharpCompress will keep the supplied streams open. Default is true. /// public bool LeaveStreamOpen { get; set; } = true;

    public ArchiveEncoding ArchiveEncoding { get; set; } = new ArchiveEncoding();
}

} System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'SharpCompress.Common.ArchiveEncoding' threw an exception.

Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Any ideas please?

Many thanks

Mark

RepeatSoftware avatar Jun 08 '21 09:06 RepeatSoftware

This all depends on what legacy framework you have installed and what netstandard version that it supports.

I'm not supporting legacy framework use cases as it's painful. Best I can do is help fix any bugs that happen in netstandard2.0 use cases.

adamhathcock avatar Jun 09 '21 08:06 adamhathcock

Hi Adam

Thanks for coming back to me.

I have all my stuff running on Framework 4.6.1 at the moment. Looks like I would have to update to Framework 5.0 if I want to use your stuff unless there is any quick way I can get it working on this framework?

Thanks

Mark.

From: Adam Hathcock @.> Sent: 09 June 2021 09:55 To: adamhathcock/sharpcompress @.> Cc: Mark Adams @.>; Author @.> Subject: Re: [adamhathcock/sharpcompress] VB.NET in VS2017 - Referencing .NET 5.0 in the Framework 2.1 DLL (#604)

This all depends on what legacy framework you have installed and what netstandard version that it supports.

I'm not supporting legacy framework use cases as it's painful. Best I can do is help fix any bugs that happen in netstandard2.0 use cases.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/adamhathcock/sharpcompress/issues/604#issuecomment-857515352, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJFDS6NM2TT5A6KPPRRCPJLTR4T5RANCNFSM46JSBTIQ.

RepeatSoftware avatar Jun 09 '21 09:06 RepeatSoftware

I think 4.7.2 is what is officially supported....I've long forgotten.

I understand there are a lot of people still on legacy frameworks and will continue to be for a long time. However, I can't continue to support this so I've moved SharpCompress on to NetStandard 2.0 (1.x isn't supported anymore) but that may break soon as well with the new Span/Memory work and async/await branches.

I'm not sure what to tell you to do as I generally see the Open Source community not wanting to support legacy frameworks unless they themselves are using them.

adamhathcock avatar Jun 14 '21 12:06 adamhathcock

Hi Adam

OK. Thanks your help. I couldn’t get the Framework 2.0 working so will try an older version when I get chance,

Regards

Mark.

From: Adam Hathcock @.> Sent: 14 June 2021 13:10 To: adamhathcock/sharpcompress @.> Cc: Mark Adams @.>; Author @.> Subject: Re: [adamhathcock/sharpcompress] VB.NET in VS2017 - Referencing .NET 5.0 in the Framework 2.1 DLL (#604)

I think 4.7.2 is what is officially supported....I've long forgotten.

I understand there are a lot of people still on legacy frameworks and will continue to be for a long time. However, I can't continue to support this so I've moved SharpCompress on to NetStandard 2.0 (1.x isn't supported anymore) but that may break soon as well with the new Span/Memory work and async/await branches.

I'm not sure what to tell you to do as I generally see the Open Source community not wanting to support legacy frameworks unless they themselves are using them.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/adamhathcock/sharpcompress/issues/604#issuecomment-860634009, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJFDS6NENFQ2RP3JKRNJFHLTSXWTBANCNFSM46JSBTIQ.

RepeatSoftware avatar Jun 14 '21 12:06 RepeatSoftware

Looks like the official MongoDB driver uses 0.23.0 and will likely stay there until they drop some kind of legacy support.

adamhathcock avatar Jun 15 '21 07:06 adamhathcock

There is another refference to .Net 5 to this as well in Dec 2019 specifically https://github.com/adamhathcock/sharpcompress/commit/80b06718441560d4f7a3982756fa70236e6dab2e starts using T[].AsSpan() method it is only available in .Net 5 https://docs.microsoft.com/en-us/dotnet/api/system.memoryextensions.asspan?view=net-5.0&viewFallbackFrom=netframework-4.8#System_MemoryExtensions_AsSpan__1___0___System_Index_

Exception Could not find file or assembly 'System.Runtime.CompilerServices.Unsafe', Version=4.0.4.1' triggered from var lzma = new SharpCompress.Compressors.LZMA.LzmaStream(props, new System.IO.MemoryStream(cdata)); because of https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Compressors/LZMA/LzmaStream.cs#L61

barkermn01 avatar Jul 25 '21 00:07 barkermn01

Ah, it's not just me then. BizHawk was also affected by this System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. (this is from our Standard 2.0 library uesd by our Framework 4.8 app). Strangely, it didn't seem to affect local builds on Windows or Linux, only those made in GitLab CI. I tried unsuccessfully to override the transient dep but ended up downgrading SharpCompress to 0.26.0.

YoshiRulz avatar Sep 30 '21 21:09 YoshiRulz

Looks like this might be cleared up as the net461 target will be put back here: https://github.com/adamhathcock/sharpcompress/pull/621

adamhathcock avatar Oct 01 '21 14:10 adamhathcock

net461 back here https://www.nuget.org/packages/SharpCompress/0.30.0

adamhathcock avatar Oct 02 '21 14:10 adamhathcock

Just installed up. Up and fully working on .NET 4.7.2. Thanks a lot for that. Means I can go back to a project I've put on hold. Cheers.

RepeatSoftware avatar Oct 02 '21 19:10 RepeatSoftware

Unfortunately 0.30.0 doesn't fix our problem, the same exception is thrown, again only by CI builds. Shall I open a new issue?

YoshiRulz avatar Oct 02 '21 23:10 YoshiRulz

If you're using net48 it should be using net461.

I remember reading sometimes the incorrect target being used.

adamhathcock avatar Oct 03 '21 05:10 adamhathcock

Figured it out. When I forced System.Runtime.CompilerServices.Unsafe = 4.5.3 it didn't work because that's outside the lower bound >= 5.0.0 inherited via SharpCompress. By simply forcing it up to 5.0.0, all the version constraints are satisfied and our app runs normally.

YoshiRulz avatar Jan 25 '22 07:01 YoshiRulz

.net 4.8 can't load 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

SplitGemini avatar May 09 '23 14:05 SplitGemini