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
Dayne
Dec 5, 2003
uh, yeah
I've got a MVC webapp that's doing some funky stuff with the validation message rendering.

Instead of rendering the validation message html as:

code:
<span class="field-validation-valid" data-valmsg-for="Email" data-valmsg-replace="true"></span>
it's rendering a fully qualified path to the form input like this:
code:
<span class="field-validation-valid" data-valmsg-for="https://test2.mycompany.com/app/createorder/Email" data-valmsg-replace="true"></span>
The form inputs themselves are still rendering as having a name/id of Email and the validation still works, it just doesn't display the validation message.

The really weird thing is that while right now, I have these setup in my Razor view as @Html.ValidationMessageFor, anything else I try like @Html.ValidationMessage (without the For) or even manually putting in the validation span tag like I have in the first code block, it still renders that fully qualified path to the input.

I tried Googling for the issue but was unable to find anything on it and none of my coworkers can figure it out either. I was able to work around it for now by having some javascript clear out the path after the page is rendered but I'd prefer to figure out why it just randomly started doing this for the entire application.

I'm about to open a MSDN ticket for it but I figured I'd try here first.

Adbot
ADBOT LOVES YOU

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
A lot of ASP.NET errors give more generous information when encountered in debug and/or from a local computer - this feels like it could be one such case.

Are you encountering these errors while running a local instance or is this from something deployed?

Newf fucked around with this message at 13:50 on Sep 30, 2014

Dayne
Dec 5, 2003
uh, yeah

Newf posted:

A lot of MVC errors give more generous information when encountered in debug and/or from a local computer - this feels like it could be one such case.

Are you encountering these errors while running a local instance or is this from something deployed?

I haven't seen any errors pop up in the debug output window. This is happening on both my local instance and now in one of our test environments.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Dayne posted:

I'd prefer to figure out why it just randomly started doing this for the entire application.

Can you pinpoint a specific revision (or a small range) when it started? If so, take a close look at any changes to any of the web.config files (there are at least two of these in an MVC project - one in the root and one in the views folder).

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Search your codebase for "HtmlFieldPrefix".

Dayne
Dec 5, 2003
uh, yeah
I ended up figuring it out. This is part of a big legacy app that we're migrating over from web forms to MVC. The previous developers were doing a ton of crap in the http pipeline. So we decided to bypass it for our new MVC code.

Apparently one of the developers on our team was having some problems with that bypass so he just decided to remove it from a few places. This caused our MVC code to get routed through that legacy pipeline and caused the issue. Sigh.

This legacy app is just one giant WTF after another. It's a real piece of work. If I wouldn't get fired for it, I'd just post the entire thing on the internet somewhere and post the link in the Coding Horrors thread.

Thanks for the quick replies though!

aBagorn
Aug 26, 2004
So potential can of worms here, but I'm considering taking an app that is little more than CRUD (and maybe some 'reporting' down the line) and making it an SPA with Web API on the server end.

What is everyone's favorite javascript framework? Angular, Backbone, Ember, React, Knockout + Require + Durandal (or sammy), etc?

I'm in the middle of watching a session on Angular on top of ASP.NET Web API and it looks like there's a steep learning curve. Am I right in my assumption there? Obviously everyone is going to have their opinion (as I've seen from googling) but I am interested in what the .NET megathread consensus is, since you guys are awesome

Dietrich
Sep 11, 2001

Angular über alles.

It's not that bad. Go though the Angular Tutorial thingy to get the basics.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
I love React for the front-end. It's fast and easy to think/reason about. Of course, it only handles the view layer so it doesn't offer things that large SPA frameworks typically give, such as routing.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
My main project at work is a from scratch rewrite of an old, massive database application, and I'm doing it as an effective SPA with Ractive.js. Controllers are json API providers to the "real" backend. It's actually a rails app, but you were asking about the frontend. I like Ractive and the project is shaping up well.

Schmerm
Sep 1, 2000
College Slice
Say I want to host managed CLR code in my C++ application. I've got some managed DLL assemblies, and from my C++ code, I want to be able to call managed methods and poke global/static structs. How do I go about doing this? Do I have to use COM? I can't seem to find any APIs on MSDN that do these things.

I know there's C++/CX or C++/CLI or whatever it's called, and I'm not against making wrappers written in this, as long as they can be called from normal unmanaged native C++ code.

I've been playing with Mono, and it has very straightforward APIs: create app domain, load .dll, get class by name, get method by name, and then call it. I'd figure MS would have made something even more elegant, and faster. Plus, I want to be able to debug the whole combined managed/unmanaged mess from Visual Studio.

raminasi
Jan 25, 2005

a last drink with no ice

Schmerm posted:

Say I want to host managed CLR code in my C++ application. I've got some managed DLL assemblies, and from my C++ code, I want to be able to call managed methods and poke global/static structs. How do I go about doing this? Do I have to use COM? I can't seem to find any APIs on MSDN that do these things.

I know there's C++/CX or C++/CLI or whatever it's called, and I'm not against making wrappers written in this, as long as they can be called from normal unmanaged native C++ code.

I've been playing with Mono, and it has very straightforward APIs: create app domain, load .dll, get class by name, get method by name, and then call it. I'd figure MS would have made something even more elegant, and faster. Plus, I want to be able to debug the whole combined managed/unmanaged mess from Visual Studio.

This SO question, despite being closed, has a good summary of your options.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Odd question for you guys. I have to classify and create text based on a relatively complex table. The table is the AGTA gem treatment manual (found here http://www.firemountaingems.com/encyclobeadia/beading_resources.asp?docid=8930 under the "Introduction of the Gemstone Information Chart" section partway down the page). As you can see, there's 7 columns and about 140 rows. The workflow is as thus:
1. Product comes in
2. Extract gem info from product (products can have more than one kind of gem)
3. Based on the gem, present treatment tag, explanation of treatment, and any special care instructions
4. If gems>1 goto 3 until finished
5. Append string of tags, explanations, and treatments to product description

I started doing it badly, basically if gem="ruby" then description.append("Gem: Ruby, Treatment: H, Explanation: Many gems are heated to enhance their color and intensity., Special Care: None") and so on and so on. I got about 5 gems into this before realizing that it sucks and I hate it.

I consulted a co-worker who suggested putting the whole table into database, and then putting it into session at step 3 and querying from session when it's present, and loading it into session with it's not available.

I didn't want to do pure database because I want to avoid the roundtrip. This is going to be a bulk operation, with thousands of products being processed at a time. Is his solution reasonable, or do you guys feel there's a better way? I'm using VS2012 and vb.net.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug
You are (probably) overestimating how slow a database trip is. If this database is close to your web server (same host) you are looking at a couple of milliseconds per call. I would start with the database and then see what you need to do to optimize the process.

I'm also unsure of what you mean you were "doing it badly"? Just appending everything with a StringBuilder sounds OK to me (until it's not)

Che Delilas
Nov 23, 2009
FREE TIBET WEED
What are you doing with the "Product?" I mean, once you're done appending a description to it, what happens? I'm guessing it goes into some kind of database of available inventory/products, yes?

If so, that's textbook relational database. Three tables: Products, Gems, ProductGems. Gems has all the description information and special handling and processing instructions for each gem, and when you need to print out a product data sheet, you just join those tables.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
SQL Server can very, very easily reach 1000 inserts per second when you batch your operations. If you start optimizing beyond that, you can reach tens of thousands (or hundreds depending on your table layouts, indexes, and hardware). Just use the database.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Schmerm posted:

Say I want to host managed CLR code in my C++ application. I've got some managed DLL assemblies, and from my C++ code, I want to be able to call managed methods and poke global/static structs. How do I go about doing this? Do I have to use COM? I can't seem to find any APIs on MSDN that do these things.

I know there's C++/CX or C++/CLI or whatever it's called, and I'm not against making wrappers written in this, as long as they can be called from normal unmanaged native C++ code.

I've been playing with Mono, and it has very straightforward APIs: create app domain, load .dll, get class by name, get method by name, and then call it. I'd figure MS would have made something even more elegant, and faster. Plus, I want to be able to debug the whole combined managed/unmanaged mess from Visual Studio.

Host the CLR via COM.

It's a pain. Going the other way via P/invoke / COM Interop is much nicer so it may be worth inverting your config.

Or do generic IPC via message passing.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Thanks for the replies guys; I think I either gave too much information or too little! If I was to break down my question into the abstract it'd be: "If I need to refer to a static series of values, is it better to have a database hit once and store the table in session, or should I make a database call every time? (keeping in mind that the table data doesn't change)"

I have to do this in real time because I'm parsing over 500,000 pieces of jewelry per day from EDI, csv, XML, our own database, etc. etc. In about 50% of the cases the AGTA information isn't included, so I have to make assumptions using the table. The application is not on the same server as the database, and the job is already so big it's chunked up by vendor, with each vendor taking about 40 minutes to process. This is why I'm trying not to introduce more time into the operation.

By doing it badly I mean typing out 140 if/then/else or case statements, even though the actual number of treatments is about 20 or so. In the short term I've done a database only solution last night, we'll see how it performs.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

I'm working from a database I can't really modify the structure of(or rewrite stored procedures on) and the use of smalldatetime is causing me problems.

When I use a datatable adapter to pull out a smalldatetime structure, it returns in a byte[], so I use

edit: actually, this code isn't working. How should I convert the byte array to a datetime object?
code:
DateTime DateIn = DateTime.FromBinary(BitConverter.ToInt64(row.TimeStamp, 0));

bobua fucked around with this message at 22:25 on Oct 2, 2014

mortarr
Apr 28, 2005

frozen meat at high speed
I've got a problem with a 3rd-party component not playing nicely... maybe someone in here can point me in the right direction?

Not sure what info is relevant, so here's the config:
- I have a c#/MVC web app that takes a word doc (docx), adds a bunch of text and images using OpenXmlSdk.
- Some of the images are extracted from other pdf or tiff documents using PageExtractor (the 3rd party component).
- PageExtractor comes in x86 and x64 versions, however we need to use the x86 version because OpenXmlSdk is x86 and there is no x64 version, and both assemblies are used in the same VS project.
- The three VS projects (one holding PageExtractor, one the word doc wrapper code and the last holding the MVC site) are all set to build with an x86 platform target.
- I also have an integration test project using xunit & testdriven.net that tests key PageExtractor methods for a bunch of tiff and pdf files.
- I'm running this in VS 2012 and targetting .net v4.5

What's happening is that I have one tiff that I can extract the pages from and save to disk inside the test project, but can't extract the pages from and insert into the word doc (or save to disk) when running the mvc app inside VS - I get an exception on a method on PageExtractor for the ones that fail.

I've logged a bug with the vendor, but they're not familiar with IIS, and I'm suspicious that it's my environment that's at fault. Does anyone have any tips on nutting this one out?

Che Delilas
Nov 23, 2009
FREE TIBET WEED

Stuff like the actual type of exception and the exception message would help. Wild guess, where are you trying to save your files?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

mortarr posted:

- PageExtractor comes in x86 and x64 versions, however we need to use the x86 version because OpenXmlSdk is x86 and there is no x64 version, and both assemblies are used in the same VS project.

Can't say much without knowing the exception, but based on my past experience with 3rd party apps something is going on here.

Anaxandrides
Jun 7, 2012

Every summer day in the desert is like a vacation in hell.

bobua posted:

I'm working from a database I can't really modify the structure of(or rewrite stored procedures on) and the use of smalldatetime is causing me problems.

When I use a datatable adapter to pull out a smalldatetime structure, it returns in a byte[], so I use

edit: actually, this code isn't working. How should I convert the byte array to a datetime object?
code:
DateTime DateIn = DateTime.FromBinary(BitConverter.ToInt64(row.TimeStamp, 0));

Is this actually a TIMESTAMP column type? If so, it's not a date at all, and you can't convert it to one.

mortarr
Apr 28, 2005

frozen meat at high speed

quote:

2014-10-03 11:49:01,602 [12] ERROR PNCC.LimDocumentBuilder.WordIntegration.Services.PageAttacherService Failed to attach page 35
System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at PTI_Converter.ImageProcessing.BitmapFromDIB(IntPtr dibPtrArg)
at PTI_Converter.TiffPageExtractor.GetBitmap(Int32 pageNumber)
at PTI_Converter.TiffPageExtractor.GetPage(Int32 pageNumber)
at PNCC.LimDocumentBuilder.DocToImageConverter.Services.DocumentConverterService.GetPageAsBitmap(Int32 pageNumber) in c:\...\DocumentConverterService.cs:line 62

Here's the stack trace.

It's bailing when called from an MVC app hosted in VS 2012, but not when called from a test project in the same solution run using testdriven.net. Same method, same arguments, same document I'm trying to extract pages from, but different result. In both cases I can extract pages 1-34, but not >=35 under MVC. The tiff does not appear to be malformed - I can open it in a variety of apps and see all its pages.

Doesn't seem to matter where the doc is on the filesystem, so probably not a permissions thing.

wwb
Aug 17, 2004

Scaramouche posted:

Thanks for the replies guys; I think I either gave too much information or too little! If I was to break down my question into the abstract it'd be: "If I need to refer to a static series of values, is it better to have a database hit once and store the table in session, or should I make a database call every time? (keeping in mind that the table data doesn't change)"

I have to do this in real time because I'm parsing over 500,000 pieces of jewelry per day from EDI, csv, XML, our own database, etc. etc. In about 50% of the cases the AGTA information isn't included, so I have to make assumptions using the table. The application is not on the same server as the database, and the job is already so big it's chunked up by vendor, with each vendor taking about 40 minutes to process. This is why I'm trying not to introduce more time into the operation.

By doing it badly I mean typing out 140 if/then/else or case statements, even though the actual number of treatments is about 20 or so. In the short term I've done a database only solution last night, we'll see how it performs.

I'll just be contrarian here and note that while the concept of using a database makes a lot of sense you might not want an actual database server involved -- if it is just a key-value lookup then using a static Dictionary<string, GemInfo> isn't the most horrible thing in the world. Said "database" could be hydrated from an xml or json file which gets compiled in as a static resource. The key advantage here is that the app can travel with the data internally so you don't need to stand up the gem DB to do testing / developing. Downside is you've got a big object in memory but RAM is cheap these days.

Mr Shiny Pants
Nov 12, 2012
Or use something like Redis and tell it to save after every update.

wwb
Aug 17, 2004

I'm not sure if redis would help here -- you get the same, if not more, development friction by adding redis or adding a database. They are both external tools that need to be installed and configured.

mortarr posted:

Here's the stack trace.

It's bailing when called from an MVC app hosted in VS 2012, but not when called from a test project in the same solution run using testdriven.net. Same method, same arguments, same document I'm trying to extract pages from, but different result. In both cases I can extract pages 1-34, but not >=35 under MVC. The tiff does not appear to be malformed - I can open it in a variety of apps and see all its pages.

Doesn't seem to matter where the doc is on the filesystem, so probably not a permissions thing.

I'd add some debug statements to spit out data about the pdf like how many pages it sees. Not familiar with the underlying library but my guess is it does something that makes it behave different running inside IIS versus running in testdriven.net.

It also might be worth hooking it into full-blown IIS on said machine to see if that somehow makes a difference. To do so and get debugging just setup a virtual site pointed to the app and run VS as administrator and connect to the right w3wp.exe process.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

wwb posted:

I'll just be contrarian here and note that while the concept of using a database makes a lot of sense you might not want an actual database server involved -- if it is just a key-value lookup then using a static Dictionary<string, GemInfo> isn't the most horrible thing in the world. Said "database" could be hydrated from an xml or json file which gets compiled in as a static resource. The key advantage here is that the app can travel with the data internally so you don't need to stand up the gem DB to do testing / developing. Downside is you've got a big object in memory but RAM is cheap these days.

The biggest problem for Scaramouche is it the data isn't 100% static. Like if someone updates a description do you have to recycle the app pools to get Application_start to rehydrate your Dictionary? I would start with a database, it could even be a SQL Server Express hosted on the web server. A database is nice in that it gives you a point of integration. Later you might need to do allow updating of descriptions or adding new gems not in the original dump of data. If you are constantly hitting the database you don't need to worry about caching.

Quite honestly, with a fairly low volume (like 8-17 items/second) there's not really a "bad choice". I doubt you could add measurable latency to your process when the whole thing takes 40 minutes. What's another 1-2 seconds in the pipeline? Really the whole process should probably take 10ms to lookup a database, transform the data into a description, and pass the work item and description to the next process.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

Anaxandrides posted:

Is this actually a TIMESTAMP column type? If so, it's not a date at all, and you can't convert it to one.

Thought of that, but when I checked it the original guy had just named the variable that. Stile thought it was weird to be getting bytes out and rechecked. I was looking at something wrong and the actual problem was 2 parts... 1 is that that WAS a timestamp column and the other was that the actual datetime field wasn't actually used, so I needed to ignore it altogether.

Thanks!

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
Anyone know the equivalent of {StaticResource PhoneAccentBrush} for Windows 8 Metro apps? I want the theme accent color, which I figured out on the phone, but can't find the right value on Desktop.

wwb
Aug 17, 2004

gariig posted:

The biggest problem for Scaramouche is it the data isn't 100% static.

quote:

Thanks for the replies guys; I think I either gave too much information or too little! If I was to break down my question into the abstract it'd be: "If I need to refer to a static series of values, is it better to have a database hit once and store the table in session, or should I make a database call every time? (keeping in mind that the table data doesn't change)"

So what is 100% static then? Even if it was 98% static I would not call app pool recycles a no go here if you are deploying as frequently as one should be doing in the modern era.

epswing
Nov 4, 2003

Soiled Meat
I'm bulk inserting records with EF code first (barf?), issuing SaveChanges() every X records, and it seemed to work fine. Not the fastest option, takes a few minutes but that's no problem.

The records I'm inserting have Id values, which is where the cheese starts to slide off the cracker. Doing context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT MyTable ON"); and (... OFF"); before and after has no effect, it seems EF will just do whatever DatabaseGeneratedOption is set to. So the default ends up using the initial seed value and my records in SQL Server end up having Id 1, 2, 3, instead of what I am manually setting Id to.

If I set my entity Id value to DatabaseGeneratedOption.None, then in SQL Server the records have the Id I specify. But now, the generated table's Id column is not an identity column.

What's the right way to go about this? Please don't say hand-crafted SQL :v:

epswing fucked around with this message at 01:17 on Oct 4, 2014

Che Delilas
Nov 23, 2009
FREE TIBET WEED
The column isn't Identity because it's not being generated by the database. What you want it to be is a Primary Key.

Edit: (You can use the [Key] attribute for that if it isn't picking it up on its own)

Che Delilas fucked around with this message at 01:54 on Oct 4, 2014

epswing
Nov 4, 2003

Soiled Meat

Che Delilas posted:

The column isn't Identity because it's not being generated by the database. What you want it to be is a Primary Key.

It is a primary key. A column can be a PK and not have an Identity Specification, unless SMSS is lying to me.

Che Delilas
Nov 23, 2009
FREE TIBET WEED

epalm posted:

It is a primary key. A column can be a PK and not have an Identity Specification, unless SMSS is lying to me.

Yes, I know it can be. What I'm telling you is that you don't need the column to be Identity if you're setting the value yourself. What you are seeing is expected behavior.

Edit: yourself, not itself

epswing
Nov 4, 2003

Soiled Meat

Che Delilas posted:

Yes, I know it can be. What I'm telling you is that you don't need the column to be Identity if you're setting the value itself. What you are seeing is expected behavior.

Sorry, you're right, now that I re-read, I never really explained what I'm asking.

After the import, I want the Id column to be an identity column with an appropriate seed. Roughly the plan is to roll with DatabaseGeneratedOption.None to import the data, and then set the Id columns to DatabaseGeneratedOption.Identity afterwards.

I guess what I'm asking is, does that make sense, and is that what folks in my situation do when faced with data that they need to (A) import while preserving Id column values, (B) be able to insert further records without needing to specify the Id.

aBagorn
Aug 26, 2004
Looks like you can't without going raw SQL, or using a different DbContext for the initial import

http://stackoverflow.com/questions/7151710/how-do-i-temporarily-turn-off-an-identity-column-in-ef-code-first

Che Delilas
Nov 23, 2009
FREE TIBET WEED
Okay, that makes sense.

From some quick research it appears that EF just isn't able to handle what you want right now. SET IDENTITY INSERT ON/OFF affects the behavior of SQL Server, but not of Entity Framework, which is why it's doing nothing for you. The best solution I'm able to find does indeed involve hand-crafted queries, unfortunately.

How often are you going to be migrating existing records to this table? If it's just a one-time import of an old database into the new system, you may want to handle that during deployment (or let the DBA do it if you have one). As long as the column is re-seeded so that it won't ever overlap with existing inventory, you shouldn't have to deal with it again.

epswing
Nov 4, 2003

Soiled Meat

aBagorn posted:

Looks like you can't without going raw SQL, or using a different DbContext for the initial import

http://stackoverflow.com/questions/7151710/how-do-i-temporarily-turn-off-an-identity-column-in-ef-code-first

Right, saw that, started down the path of option 2: "Use a different DbContext, in which you define the keys as non-generated." I'm planning to throw away the DbContext I use for the import (which looks like the DbContext I'll use for the application with a bunch of modelBuilder.Entity<MyTable>().Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); statements added to the OnModelCreating override). I haven't started using migrations, but I think from there EF migrations will see the new DbContext and adjust the identity of the necessary columns.

I guess I was just looking for some guidance, I'll proceed and report back with my findings.

Adbot
ADBOT LOVES YOU

epswing
Nov 4, 2003

Soiled Meat

Che Delilas posted:

How often are you going to be migrating existing records to this table? If it's just a one-time import of an old database into the new system, you may want to handle that during deployment (or let the DBA do it if you have one). As long as the column is re-seeded so that it won't ever overlap with existing inventory, you shouldn't have to deal with it again.

Yes, it's a 1-time import. I'm looking into reseeding (which I suppose I'd do in a migration?).

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