How do I get the running dot net version of my asp.net application.
I tried the solution from here
Is there an easy way to check the .NET Framework version?
It gives the highest version installed but I need the running version.
Use Environment.Version for getting the run time version. It will give the version number of .Net CLR which is being used for executing current application.
You need to be careful here, it will only return run time version not framework version. The CLR for .NET 3.0 and .NET 3.5 is the same CLR from .NET 2.0.
Use Environment.Version - it gives you the exact version of .NET running the application.
Hope this one helps,
DirectoryEntry site = new DirectoryEntry(#"IIS://localhost/w3svc/1/Root");
PropertyValueCollection values = site.Properties["ScriptMaps"];
foreach (string val in values)
{
if (val.StartsWith(".aspx"))
{
string version = val.Substring(val.IndexOf("Framework") + 10, 9);
MessageBox.Show(String.Format("ASP.Net Version is {0}", version));
}
}
The script map property is an array of strings. If the app supports asp.net one of those strings will be a mapping of the aspx file extension to the asp.net handler which will a the full path to a DLL. The path will be something like
%windir%/Microsoft.NET/Framework//aspnet_isapi.dll.
You can get the version out of this string with some simple parsing.
Related
This may be a long shot... I need to create a simple-ish web app that needs to call an OEM supplied SDK that is 10-15, or more, years old (no updates are possible). The SDK is 32bit and is pegged to .Net Framework 3.5. There is still an active NDA for using the SDK so there is not much that I can share.
I have access to Visual Studio 2015, 2017 and 2019. In each version I can go through the process of creating a C# web app and I can select .Net 3.5 as the target framework but the only available template is a "Blank" one. Are there MVC based templates for 3.5? I have googled and have not found any.
That is my first problem. I decided to just move on and try newer .Net versions that might have a more complete template set. I have tried 4.8 most recently.
Using .Net 4.8 and specifying an "x86" platform I can create a simple app. I can call the SDK lib and get values from the simple library "get" methods like "getHeight", "getWidth", etc. The SDK is for an old computer controlled device that still works like a charm. It has a camera and one of the available functions is GetCameraImage.
The SDK comes with documentation and some sample C# "SLN"s. One of those has the following sample code:
var idata = new byte[numOfBytes];
unsafe {
fixed (byte* fixedPtr = idata) {
channel.GetCameraImage((int) numOfBytes, out idata[0]);
}
}
In my code the above just crashes with an "Access Violation". No exceptions are thrown in the debugger. It just dies.
The docs that come with the SDK suggest that the following is valid:
var idata = new byte[numOfBytes];
channel.GetCameraImage((int) numOfBytes, out idata[0]);
but I get the same Access Violation.
Any ideas about the Access Violation?
EDIT
#Serg: Addressing a couple of comments: var idata = new byte[numOfBytes*3] did not work but was a great idea.
#DekuDesu: I am not sure how to exactly verify that the memory is allocated so I did the following:
var idata = new byte[numOfBytes];
for (var i=0;i<numOfBytes;i++) {
idata[1] += 0;
}
channel.GetCameraImage((int) numOfBytes, out idata[0]);
I also tried this with #Serg's offset idea and the violation is definately triggered by the GetCameraImage call.
Can the Microsoft Z3 .NET API handle .NET Core? We're using it in a scheduling algorithm for a school project, and we believe when the project was upgraded to .net core, z3 stopped working. We can't find any information on z3 being used with .net core.
Z3 uses code contracts, which are not available in .NET core. However, we have a dummy class that replaces them, and which comes with the source code, see src/api/dotnet/core/DummyContracts.cs.
At the moment, this is not tied into the rest of our build infrastructure, but you can build them thusly:
cd src/api/dotnet/core
dotnet restore
dotnet build
(Make sure you update your copy of the source code as I just committed a fix for the Core build.)
For Z3 to work in a .Net Core 2 project you need the following things:
The Microsoft.Z3.dll in your project and add a reference to it in the project. Place it in the project root if unsure.
The libz3.dll as well but this doesn't need to be referenced (won't work anyways).
Add the libz3.dll and z3.exe to your PATH, either through code or by your OS. (this part is the one often resulting in dll not found errors).
** My code in C#
// Convinient metod to decide OS. false => linux in this case.
public static bool IsWindows() =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static void AddZ3ToProcessPath()
{
// We store our OS-dependent Z3 DLLs in diffrent folders in our root.
var solverZ3Path = IsWindows() ? "z3winx64_485" : "z3linuxx64_485";
var z3X64BinariesPath = "";
if (IsWindows())
{
z3X64BinariesPath = $"{solverZ3Path}"; // Windows friendly
}
else
{
z3X64BinariesPath =$"/{solverZ3Path}"; // Unix friendly
}
var path = Uri.UnescapeDataString(z3X64BinariesPath); // Escape chars
var name = "PATH"; // Add dlls to this environment variable
var target = EnvironmentVariableTarget.Process; // But only for this process and not entire machine or user
Environment.SetEnvironmentVariable(name, path, target);
}
What OS are you using, what version of .Net Core? Any link to code?
Iget the following error:
The name 'HttpUtility' does not exist in the current context
I am building a winform app this my code using framework 4 client profile
and I can't find the System.Web reference:
string longurl = "https://test.com/currentaccount/Pages/current.aspx";
var uriBuilder = new UriBuilder(longurl);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);//error
query["ltFrom"] = FromDate;
query["ltTo"] = ToDate;
query["ltFilterSelected"] = "none";
uriBuilder.Query = query.ToString();
longurl = uriBuilder.ToString();
What is the problem?
HttpUtility cannot be accepted with ClientProfile - change your .Net version to full.
The project is set on Target Framework to: .net 4 client profile.
That's the problem. HttpUtility doesn't exist in the client profile. Target the full profile instead (and make sure you have a reference to System.Web.dll).
Compare the "Version information" line from the above documentation:
.NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
with that of (say) System.String:
.
NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
Portable Class Library
Supported in: Portable Class Library
.NET for Windows Store apps
Supported in: Windows 8
ref: Im getting error on visual studio 2010: The type or namespace name 'HttpUtility' does not exist
to use "HttpUtility" simply add reference in visual studio from option Project->Add Reference->click on system.web then ok.
HttpUtility is based in System.Web, the Client Profile for .NET 4 only allows access to a subset of the .NET framework and System.Web is not included in that.
If you can, change from Client Profile to Full unless you have a really good reason to stick with Client Profile in which case you will need to find a different approach.
I'm trying to check what framework version a other .NET application is working with through a assembly. I found two ways to get the version of the framework ( first through the ImageRunetimeVersion and with the FullName of the assembly ) but i'm getting two different values from it and i dont know which is the right one:
Assembly ass = Assembly.LoadFrom(autPath);
string imageRuntimeVersion = ass.ImageRuntimeVersion;
Console.WriteLine("ImageRunetimeVersion: " + imageRuntimeVersion);
Console.WriteLine("FullName: " + ass.FullName);
Console.WriteLine("");
Console.WriteLine("----");
Console.WriteLine("Referenced Assemblies: ");
Console.WriteLine("");
AssemblyName[] referencedAssemblies = ass.GetReferencedAssemblies();
foreach (AssemblyName a in referencedAssemblies)
{
Console.WriteLine(a.FullName);
}
if i'm going to test this with my application and of e.g paint.net the results are:
Like you can see i cant say which "version" is the right one. The biggest problem is that if i'm going to take a look to my project properties for my .net application the target platform is 3.5 and not 2.0 or 1.0-
I think I can clear some things up for you. First, the FullName property gives you the application version number. That is the number you set and has no relation to the .NET framework version. That means the version number in the FullName property can be ignored.
The imageRuntimeVersion is the CLR version. Unfortunately, 2.0 covers .NET 2.0, 3.0, and 3.5. Technically, your application is giving you the right information but it isn't really the information you want (I don't think).
Here is a SO article with more explanation:
Retrieve Target Framework Version and Target Framework Profile from a .Net Assembly
A couple of suggestions for you from that article include looking for a config file that would give you the targetted framework or looking at the versions of the libraries that are used. Neither is really foolproof but as far as I know, that is the best you can do.
TargetFramework not same CLR version.
For example,
CLR 4.0
TargetFramework: .NET 4.0 and .NET 4.5
A solution using TargetFrameworkAttribute http://www.lucbos.net/2011/08/get-targetframework-for-assembly.html
Note: TargetFrameworkAttribute is only available from .NET 4.0.
var targetFramework = "Unknown";
var targetFrameworkAttributes = assembly.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), true);
if (targetFrameworkAttributes.Length > 0)
{
var targetFrameworkAttribute = (TargetFrameworkAttribute)targetFrameworkAttributes.First();
targetFramework = (targetFrameworkAttribute.FrameworkDisplayName);
}
Console.WriteLine("Version: {0}", Environment.Version.ToString());
I'm trying to evaluate an expression stored in a database i.e.
"if (Q1 ==2) {result = 3.1;} elseif (Q1 ==3){result=4.1;} else result = 5.9;"
Rather than parsing it myself I'm trying to use the DLR. I'm using version .92 from the Codeplex repository and my solution is a .NET 3.5 website; and I'm having conflicts between the System.Core and Microsoft.Scripting.ExtenstionAttribute .dll's.
Error =
{
Description: "'ExtensionAttribute' is ambiguous in the namespace 'System.Runtime.CompilerServices'.",
File: "InternalXmlHelper.vb"
}
At this time I cannot upgrade to .NET 4.0 and make significant use of the .net 3.5 features (so downgrading is not an option).
Any help greatly appreciated.
The solution is to type forward ExtensionAttribte into System.Core.dll. We've made 3 different versions of this assembly (for the 3 different versions that we've shipped w/ various IronPython versions) and attached to them on this bug on IronPython's CodePlex site.
You'll need to download them and check the versions on them and replace the one that matches the version in the CodePlex release you're using.
I might be to complex thinking right now and more easy solutions exists, but this jumped into my mind as a possibility;
Have you considered building a runtime class using the CodeDom, instanciating one, executing a method on it (with the expression as its implementation, which is more like code-snippets than a pure expression) and then retrieving the 'result' value from that class instance via a public property?