Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

[Core] Change libs to netstandard #687

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

LORDofDOOM
Copy link

Make it run on Linux, rename unused files to *.cs.bak

@LORDofDOOM
Copy link
Author

Build on VS2017 works fine - It seems VS14 is hardcoded in appveyor - Please change it manually.

@v1r7u v1r7u mentioned this pull request Jan 29, 2018
@aarani
Copy link
Contributor

aarani commented Feb 9, 2018

@sochix Please check CI as it's useful pull request to merge

@aarani
Copy link
Contributor

aarani commented Feb 9, 2018

You must seperate your commits :
I think you did renamed some files that are unused if you sure that these are unused remove them completely and create a commit for it.
and propose your .net core support in another commit ( and another pull request)

Copy link
Contributor

@aarani aarani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Unused Files

@LORDofDOOM
Copy link
Author

Hi,

I've merged and drop unused files -> Merge should be OK - appveyor needs modification from repo owner (still hardlinked to VS14)

@Jarzamendia
Copy link

I recive An item with the same key has already been added. Key: 481674261 when I use this dll's. :(

@LORDofDOOM
Copy link
Author

Hi,

what version you use ? This should be fixed with LORDofDOOM@cc09cb8

@knocte
Copy link
Collaborator

knocte commented Mar 4, 2018

What's the motivation of migrating from 4.5.2 to 4.7? No Linux distributions have support for this .NET version yet.

@LORDofDOOM
Copy link
Author

4.7 support netstandard reference 4.5.2 do not support this- If you use Linux use netcore

@knocte
Copy link
Collaborator

knocte commented Mar 4, 2018

4.7 support netstandard reference 4.5.2 do not support

That's wrong, I use .netStandard libraries all the time that allow both 4.5.x and .netStandard 2.0 usage (examples: NBitcoin and Nethereum).

If you use Linux use netcore

Using .NET Core should be optional for TLSharp, not a requirement. You could improve this PullRequest to add support for .NET Core without the need to remove 4.5.x support.

@siberianguy
Copy link

I'm trying to use this branch from .NET Core and get the following error:

{System.IO.FileNotFoundException: Could not load file or assembly 'Ionic.ZLib, Version=2.0.0.14, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'Ionic.ZLib, Version=2.0.0.14, Culture=neutral, PublicKeyToken=null'
at TLSharp.Core.Network.TcpMessage.Encode()
at TLSharp.Core.Network.TcpTransport.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at TLSharp.Core.Network.MtProtoPlainSender.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at TLSharp.Core.Auth.Authenticator.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TLSharp.Core.TelegramClient.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ReneGoetzSignalBot.DataRecorder.Program.

d__3.MoveNext() in /Users/alexidsa/Code/mb/Bots/ReneGoetzSignalBot/DataRecorder/Program.cs:line 53
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ReneGoetzSignalBot.DataRecorder.Program.(String[] args)

}

Do you guys know which nuget package for DotNetZip (there's like a million of forks) can be used on .NET Core?

@LORDofDOOM
Copy link
Author

That's wrong, I use .netStandard libraries all the time that allow both 4.5.x and .netStandard 2.0 usage (examples: NBitcoin and Nethereum).

Even if this work it's not supported - Here are official specifications - netstandard 2.0 is supported on 4.6.1 and greater - not on 4.5:

https://docs.microsoft.com/en-US/dotnet/standard/net-standard

Using .NET Core should be optional for TLSharp, not a requirement. You could improve this PullRequest to add support for .NET Core without the need to remove 4.5.x support.

IMHO it is optional - Net 4.7 is available on every maintained Windows and if a user don't want to use netcore in Linux or unsupported Windows version (XP) he still can use mono -> It support 4.7:

http://www.mono-project.com/docs/about-mono/compatibility/

Do you guys know which nuget package for DotNetZip (there's like a million of forks) can be used on .NET Core?

This PR should work in netcore/netstandard:

haf/DotNetZip.Semverd#112

@knocte
Copy link
Collaborator

knocte commented Mar 19, 2018

Even if this work it's not supported - Here are official specifications - netstandard 2.0 is supported on 4.6.1 and greater - not on 4.5.

Good point, then please use 4.6.1, not 4.7.1.

he still can use mono -> It support 4.7:

That's only the very alpha versions. The mono versions that are included in Ubuntu LTS (16.04) and Debian 9, don't support 4.7 yet. Please change it to 4.6.1 and we're all happy.

@siberianguy
Copy link

This PR should work in netcore/netstandard:

haf/DotNetZip.Semverd#112

Could you please enlighten me how to reference DotNetZip so this PR doesn't crash? I downloaded the source code from the PR you referenced, opened a NetStandard solution and got Ionic.zip.NetStandard. After referencing that library, TLSharp still gave me an error about not being able to find Ionic.ZLip. I renamed Ionic.zip.NetStandard to Ionic.ZLib - still the same error message.

@LORDofDOOM
Copy link
Author

That's only the very alpha versions. The mono versions that are included in Ubuntu LTS (16.04) and Debian 9, don't support 4.7 yet. Please change it to 4.6.1 and we're all happy.

I've changed full Framework to 4.6.1 :-)

Could you please enlighten me how to reference DotNetZip so this PR doesn't crash? I downloaded the source code from the PR you referenced, opened a NetStandard solution and got Ionic.zip.NetStandard. After referencing that library, TLSharp still gave me an error about not being able to find Ionic.ZLip. I renamed Ionic.zip.NetStandard to Ionic.ZLib - still the same error message.

Do you have any repo where I can check whats wrong ? What you have rename (Namespace or Filename) ? How you reference DotNetZip (dll or project) ?

select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);
Types.Add(481674261, typeof(TLVector<>));
}
catch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exception did you receive here? You should add the exception type, as putting "catch-all" blocks like this is quite dangerous.

Copy link
Author

@LORDofDOOM LORDofDOOM Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometime the error that @Jarzamendia describes top

I recive An item with the same key has already been added. Key: 481674261 when I use this dll's. :(

This happens if the assembly is loaded twice e.g. from any dependency injection. This only happens if 481674261 is already added - A global try/catch is OK here IMHO

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A global catch is never OK (the only exception is in the entry point of your application, for logging and bug-auto-submission purposes). When you're dealing with certain exception of type X, you need to use that type X in the code because the future developers need to know what was happening, what were you trying to fix. Please add the type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add proper method to prevent double adding type

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnit" version="3.9.0" targetFramework="net47" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still pointing to 4.7

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

<add key="ApiHash" value=""/>
<add key="ApiId" value=""/>
<add key="NumberToAuthenticate" value=""/>
<add key="CodeToAuthenticate" value=""/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you change this? please remove this noise

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added from VS2017 because XML syntax is wrong in original file. There is no change here - Only correct spaces to MS defaults

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you can remove this noise from the PullRequest. To not make this kind of mistake in the future, I recommend using a visualizing-tool for committing, for example git gui. This way you know exactly what hunks you're committing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to old file with spaces

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still pointing to 4.7, change it to 4.6.1 please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net47" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still pointing to 4.7

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

<ItemGroup>
<Compile Include="ObjectDeserializer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TLContext.cs" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you removing all these files from this project?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's a new csproj format (VS17) and you don't need to explicitly include files. Everything inside project folder will be included automatically

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool

where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null
select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);

if (!Types.ContainsKey(481674261))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see what you did here, but actually I think the best approach is simply changing the line Types.Add(481674261, typeof(TLVector<>)); to simply Types[481674261] = typeof(TLVector<>);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True -> This is a better method :) Changed

@guylando
Copy link

guylando commented May 12, 2018

@knocte Any news on this? Its essential to add support of netcore to TLSharp

@ilyalatt
Copy link

I created a fork with netstandard and published it via nuget, it works in my project.

@knocte
Copy link
Collaborator

knocte commented Dec 22, 2018

Oops I thought that not all my comments had been addresses, so I was waiting for that. Now I'm not sure anymore if anything here is missing to do... But I've checked again at the diff and I have two more questions: why are some files like InitConnectionRequest.cs being removed? and why the upgrade of nunit from 2.x to 3.x?

@ilyalatt
Copy link

@knocte As you can see here, 'Requests' directory is legacy, so it was removed. Also I removed TLSharp.Tests.VS and inlined TLSharp.Tests.NUnit into TLSharp.Tests. I updated all packages, not just NUnit. I will not create a pull request for it, because I want to introduce subjective breaking changes, like changing transport classes hierarchy to disjoint unions.

@ilyalatt
Copy link

@knocte Also the main reason of my fork is absence of the owner for long time.

@guylando
Copy link

guylando commented Jan 9, 2019

@knocte @sochix this and many other pull requests already exist and many people including me did a lot of work to make it happen that TLSharp will start supporting net core, why is this and none of the other net core support pull requests merged?

@ilyalatt
Copy link

Guys, I've made a big refactoring of the library finally, you can see the change list here. The code is much simpler and efficient than it was. The usability is much better because of discriminated unions. The transport will be updated to 82 layer soon. However, I struggle with one problem, ilyalatt#6. I do not have much of attempts to fix it, because after several logins I receive a flood error for a few hours. I will be grateful if somebody can help me to fix it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants