Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
PhonyMcRingRing
Jun 6, 2002

bpower posted:

Is it just me or is a lot of the .Net documentation a bit poo poo?

I want to learn about the different ways to render links with razer. So I end up here.

http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions_methods(v=vs.118).aspx

As a learning tool thats bloody awful. Where do you guys go to learn about the small things? I seem to just bounce around the web looking for examples.

I actually think a good portion of the .Net documentation is well written and informative. The MVC documentation though is pretty bad. The HtmlHelper extensions are the worst since they're mostly overloads with varying numbers of strings and anonymous objects.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

zergstain posted:

After a while of Googling, I haven't been able to get a clear answer on whether QPC() measures CPU time or actual time. I need an operation to occur every 100ms, so I need actual time. If not QPC(), what should I use?

I'm stuck in MFC or WINAPI land. Maybe the wrong thread, but it was the closest I could find.

I don't want to type the actual function name on my phone.

The C/C++ thread might be able to help.

twodot
Aug 7, 2005

You are objectively correct that this person is dumb and has said dumb things

Inverness posted:

New MSDN blog post: Introducing .NET Core. That's pretty interesting.

I was just reading the Reddit thread on it and saw a comment about AppDomains from a dev:

My only concern when it comes to AppDomains not being available is how I would unload an assembly in runtime without them. I've never really understood the whole partial trust security stuff or the deluge of security-related attributes all across the framework.
For clarity there is an AppDomain, but there is exactly one and everyone lives in the same AppDomain. This means you can't unload assemblies, or load multiple assemblies with the same name and different versions, or other weirdness with loading. Is there any particular reason you need to unload assemblies?

Partial trust was something of a failed promise that we've sort of given up on. It turns out that the OS is much more capable of making promises about security than we are, so all the new stuff is pretty much full trust only. An assembly loaded as partial trust is supposed to have a number of restrictions regarding what it can call and what features it can use, and while defense in depth is good, it turns out some of those promises are hard and require developers to be extremely disciplined (which often they're not).

twodot fucked around with this message at 17:37 on Dec 5, 2014

Opulent Ceremony
Feb 22, 2012

aBagorn posted:

Should I be flattening in the service layer? I am mainly using that for data access and some calculations that need to be done before objects are saved to the DB.

We do all our DTO flattening at the Service/EF layer because we use AutoMapper projections to select only the fields we want from the database.

aBagorn posted:

I had been serializing to JSON at that layer and passing up to the Web API in that format

What? You are serializing before you get to the WebAPI layer? One of the main points of WebAPI is so you can have a Controller Action like
code:
public IEnumerable<Junk> GetJunks()
and the client can decide what format they would like it serialized in via headers. If your WebAPI Actions look like
code:
public string GetJunks()
because the Service GetJunks uses already turns the data into a JSON string, that is wrong.

Mr Shiny Pants
Nov 12, 2012
It's not getting any easier....

I liked that there was one runtime for all your needs.

Why did you need to invent the RT stuff? Why didn't you just add it to the framework that was already. The RT stuff is the Windows 8 thing that sits next to .Net right? It is all pretty confusing.

Still a shame you gave up on Silverlight, you should have stuck to your guns and kept it instead of this html 5 javascript thingy we have now.

Another thing: Are there any plans to make OS level operations .Net compatible? I would love to be able to interface with snapshots, disks etc. Hell writing my own managed VSS provider would be awesome.

aBagorn
Aug 26, 2004

Opulent Ceremony posted:

We do all our DTO flattening at the Service/EF layer because we use AutoMapper projections to select only the fields we want from the database.


What? You are serializing before you get to the WebAPI layer? One of the main points of WebAPI is so you can have a Controller Action like
code:
public IEnumerable<Junk> GetJunks()
and the client can decide what format they would like it serialized in via headers. If your WebAPI Actions look like
code:
public string GetJunks()
because the Service GetJunks uses already turns the data into a JSON string, that is wrong.

See, there you go. I was doing it wrong, I figured. Luckily I'm not too far enough along that refactoring is not an issue

xgalaxy
Jan 27, 2004
i write code
To be fair Microsoft themselves are probably wondering why they wrote the RT stuff. Granted the Win32 Api is loving ancient, but the RT stuff is just bad. I'd rather use the old Win32 api.

Essential
Aug 14, 2003

twodot posted:

Is there any particular reason you need to unload assemblies?

I've used it for a windows service, to allow the service to update a library without having to stop/restart the service. As far as I know, there isn't a way to update a library once it's been loaded. I don't know if that's a security issue, but at the time it was the only thing I found that would work.

twodot
Aug 7, 2005

You are objectively correct that this person is dumb and has said dumb things

Essential posted:

I've used it for a windows service, to allow the service to update a library without having to stop/restart the service. As far as I know, there isn't a way to update a library once it's been loaded. I don't know if that's a security issue, but at the time it was the only thing I found that would work.
There's nothing inherently wrong with doing this, it's just that Windows services is not really a target scenario for .NET Core. When you're thinking about .NET Core think about things like Windows Store apps (Phone and Client) or ASP.NET.

Essential
Aug 14, 2003

twodot posted:

There's nothing inherently wrong with doing this, it's just that Windows services is not really a target scenario for .NET Core. When you're thinking about .NET Core think about things like Windows Store apps (Phone and Client) or ASP.NET.

Ah, got it thanks. I should have read the article first :S

Forgall
Oct 16, 2012

by Azathoth
So I guess there's no free mocking framework on .net that can stub out concrete classes with non-virtual methods?

xgalaxy
Jan 27, 2004
i write code

Forgall posted:

So I guess there's no free mocking framework on .net that can stub out concrete classes with non-virtual methods?

Not free no. I'm actually kind of hoping now that Roslyn is out there that someone could create a test/mock suite that could mock those things.
Any experts on Roslyn / or even Mono.Cecil know if that would be possible?

The problem with the two paid libraries that I know of that can do this is that they require you do it in visual studio as a plugin. They don't seem to offer a command line runner at all.
Mono support would be nice too.

xgalaxy fucked around with this message at 20:05 on Dec 5, 2014

LiteraryDouble
Nov 28, 2014

Hello friends.

xgalaxy posted:

Not free no. I'm actually kind of hoping now that Roslyn is out there that someone could create a test/mock suite that could mock those things.
Any experts on Roslyn / or even Mono.Cecil know if that would be possible?

The problem with the two paid libraries that I know of that can do this is that they require you do it in visual studio as a plugin. They don't seem to offer a command line runner at all.
Mono support would be nice too.

https://github.com/Moq/moq4 ?

xgalaxy
Jan 27, 2004
i write code

I don't see where Moq allows for mocking non-virtual, static, or even private methods.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Forgall posted:

So I guess there's no free mocking framework on .net that can stub out concrete classes with non-virtual methods?

IIRC the Fakes framework can do that and it's built into visual studio 2012+.

Forgall
Oct 16, 2012

by Azathoth

Ithaqua posted:

IIRC the Fakes framework can do that and it's built into visual studio 2012+.
Yeah, but visual studio itself isn't free (it's not in the new community edition either).

LiteraryDouble
Nov 28, 2014

Hello friends.

xgalaxy posted:

I don't see where Moq allows for mocking non-virtual, static, or even private methods.

Apologies. Moq is just the canonical free mock lib I've seen used everywhere.

I believe Ithaqua is correct that Fakes can do this, but haven't used it myself.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Mr Shiny Pants posted:

Still a shame you gave up on Silverlight, you should have stuck to your guns and kept it instead of this html 5 javascript thingy we have now.

Flash, Silverlight and co. have been on the way out for some time. The browser vendors started cutting them off years ago, they've been handed their coats and most have had the good sense to slink off to their long nights. Flash is still drunkenly slurring about how it can't seem to find its keys and gosh maybe it should stick around for one more drink but everyone just politely averts their eyes and hopes it gets the message.

There was no point in keeping Silverlight around and they made the right call letting it die. Supporting HTML5+JS for native OS UIs is something they did years ago, so why not brink it back :v: I agree it's a little nuts when you have WPF/XAML, but it's a nice olive branch, I guess?

Mr Shiny Pants
Nov 12, 2012

Munkeymon posted:

Flash, Silverlight and co. have been on the way out for some time. The browser vendors started cutting them off years ago, they've been handed their coats and most have had the good sense to slink off to their long nights. Flash is still drunkenly slurring about how it can't seem to find its keys and gosh maybe it should stick around for one more drink but everyone just politely averts their eyes and hopes it gets the message.

There was no point in keeping Silverlight around and they made the right call letting it die. Supporting HTML5+JS for native OS UIs is something they did years ago, so why not brink it back :v: I agree it's a little nuts when you have WPF/XAML, but it's a nice olive branch, I guess?

Compared to JS and HTML5 WPF/XAML or Silverlight are light years beyond.

wwb
Aug 17, 2004

Silverlight is dead but alive -- a lot of the technical basis -- basically componentizing the BCL and runtime -- for what they are doing in .NET core came from what they did to build silverlight funnily enough.

twodot posted:

There's nothing inherently wrong with doing this, it's just that Windows services is not really a target scenario for .NET Core. When you're thinking about .NET Core think about things like Windows Store apps (Phone and Client) or ASP.NET.

This and also the sorts of service apps they are targeting are the cloud based sort where you have multiple nodes and do rolling updates to get the same sort of effective update without downtime scenario.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

Mr Shiny Pants posted:

Compared to JS and HTML5 WPF/XAML or Silverlight are light years beyond.

Not when it comes to cross-platform support which grows overwhelmingly more important every year.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

twodot posted:

For clarity there is an AppDomain, but there is exactly one and everyone lives in the same AppDomain. This means you can't unload assemblies, or load multiple assemblies with the same name and different versions, or other weirdness with loading. Is there any particular reason you need to unload assemblies?

Partial trust was something of a failed promise that we've sort of given up on. It turns out that the OS is much more capable of making promises about security than we are, so all the new stuff is pretty much full trust only. An assembly loaded as partial trust is supposed to have a number of restrictions regarding what it can call and what features it can use, and while defense in depth is good, it turns out some of those promises are hard and require developers to be extremely disciplined (which often they're not).

As someone who has done a lot of work with App Domains, I'm glad they won't be in .NET Core. People always think "Hurr, I can use app domains to have different versions of the same assembly in the same process no problem", but then they end up serializing custom types, or throwing custom exceptions across app domains and it all goes to pot.

I'm also looking forward to the relaxation of the binding policy in ASP.NET 5. I wouldn't mind it going from the normal .NET framework. It's maddening that as soon as you reference System.Net.Http.Formatting (or whatever), you've got to add a binding redirect for the version of NewtonSoft you're using. It's generally a headache too if you're dumping all your DLLs into one folder to run NUnit over. I really don't care if you find Moq 4.4 but you were expecting 4.2.

Forgall
Oct 16, 2012

by Azathoth

xgalaxy posted:

Not free no. I'm actually kind of hoping now that Roslyn is out there that someone could create a test/mock suite that could mock those things.
Any experts on Roslyn / or even Mono.Cecil know if that would be possible?

The problem with the two paid libraries that I know of that can do this is that they require you do it in visual studio as a plugin. They don't seem to offer a command line runner at all.
Mono support would be nice too.
Not in any way an expert, but I've tried to remove sealed from classes and add virtual to methods with Mono.Cecil, after which Moq works fine on them. Not sure what side effects such modification can cause though.

Edit: Constructor is still going to be executed, but I guess Cecil can also be used to clear out its body. Then there's a call to base class constructor... Yeah, it's kind of a pain.

Forgall fucked around with this message at 23:17 on Dec 5, 2014

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



twodot posted:

Partial trust was something of a failed promise that we've sort of given up on. It turns out that the OS is much more capable of making promises about security than we are, so all the new stuff is pretty much full trust only. An assembly loaded as partial trust is supposed to have a number of restrictions regarding what it can call and what features it can use, and while defense in depth is good, it turns out some of those promises are hard and require developers to be extremely disciplined (which often they're not).

So start a new process with different credentials and communicate through a pipe(?) instead if you want to isolate something?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Mr Shiny Pants posted:

Compared to JS and HTML5 WPF/XAML or Silverlight are light years beyond.

Eh, better in plenty of ways, sure, but worse in others. XAML+C# looks like an over-engineered, boilerplate-filled mess compared to HTML+JS if you've been in HTML-land long enough (and use helper libraries, which everyone sane does). HTML+JS is a confusing mess of ad-hoc 'standards' bolted together with a lot of magic behind the scenes that, no, you can't tweak, and of course no type safety which throws XAML+C# people who are used to the compiler telling them about some things that won't work in advance. But you get cross-platform code and performance is going to be similar in many cases.

TypeScript can help a lot with the C#->JS transition, SASS/LESS/WHATEVER can help make CSS less painfully awful and good templating engines make HTML easier to manage as components instead of monolithic documents.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

xgalaxy posted:

To be fair Microsoft themselves are probably wondering why they wrote the RT stuff. Granted the Win32 Api is loving ancient, but the RT stuff is just bad. I'd rather use the old Win32 api.
What bothers me about WinRT is that they designed it for use with their own version of C++, at a time when Visual C++ was lagging behind standards compatibility. :bang:

Custom language stuff like that irks me. They could have designed it around new C++ standards to help promote it but nope. Sure there is some library that lets you use the stuff without C++ CX, but it's never given me the impression that it was anything but a second-class citizen.

I feel like this whole nonsense happened because of internal rivalry bullshit.

C# would have been better for that kind of thing.

twodot posted:

For clarity there is an AppDomain, but there is exactly one and everyone lives in the same AppDomain. This means you can't unload assemblies, or load multiple assemblies with the same name and different versions, or other weirdness with loading. Is there any particular reason you need to unload assemblies?
No particular reason. I never got a chance to see how it might be useful. Why did .NET even support appdomains in the first place? To have different trust levels in the same process? What did it offer over using a separate process and some form of IPC?

ljw1004
Jan 18, 2005

rum

xgalaxy posted:

Not free no. I'm actually kind of hoping now that Roslyn is out there that someone could create a test/mock suite that could mock those things.
Any experts on Roslyn / or even Mono.Cecil know if that would be possible?

The problem with the two paid libraries that I know of that can do this is that they require you do it in visual studio as a plugin. They don't seem to offer a command line runner at all.
Mono support would be nice too.

Conceptually, the mocks have to be either [1] created at source code which VS then compiles as part of your project, or [2] created as a post-build step by examining IL and spitting out additional assemblies, or [3] created at runtime.

Roslyn doesn't enable either two things. The best you'd do with Roslyn is, once again like [1], write a VS plugin "VS Single File Generator" (also known as "Custom Tool" in the Solution Explorer Properties Dialog). Your plugin might use Roslyn's help to analyze the user's source code and discover what additional source code to spit out. But that's it.

Gul Banana
Nov 28, 2003

I've got a piece of code that uses app domains and assembly unloading- unsurprisingly, it's a plugin loader system. It supports multiple versions of the same types, wants to keep runs isolated, etc. (Why is this all in one process? Because my project is, itself, a visual studio plugin...)

The feature is effective but very niche and complex to use. I'm not surprised to see it cut from Core

twodot
Aug 7, 2005

You are objectively correct that this person is dumb and has said dumb things

Munkeymon posted:

So start a new process with different credentials and communicate through a pipe(?) instead if you want to isolate something?
I may have overstated. Partial trust works, it just is a highly technical feature that is commonly misused. AppDomains are a fine way to get isolation, but there's nothing wrong with running a new process, especially if you are feeling paranoid.

Inverness posted:

No particular reason. I never got a chance to see how it might be useful. Why did .NET even support appdomains in the first place? To have different trust levels in the same process? What did it offer over using a separate process and some form of IPC?
I'm not sure what the answer is historically, but AppDomain creation is almost certainly faster than process creation/startup. Process creation is fast, but I've certainly run into scenarios where it was a measurable piece of my runtime. AppDomains have other performance benefits over process creation since string interning is shared across AppDomains (this make locking on string a bad idea). AppDomains predate partial trust, so partial trust isn't the reason.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

twodot posted:

I'm not sure what the answer is historically, but AppDomain creation is almost certainly faster than process creation/startup. Process creation is fast, but I've certainly run into scenarios where it was a measurable piece of my runtime. AppDomains have other performance benefits over process creation since string interning is shared across AppDomains (this make locking on string a bad idea). AppDomains predate partial trust, so partial trust isn't the reason.
I can't think of a scenario where creation time would be a real factor when it comes to AppDomain versus a separate process. If you were doing a bunch of small things frequently you would use pooling and job queuing like with threads, no? Communication speed between processes would be the bigger concern I think. I've rarely ever used IPC so I don't know how well that would work.

Sedro
Dec 31, 2008

Inverness posted:

I can't think of a scenario where creation time would be a real factor when it comes to AppDomain versus a separate process. If you were doing a bunch of small things frequently you would use pooling and job queuing like with threads, no? Communication speed between processes would be the bigger concern I think. I've rarely ever used IPC so I don't know how well that would work.
Maybe if you are doing a bunch of things frequently which involve running untrusted/fenced code, like a plugin system. Intra-process communication between AppDomains would presumably be faster than standard IPC. Also it's the only way to unload code.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
I'm using Autofac with an MVC project. I need to provide a value from HttpApplication.Request to the container - it needs to be used elsewhere in the hierarchy, possibly from components which don't know anything about ASP.NET. Something like:

code:
protected void Application_Start()
{
    // register a bunch of things including ButtModule
    builder.RegisterInstance(Request.UserHostAddress).Named<string>("RequestAddress");
    container = builder.Build();
}

// in a module far, far away
public class ButtModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(c => new Butt(c.ResolveNamed<string>("RequestAddress")).As<IButt>().InstancePerDependency();
    }
}
Unfortunately, the request object is not available in Application_Start - it throws an exception "Request is not available in this context". I tried to be sneaky and register it with a lambda instead, but run into the same problem. It seems like it would be bad to build the container in BeginRequest but I can't think of anywhere else where I could access the request data and provide it to the container before it is needed to resolve dependencies. Ideas?

Wardende
Apr 27, 2013
You need the UserHostAddress for each user, right? I believe App_Start is called one time, when the application, uh, starts, so it's user agnostic. Why not just have the constructor for ButtModule get the user host address per request itself?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
The problem is that ButtModule is dynamically loaded and Application_Start will have no idea it even exists (usually with RegisterAssemblyModules and a dynamically loaded assembly). Likewise, ButtModule does not know that it's being used in ASP.NET (or at least I'd like to avoid explicitly referencing/checking it). Can Autofac inject into a module constructor? I could maybe find a way to pass those values as parameters.

Wardende
Apr 27, 2013
If ButtModule doesn't know it's being used in ASP.NET, why does it need a user host address? Why shouldn't it reference System.Web if it deals in IP addresses? Seems natural to me...

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'm struggling a little with CSS bundling and I hope someone might have an answer for me. I want to use CSS bunding but the resulting CSS path output in the HTML is giving me a 403. From a quick Google it turns out that this can occur when you have named your bundle after an actual path that exists. No problem, I figure I'll just change the bundle name. But doing this breaks all the relative URLs in the CSS. So back to Google. Okay, apparently I can use an override of the Include method to specify a Transform for each Include, one of which will transform the URLs to absolute paths: CssRewriteUrlTransform(). So this kind of works, it definitely rewrites all the URLs, but it doesn't include the application/virtual folder in the URL. So where http://localhost:1234/ApplicationName/ is my actual application URL, the transform will change the URLs so that any relative URL mapping to the Content folder gets rewritten to http://localhost:1234/Content which is clearly not the correct transformation.

How can I simply get my files bundled without and have the relative URLs rewritten correctly - this must be an incredibly common requirement, I'm stunned it's not a simpler process.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

chmods please posted:

I'm using Autofac with an MVC project. I need to provide a value from HttpApplication.Request to the container - it needs to be used elsewhere in the hierarchy, possibly from components which don't know anything about ASP.NET. Something like:

code:
protected void Application_Start()
{
    // register a bunch of things including ButtModule
    builder.RegisterInstance(Request.UserHostAddress).Named<string>("RequestAddress");
    container = builder.Build();
}

// in a module far, far away
public class ButtModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(c => new Butt(c.ResolveNamed<string>("RequestAddress")).As<IButt>().InstancePerDependency();
    }
}
Unfortunately, the request object is not available in Application_Start - it throws an exception "Request is not available in this context". I tried to be sneaky and register it with a lambda instead, but run into the same problem. It seems like it would be bad to build the container in BeginRequest but I can't think of anywhere else where I could access the request data and provide it to the container before it is needed to resolve dependencies. Ideas?
I think this does what you're looking for? http://stackoverflow.com/a/15542425/291137
You may have to add the Autofac.Mvc package if you haven't already.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Wardende posted:

If ButtModule doesn't know it's being used in ASP.NET, why does it need a user host address? Why shouldn't it reference System.Web if it deals in IP addresses? Seems natural to me...

In this case it needs a string identifying the origin of the request for auditing purposes. When used from ASP.NET I use the request IP address, from WCF I have to get the client IP address from the operation context, when used directly I would pass the string "local".

Destroyenator posted:

I think this does what you're looking for? http://stackoverflow.com/a/15542425/291137
You may have to add the Autofac.Mvc package if you haven't already.

I'll give it a shot at work tomorrow, thanks.

Wardende
Apr 27, 2013

chmods please posted:

In this case it needs a string identifying the origin of the request for auditing purposes. When used from ASP.NET I use the request IP address, from WCF I have to get the client IP address from the operation context, when used directly I would pass the string "local".

Perhaps you need an, uh, IAuditIdentifierProvider and three implementations (one which retrieves the IP address from System.Web, one which gets the client IP, and one which provides "local"), and add that as a dependency to the ButtModule instead of a string. Then you can register the correct implementation in each App_Start.

Adbot
ADBOT LOVES YOU

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

The Wizard of Poz posted:

But doing this breaks all the relative URLs in the CSS.

Can you not just find/replace in *.css?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply