Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 3.5 support #94

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

.NET 3.5 support #94

wants to merge 12 commits into from

Conversation

krk
Copy link

@krk krk commented Dec 8, 2012

MiniProfiler classes are moved to a new .NET 3.5 class library project. .NET4.0 Profiler references this .NET 3.5 project.

ADO.NET profiling objects moved to a new project.

.NET3.5 can run profiled ADO.NET commands and use MiniProfiler.

@mmooney
Copy link

mmooney commented Sep 9, 2013

FYI, I took a fresh copy of the trunk last Friday (Sept 6 2013) and created a .NET 3.5 fork. I’ve been testing it out with a 3.5 Webforms project I’m supporting, and it seems to work well.

https://github.com/mmooney/miniprofiler/tree/DotNet35

I skipped most of the MVC stuff, because that is not 3.5-friendly. Sure, I could have tried to port that to and older MVC, but that would be a much larger undertaking I really needed it for Webforms (I can’t test it in a real app that I’m supporting, I don’t want to claim to have done it :))

Anyhow, I’m not going to submit it back as a pull request, but it would really just make the trunk ugly, and this is just a hack until all of the 3.5 stuff finally dies. Sure that will be years, but I wouldn’t want to clutter up the trunk with all of those legacy compiler switches and custom implementations of Guid.TryParse etc.

I tried to minimize the changes to the structure of the code, and wrap everything in compiler switches, so hopefully it will be easy to pull the latest trunk changes moving forward.

I also put a copy of the latest build out on NuGet, and I’ve been using that NuGet version in my testing.

https://www.nuget.org/packages/MiniProfilerDotNet35/

If you see any issues, let me know at @MooneyDev.

Cheers, Mike Mooney

@yellis
Copy link
Contributor

yellis commented Sep 10, 2013

@mmooney : I tried adding this to a .net 3.5 Web Forms project, and got the following error when running MiniProfiler.Start() in Global.asax: The type initializer for 'StackExchange.Profiling.UI.MiniProfilerHandler' threw an exception.

Inner Exception: Could not load file or assembly 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Stack Trace:

   at StackExchange.Profiling.UI.MiniProfilerHandler.RegisterRoutes()
   at StackExchange.Profiling.WebRequestProfilerProvider..ctor() in c:\Projects\MiniProfiler\StackExchange.Profiling\WebRequestProfilerProvider.cs:line 23
   at StackExchange.Profiling.MiniProfiler.Settings.EnsureProfilerProvider() in c:\Projects\MiniProfiler\StackExchange.Profiling\MiniProfiler.Settings.cs:line 345
   at StackExchange.Profiling.MiniProfiler.Start(ProfileLevel level) in c:\Projects\MiniProfiler\StackExchange.Profiling\MiniProfiler.cs:line 251
   at ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in c:\Code\...\Global.asax:line 64

Any idea why this would be happening, or if there are any special config settings that need to be done in order to get this working on a .net 3.5 web forms project?

@mmooney
Copy link

mmooney commented Sep 10, 2013

Ah, sorry about that, I was missing the NuGet dependency for the Task Parallel Library (which is needed to get a 3.5 implementation of ConcurrentDictionary). I just pushed a fix and published an update to NuGet (0.35.2). Updating to the latest NuGet package should pull in Task Parallel Library and fix your issue.

@yellis
Copy link
Contributor

yellis commented Sep 10, 2013

@mmooney That fixed the problem with MiniProfiler.Start(). Now I am running into a problem with getting it to play nicely with Linq2Sql. I have my connection initialization set up as it is recommended in miniprofiler.com:

public static MyDataContext GetMainDataContext() {
  var sqlConnection = new SqlConnection(mainConnectionString);
  var profiledConnection = new ProfiledDbConnection(sqlConnection, MiniProfiler.Current);
  return new MyDataContext (profiledConnection);
}

When I try to retrieve data from the DataContext, or Insert, I get an exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

StackTrace:

System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key) +84
StackExchange.Profiling.SqlProfiler.ExecuteFinishImpl(IDbCommand command, ExecuteType type, DbDataReader reader) in c:\Projects\MiniProfiler\StackExchange.Profiling\SqlProfiler.cs:74
StackExchange.Profiling.SqlProfilerExtensions.ExecuteFinish(SqlProfiler sqlProfiler, IDbCommand command, ExecuteType type, DbDataReader reader) in c:\Projects\MiniProfiler\StackExchange.Profiling\SqlProfiler.cs:129
StackExchange.Profiling.MiniProfiler.StackExchange.Profiling.Data.IDbProfiler.ExecuteFinish(IDbCommand profiledDbCommand, ExecuteType executeType, DbDataReader reader) in c:\Projects\MiniProfiler\StackExchange.Profiling\MiniProfiler.IDbProfiler.cs:123
StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\Projects\MiniProfiler\StackExchange.Profiling\Data\ProfiledDbCommand.cs:252
System.Data.Common.DbCommand.ExecuteReader() +12
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +332
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +113
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +344
System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute(Expression expression) +49
System.Linq.Queryable.SingleOrDefault(IQueryable`1 source, Expression`1 predicate) +301

Any insights into why this wouldn't work with the 3.5 framework project?

@yellis
Copy link
Contributor

yellis commented Sep 10, 2013

Something else not working (turned off db profiling for the time being). Added System.Web.Routing to the project, and then added the MiniProfiler handler to web.config, per instructions on miniprofiler.com. However, the mini profile script that loads up points at a location like this: src="/mini-profiler-resources/includes.js?v=UOP6zqsdLx/836L5gEc27oqeojJEVGMsiM3Br1uiYBc=". This location does not exist. So there is something up with the way that routing is working on 3.5 web forms that is not setting up the route to the mini profiler resource that returns the JS (or some additional config settings need to be added). Unfortunately, I am getting build errors on the Web Forms sample project in the source, so I can't test this out there.

@mmooney
Copy link

mmooney commented Sep 10, 2013

Hi @yellis, can you check if you have this in your web.config? You may need to enable the routing handler/modules, especially if it's web forms (yes I need to write up a blog post on this :) ).
http://msdn.microsoft.com/en-us/magazine/dd347546.aspx

I'll have to setup a test case to recreate the Linq to SQL issue. Of course, if you want to take a crack at it, the branch is here: https://github.com/mmooney/MiniProfiler/tree/DotNet35

@yellis
Copy link
Contributor

yellis commented Sep 10, 2013

@mmooney Adding the module/handler settings per the msdn article fixed the routing. Thanks.

I have tried to use the code in your branch to test out the L2S issue, but am unable to do so. When I try to run Sample.Webforms in the solution, I get an error message:

Could not load file or assembly 'EntityFramework' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

I have tried forcing it to use the 2.0 runtime (setting it up as a site in IIS and running it off of a 2.0 app pool) but that didn't help. I am not sure why it is trying to use EntityFramework, as that is only present in the StackExchange.Profiling.EntityFramework project, which is not reference din StackExchange.Profiling or Sample.Webforms. But it still looks like the sample project is trying to reference it, leading to this error.

The error itself is interesting. It is happening on this line:

var current = _inProgress[id];

In the SqlProfiler.ExecuteFinishImpl() function, not finding the id index. No idea why this isn't getting in there, as it should be set in ExecuteStartImpl(). However, until I can get the sample project running, no easy way to test this out (I dont want to take the step of copying the whole Profiler project into my project to debug just yet - hoping that you can figure out a way to test it).

@mmooney
Copy link

mmooney commented Sep 11, 2013

Hi @yellis,
For the EntityFramework error, can you check your bin directory under the website and see if the an EntityFramework DLL is there? Just to be sure, whack the whole bin directory and then rebuild. If the DLL is still floating in there from a previous compilation, it can cause that error.

I just pushed a fix for the _inProgress[id] issue. The problem was that the index of that dictionary is a Tuple<T1,T2>, which is one of the classes I had to recreate in 3.5, and I hadn't overridden the Equals and GetHashCode methods so it was not comparing the objects by value. Anyhow, I implemented those methods and added a LinqToSqlTest.aspx page in the Sample.WebForms project.

Here's the fix:
mmooney@8f9f9e2
https://www.nuget.org/packages/MiniProfilerDotNet35/0.35.3

Thanks for your help on debugging this, and for the PR this morning. Not sure if @SamSaffron is going to get annoyed that we're cluttering up this thread, so if you run into any other issues, you want to log them over on the branch repo? I just enabled the issue list over there: https://github.com/mmooney/MiniProfiler/issues

Thanks again

@yellis
Copy link
Contributor

yellis commented Sep 11, 2013

@mmooney That fixed it. Thanks. I'll post all subsequent issues to your branch.

@yellis
Copy link
Contributor

yellis commented May 2, 2022

@SamSaffron could you please close this PR?

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

Successfully merging this pull request may close these issues.

3 participants