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

Open
opened 2026-01-29 22:12:28 +00:00 by claunia · 14 comments
Owner

Originally created by @RepeatSoftware on GitHub (Jun 8, 2021).

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

Originally created by @RepeatSoftware on GitHub (Jun 8, 2021). 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 { /// <summary> /// SharpCompress will keep the supplied streams open. Default is true. /// </summary> 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
Author
Owner

@adamhathcock commented on GitHub (Jun 9, 2021):

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 commented on GitHub (Jun 9, 2021): 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.
Author
Owner

@RepeatSoftware commented on GitHub (Jun 9, 2021):

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 commented on GitHub (Jun 9, 2021): 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 GitHub<https://github.com/adamhathcock/sharpcompress/issues/604#issuecomment-857515352>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AJFDS6NM2TT5A6KPPRRCPJLTR4T5RANCNFSM46JSBTIQ>.
Author
Owner

@adamhathcock commented on GitHub (Jun 14, 2021):

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 commented on GitHub (Jun 14, 2021): 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.
Author
Owner

@RepeatSoftware commented on GitHub (Jun 14, 2021):

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 commented on GitHub (Jun 14, 2021): 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 GitHub<https://github.com/adamhathcock/sharpcompress/issues/604#issuecomment-860634009>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AJFDS6NENFQ2RP3JKRNJFHLTSXWTBANCNFSM46JSBTIQ>.
Author
Owner

@adamhathcock commented on GitHub (Jun 15, 2021):

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

@adamhathcock commented on GitHub (Jun 15, 2021): Looks like the official MongoDB driver uses 0.23.0 and will likely stay there until they drop some kind of legacy support.
Author
Owner

@barkermn01 commented on GitHub (Jul 25, 2021):

There is another refference to .Net 5 to this as well in Dec 2019 specifically 80b0671844 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 commented on GitHub (Jul 25, 2021): 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
Author
Owner

@YoshiRulz commented on GitHub (Sep 30, 2021):

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 commented on GitHub (Sep 30, 2021): 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](https://gitlab.com/TASVideos/BizHawk/-/jobs/1637175891) to override the transient dep but ended up downgrading SharpCompress to `0.26.0`.
Author
Owner

@adamhathcock commented on GitHub (Oct 1, 2021):

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

@adamhathcock commented on GitHub (Oct 1, 2021): Looks like this might be cleared up as the `net461` target will be put back here: https://github.com/adamhathcock/sharpcompress/pull/621
Author
Owner

@adamhathcock commented on GitHub (Oct 2, 2021):

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

@adamhathcock commented on GitHub (Oct 2, 2021): net461 back here https://www.nuget.org/packages/SharpCompress/0.30.0
Author
Owner

@RepeatSoftware commented on GitHub (Oct 2, 2021):

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 commented on GitHub (Oct 2, 2021): 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.
Author
Owner

@YoshiRulz commented on GitHub (Oct 3, 2021):

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 commented on GitHub (Oct 3, 2021): 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?
Author
Owner

@adamhathcock commented on GitHub (Oct 3, 2021):

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

I remember reading sometimes the incorrect target being used.

@adamhathcock commented on GitHub (Oct 3, 2021): If you're using net48 it should be using net461. I remember reading sometimes the incorrect target being used.
Author
Owner

@YoshiRulz commented on GitHub (Jan 25, 2022):

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 commented on GitHub (Jan 25, 2022): 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.
Author
Owner

@SplitGemini commented on GitHub (May 9, 2023):

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

@SplitGemini commented on GitHub (May 9, 2023): .net 4.8 can't load 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#464