Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:22
    Dotnet-GitSync-Bot labeled #48977
  • 15:22
    AdamSpeight2008 review_requested #48977
  • 15:22
    AdamSpeight2008 opened #48977
  • 15:16
    runfoapp[bot] edited #48828
  • 15:16
    runfoapp[bot] edited #48816
  • 15:16
    runfoapp[bot] edited #48671
  • 15:16
    runfoapp[bot] edited #48644
  • 15:15
    runfoapp[bot] edited #48030
  • 15:15
    runfoapp[bot] edited #48016
  • 15:14

    AlekseyTs on master

    Add an enforcement for a layeri… (compare)

  • 15:14
    msftbot[bot] milestoned #48838
  • 15:14
    AlekseyTs closed #48838
  • 15:04

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

  • 15:03

    dotnet-bot on release

    (compare)

Johan Larsson
@JohanLarsson
tidy oneliner would have been nicer
in new csproj
Isaac Agyen
@agyen
@jnm2 really appreciate the info and resources. Will look into them, thanks!
Isaac Agyen
@agyen
so I've decided to mimic the SDk, please any resource on how to start?
kiminuo
@kiminuo

Hey guys, I have the following test code for me to understand stream behavior:

[Fact]
public async Task TestAsync()
{
    using var cts = new CancellationTokenSource(10_000);

    // Memory stream simulating network.
    using var stream = new MemoryStream();

    // Server: Read the AUTHENTICATE command from client.
    using var streamReader = new StreamReader(stream, Encoding.ASCII, leaveOpen: true);
    using var streamWriter = new StreamWriter(stream, Encoding.ASCII, leaveOpen: true);

    streamWriter.Write('X');
    streamWriter.Flush();
    string v = streamReader.ReadToEnd();
    Assert.Equal("X", v);
}

Apparently, this seems to be fundamentally wrong. I was hoping to use streams to simulate data flowing through TcpClient. But it looks like I can't read & write to the same stream at the same time.

So I basically don't know whether Stream is supposed to be bi-directional or uni-directional data structure.
Mostly, it's used as uni-directional - i.e. reading files, reading from network stream.
Joe4evr
@Joe4evr
MemoryStream is bi-directional by default
kiminuo
@kiminuo
@Joe4evr So why is my example wrong? v is empty string
Joe4evr
@Joe4evr
but for any Stream, you can check CanRead, CanWrite, and CanSeek to see if that particular instance supports the operation(s) you need
kiminuo
@kiminuo
Right, yeah.
Joe4evr
@Joe4evr
ah, I see the issue
because you're wrapping the same stream, writing to it advances the cursor of where it is, so the Read right after thinks that it's at the end of the stream
if you want to read from that stream you need to rewind it before reading
kiminuo
@kiminuo
AHA!
God, thanks!
Yair Halberstadt
@YairHalberstadt
Pipes are a more usual way to do two way streaming
Joe4evr
@Joe4evr
^
and since there's been an effort to plumb Pipes (pun half-intended) through the networking stack, that's probably a better option to look at
kiminuo
@kiminuo

Pipes are a more usual way to do two way streaming

But I'm doing this magic just to abstract TcpClient away to test my code.

Antony Male
@canton7
@kiminuo Look at System.IO.Pipelines. They make dealing with things like TcpClient a lot easier, and they also provide a pipe-like abstraction. For testing you can put your own shims on the other side of the pipelines
Thanks guys!
Antony Male
@canton7
If you do want to use Stream as your abstraction, you probably want to implement Stream yourself, rather than using MemoryStream: MemoryStream doesn't have a concept of separate read and write queues, it's all just one big array with a single position, which is used for both reading and writing
kiminuo
@kiminuo
I see, now I understand! I'm reading https://docs.microsoft.com/en-us/dotnet/standard/io/pipelines now
Impressed by the intro :)
Antony Male
@canton7
Yeah, it took me a couple of hours to get my head around the first time, but they're nice to use
Yair Halberstadt
@YairHalberstadt
PipeLines reduce the difficulties of working with streams from very complex, to complex. They certainly don't make it trivial.
Antony Male
@canton7
Bit like await, really :P
Yair Halberstadt
@YairHalberstadt
Well await pretends to makes things trivial, and then gets you when you're distracted
Pipelines don't even bother
Antony Male
@canton7
Heh, true true
CyrusNajmabadi
@CyrusNajmabadi
@huoyaoyuan
OK. Now I've implemented everything I can find about conditional await in the compiler layer. The branch is at https://github.com/huoyaoyuan/roslyn/tree/features/conditional-await . Could you consider this a candidate of community contribution?
i've championed this and will try to get this reviewed in our next triage meeting
HaloFour
@HaloFour
@CyrusNajmabadi Thoughts on the other suggestion in that thread about a post-fix dotted await operator for chaining await calls?
var result = SomeTask.await.SomeTaskProperty.await;
// instead of
var result = await (await SomeTask).SomeTaskProperty;
37 replies
Joseph Musser
@jnm2

@agyen

so I've decided to mimic the SDk, please any resource on how to start?

You might be the first person in the world that wants to do this FWIW

I think all the source code for the SDK is at https://github.com/dotnet/sdk
You'll be mimicking specialized subsets of its behavior, like packing into a single .exe
I would be very surprised if there are any guides on how to replicate this without the SDK, but there might be a blog post on the principles of what it does or on how the SDK does it.
Otherwise all you have is design docs and SDK source code.
If you don't enjoy doing all the investigation and footwork yourself, you will not enjoy this route
What you're after is not to perfectly mimic the SDK of course, from what I hear. All you need to know are the principles of how to emit a native windows .exe that extracts files to a temp folder or maps them into memory right out of the .exe file.
Joseph Musser
@jnm2
There are some design pitfalls or tradeoffs that the SDK discovered IIRC that you'd want to know about which would be in the design documents and maybe in some of the github issues related to them.
E.g. how to pick a temp folder name to use as a cache, how to safely allow multiple instances to start concurrently, etc
Oh, there's another possibility. Instead of using the SDK or implementing this yourself, there might be an existing tool that does all the packing for you with a license that allows you to redistribute it inside your app.
Laziness is a virtue IMO
Huo Yaoyuan
@huoyaoyuan
got it
Yacoub Massad
@yacoubmassad_gitlab
Hello. Is there a reason why AnalysisContext.RegisterOperationAction does not have an overload to take a Func<OperationAnalysisContext, Task> instead of Action<OperationAnalysisContext>?
I am trying to use SymbolFinder.FindReferencesAsync inside an analyzer, I need access to the Solution object. Is there a way around that? I remember there was a reason why we don't have access to the solution in an analyzer, or do we? I can't seem to remember what is the reason though.