Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

Avoid user from downloading video from asp.net web page

$
0
0

I have an asp.net website where users watch video tutorials and I don't want users to download the videos.

How can I prevent them from downloading the videos and just stream or play through the website. I am open to ideas using asp.net or html or any work arounds pleaseee.

Thank you.


Azure Batch equivalent of C# FILE.AppendAllText

$
0
0
Hi,

Could you please let me know the Azure Batch Service (Storage Account blob processing) equivalent of C# FILE.AppendAllText?

Basically, I have an input file.  I need to read it line by line with Stream Reader or its Azure Batch Service equivalent.  Do transformation.  Write the output file to Blob Storage Account.  And this should happen line by line in Azure

thank you

The type or namespace name 'MultilineStringEditor' could not be found ...

$
0
0

I have no trouble using MultilineStringEditor in my windows forms app. When I tried to create a custom text box class with that  in a library dll with same reference added, I get

Error	CS0246	The type or namespace name 'MultilineStringEditor' could not be found (are you missing a using directive or an assembly reference?)	mywindowsCtlLib	...
what do I need to do?

Is wcf suported in .net core 3.1

$
0
0
Is wcf suported in .net core 3.1

.Net Standards support on consuming WCF service

$
0
0

I am trying to port my project from .Net framework to .Net standards.  

This is basically consuming a WCF service which is running on the same system. So I am using Namedpipe , NetTCP and basichttp bindings in WCF.  I could not find any solution on how to consume WCF service over namedpipe binding from .Net standards. 

Any help would be greatly appreciated.

Thanks,

Akhil

How to fix 'Task could not find "al.exe" using the SdkToolsPath' Error?

$
0
0

I am getting the below compile time error. Visual studio (2019) version is 16.3.3. and .net framework is 4.8.03752.How to fix it? Any suggestion please.

Task could not find "al.exe" using the SdkToolsPath "" or
the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\NETFXSDK\4.7.2\WinSDK-NetFx40Tools-x86".
Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under
the SdkToolsPath and that the Microsoft Windows SDK is installed.

Could not find file 'C:\Windows\TEMP\a0xemlgt.dll' in Microsoft.CSharp.CSharpCodeGenerator

$
0
0

ClrStack:

System.IO.FileNotFoundException: Could not find file 'C:\Windows\TEMP\a0xemlgt.dll'. File name: 'C:\Windows\TEMP\a0xemlgt.dll'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.File.InternalReadAllBytes(String path, Boolean checkHost)
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)

The left picture is that the file cannot be found, the right picture is no-error。

Capture results:

Why was the DLL on the left file deleted first, in a different order? why?


How to avoid Object Reference to null?

$
0
0

Hi,

I am using this if condition to search the data:

if (services.first_name.ToLower().Contains(searchBar.Text.ToLower()) || services.middle_name.ToLower().Contains(searchBar.Text.ToLower()) || services.last_name.ToLower().Contains(searchBar.Text.ToLower()) || services.email_address.ToString().Contains(searchBar.Text.ToLower()))

My data is like this:

public class UsersData
{
    public int user_id { get; set; }
    public string first_name { get; set; }
    public string middle_name { get; set; }
    public string last_name { get; set; }
    public string email_address { get; set; }

    public string full_name
    {
        get
        {
            string user_full_name;

            user_full_name = first_name;
            user_full_name += " " + middle_name;
            user_full_name += " " + last_name;

            return user_full_name;
        }
    }

    public string user_image
    {
        get
        {
            return string.Format("https://www.ajworld.app/gallery/photos/{0}.png", user_id);
        }
    }
}


but some values might be null in MySQL which cause a crash in my code, e.g. middle_name

How can i solve this please?

Thanks,

Jassim


WPF Textbox

$
0
0

How to underline the particular part of the text in WPF Textbox?

For Example:

MyTextbox.Text=" Hello everyone";

I want to under line only the "Hello" . Is there any way to do that?

Thanks in advance..!

.Net framework 4.8 installation(on server 2012) or windows server 2019 upgrade which is better?

$
0
0

Hi All,

Should I install 4.8 framework on a production server(windows 2012) or suggest to upgrade windows to 2019 server edition?

Please suggest with a brief explanation.

Thanks,

Subhankar

XML deserialization is changing one node to i:type=“a:ArrayOfXmlNode”

$
0
0

I use Postman to send a request to my RESTful server. What I send is the following:

<Template>
    <ConnectionString>http://localhost:81/Template/InputParameters.docx</ConnectionString>
    <OutputFormat>docx</OutputFormat>
    <Parameters>
        <Parameter>
            <Name>Text</Name>
            <Value>Support \nnewline character \n\tfor text input parameter</Value>
        </Parameter>
    </Parameters>
    <Datasources>
        <Datasource>
            <Name>test</Name>
            <Type>xml2</Type>
            <ConnectionString>http://localhost:81/Template/SouthWind.xml</ConnectionString>
        </Datasource>
    </Datasources>
</Template>
But what I get on the server side is:

<?xml version="1.0" encoding="utf-8"?>
<Template xmlns="http://schemas.datacontract.org/2004/07/RESTfulEngine.Models" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Callback i:nil="true"/>
    <ConnectionString>http://localhost:81/Template/InputParameters.docx</ConnectionString>
    <Data i:nil="true"/>
    <Datasources>
        <Datasource>
            <ClassName i:nil="true"/>
            <ConnectionString>http://localhost:81/Template/SouthWind.xml</ConnectionString>
            <Data i:nil="true"/>
            <Datasets/>
            <Name>test</Name>
            <SchemaConnectionString i:nil="true"/>
            <SchemaData i:nil="true"/>
            <Type>xml2</Type>
        </Datasource>
    </Datasources>
    <EngineVersion i:nil="true"/>
    <FirstPagePrinter i:nil="true"/>
    <Format i:nil="true"/>
    <Guid>d59e1ae8-4def-437f-a860-4a93723587f6</Guid>
    <LicenseFromHeader i:nil="true"/>
    <MainPrinter i:nil="true"/>
    <OutputFormat>docx</OutputFormat>
    <Parameters>
        <Parameter>
            <Name>Text</Name>
            <Value i:type="a:ArrayOfXmlNode" xmlns:a="http://schemas.datacontract.org/2004/07/System.Xml"/>
        </Parameter>
    </Parameters>
</Template>
The array of Datasource works fine. But the array pf Parameters is giving we something real weird for the node.

The actual class on the server side is:

public class Parameter { /// Initializes a new instance of the class. public Parameter(string name, object value) { Name = name; Value = value; }

/// <summary>For the ASP.NET constructor for controllers.</summary>
public Parameter()
{
}

/// <summary>
/// Name of the parameter (the var in ${var}).
/// </summary>
[DataMember]
public string Name { get; set; }

/// <summary>
/// The Value of the parameter.
/// </summary>
[DataMember]
public object Value { get; set; }
}

What's going on here?

thanks - dave



What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

.NET Framework 4.8 is coming to App Service

$
0
0

Hi there,

Do you think when the azure app service platform is upgraded to Framework 4.8 in the next few weeks, the applications created using .NET Core 2.1 will be affected ? Even though the application I am talking about is built using .NET Core 2.1, the configuration of app service is only pointing to 4.7 till now, because there is no option for me to select .NET Core.

This implies to me that the Azure app service platform is still using .NET Framework to run its services. In such case, I may not be able to test my .NET core application on Azure app service pointing to .NET Framework 4.8 until the new framework is published in Azure.

Please clarify.

Thanks


Regards, Laks

(c#) Extract (copy) MyFile.exe file from Resources to disc (E partition)

$
0
0

Hello everyone,
I am trying to extract (copy/paste) MyFile.exe from the Resource of my project.
I have added "MyFile.exe" to my Resource of my project (myProject/Properties/Resources/Add Resource/ Add Existing File..)
I want to click this button to extract (copy/paste) "MyFile.exe" file from Resources to the E partition. 
Please help. Thanks.

I've used the following code, but it doesn't work (Microsoft .NET Framework 4.0 Client Profile):

public void ExtractFileFromResources(String filename, String location)
        {
            //  Assembly assembly = Assembly.GetExecutingAssembly();
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
            Stream resFilestream = a.GetManifestResourceStream(filename);
            if (resFilestream != null)
            {
                BinaryReader br = new BinaryReader(resFilestream);
                FileStream fs = new FileStream(location, FileMode.Create);
                BinaryWriter bw = new BinaryWriter(fs);
                byte[] ba = new byte[resFilestream.Length];
                resFilestream.Read(ba, 0, ba.Length);
                bw.Write(ba);
                br.Close();
                bw.Close();
                resFilestream.Close();
            }
        }

private void Extract()
        {
            ExtractFileFromResources("MyFile.exe", @"E:\MyFile.exe");          
        }

Match logic help

$
0
0

Hey

Looking for a little bit of help with some logic if thats ok? Cant seem to get it right..

I have some material names that i am passing through a method that searches for it in a library. If found, it returns the material associated with the name

Friend Function AssignMatsApps(ByRef PartDoc As PartDocument,
                                   ByRef StrMaterialName As String) As String

'if material name only contains A, change it for SA-
If Not StrMaterialName.Contains("SA") Then
            StrMaterialName = StrMaterialName.Replace("A", "SA-")
End If

Dim localAsset As Inventor.Asset = Nothing
Dim assetLib As Inventor.AssetLibrary = AddinGlobal.InventorApp.AssetLibraries.Item("STD_LIB")
Dim ReturnMaterial As String = String.Empty

'loop materials and find a match
For Each TryAsset As Inventor.Asset In assetLib.MaterialAssets
   Dim GetResult As String = TryAsset.DisplayName
    If GetResult.Contains(StrMaterialName) Then
       If GetResult = StrMaterialName Then
          ReturnMaterial = StrMaterialName
       Else
          ReturnMaterial = TryAsset.DisplayName
       End If
    End If

Dim libAsset As Inventor.Asset = assetLib.MaterialAssets.Item(ReturnMaterial)
localAsset = libAsset.CopyTo(PartDoc)

 Try
   PartDoc.ActiveMaterial = localAsset
Catch ex As Exception
End Try

Return ReturnMaterial

End Function

The intent is to compare the material name coming in with whats currently in the library and when a match is found, return the material so it can be assigned. This works except when there is a slight variation on the material name.

The material name in the library is always the same, here is a short list-

SA-105

SA-105N

SA-516 70

SA-516 70 B

SA-516C

notice the irregular pattern for the suffix letter? some are spaced, some are adjacent. One certain thing is there will only be one material name, nothing duplicated in a different format. for example; there will be SA-105N but not SA-105 N.

The materials that i pass into the function are

A105

A105 N

A105N

A516 70

A516 70 B

A516 70B

As mentioned above, these will all be converted to SA- numbers and i will use that format below.

What i need to do is find a match even if the material name being passed in varies. So for example, if i pass in these names

SA-105N or SA-105 N, i will return SA-105N (The library version). If i pass in SA-516 70 B or SA-516 70B, i will return SA-516 70 B. 

I tried using the replace  function to omit the space but that omits all spaces. Is there a function i can use that 'sounds like' the name so that it can cover a variation of the string to find a match?

I cant create a static list, the library is updated mainly by code for new materials and the material name being passed in can vary project to project.

Im currently looking at using RegEx to try and match the strings, i'll post back any results

hope its easy enough to understand

Thanks

Nacho




I am here to ask questions and learn from others. Cor Ligthert DO NOT REPLY TO ANY OF MY POSTS!!



Fake dll in .net core

$
0
0

Hi Team,

I am doing a migration asp.net project 4.5 frameworks toasp.net core 3.1.

I can see fake dll is used in 4.5 framework so this is feature of Visual studio enterprise edition inasp.net core also we can generate fake dll

so want to know is fake dll is supported in .net core?

any suggestion and help will be highly appreciated on how to proceed further on this.
Regards


Samesite cookie warning issue in chrome browser console window when submitting PayPal form on body load

$
0
0

Hello,

When running our ASP.net application using a chrome browser that submits a PayPal form on body load at run time, a warning message "A cookie associated with a cross-site resource at https://paypal.com/ was set without the `SameSite` attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with 'SameSite=None' and 'Secure'" is getting appeared in Google chrome browser console window. 

The following PayPal form is basically built at run time via code and it is getting submitted. As the form gets submitted, the cookie warning message is getting displayed and then getting navigated to PayPal website

    <html>
      <body onload='document.forms["paypalForm"].submit()'>
        <form id="paypalForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
          <input></input>
          <input></input>
        </form>
      </body>
    </html>

I have tried setting the target framework of my project to ".Net Framework 4.7.2" to make use of "SameSite" attribute in the code and made code changes to fix the cookie warning issue. Even after making several changes in the code, i am still getting the warning message in Google chrome browser console window

Can you please let me know the solution in order to fix the Samesite cookie warning message? 


Kamal


DataMember for an object

$
0
0

This is a DataMemberAttribute in the context of (de)serialization usage issue.

I had the following (and it fails):

[DataMember]
public object Value { get; set; }
And once I realized why - for good reason. First off, what if I passed a FileStream object? That fundamentally is not serializable.

But let's go to something simpler, a DateTime object. Our REST server is in .Net so DateTime & DateTimeOffset are serializable. So if it could handle "serializable" objects then it works great with the .Net client.

But what about the Java, JavaScript, Python, PHP, and every other SWAGGER supported client. What they store is different. Java alone now has about 12 different datetime related object. If the Java client passes an OffsetDateTime, what should a .Net deserializer do with that?

So that leads me to I create a class that has:And for the above the canonical value is a string, but we also need a type because "00123" might be a zip code (string).

[DataMember]
public string Value { get; set; }

public int ValueAsInt { get; }
public DateTime ValueAsDateTime { get; }
public float ValueAsFloat { get;}

And this will work great today. However, in the near future we plan on having complex values. Say employee where he value is their name, birthday, and an address object (so nested objects). Would the above approach be ok where we use the Value class for the birthday and standard declarations for name (string), etc?

And where we know it's a date like the birthday, we can have a ValueDateTime object we use. More specific is good. But where the Value can be anything, that's where we have this big problem.

Is this the best way to handle it?


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

Getting a 403 on a file my browser can read

Mouse pointer - change cursor

$
0
0

Hey

Im looking at trying to add either a draw line or a custom cursor to the mouse pointer. I am working inside Inventor and what i am trying to achieve requires a visual element that Inventor doesnt provide. They do provide a method of hooking into the mouse cursor by adding a .cur. I looked online to create these manually but they are all small and what i need is more of a custom length each time its used. For example:

I click on a drawing view and i can get the view size X & Y in CM. lets say the width is 75cm. I add 20cm for a space and would like to add a line that is 95cm to the mouse pointer with its hotspot dead center.

Is it an option to create a .cur file from code with the line graphic at a specified length that can be used and either delete it or overwrite it each time?

Thanks


I am here to ask questions and learn from others. Cor Ligthert DO NOT REPLY TO ANY OF MY POSTS!!

SystemEvents not working from a Windows Service

$
0
0

Requirements: Windows 10 1909 Build 18363, Visual Studio 2019 Version 16.6.1

The MSFT documentation on SystemEvents gives a clear example of how to hook SystemEvents into a Windows Service, by creating a hidden Form.  However, following the instructions exactly, I am not able to get any of the SystemEvents to log a message to the Event Viewer.  Does this no longer work?  I am running Windows 10 1909 (Build 18363), using Visual Studio 19 Version 16.6.1.

Program.cs:

using System.ServiceProcess;

namespace WindowsServiceWithGuiTest
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

ProjectInstaller.cs:

using System.ComponentModel;

namespace WindowsServiceWithGuiTest
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }
    }
}

ProjectInstaller.Designer.cs 'InitializeComponent' method:

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
            // 
            // serviceProcessInstaller1
            // 
            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
            this.serviceProcessInstaller1.Password = null;
            this.serviceProcessInstaller1.Username = null;
            // 
            // serviceInstaller1
            // 
            this.serviceInstaller1.Description = "This is a test service that also launches a GUI which you can hook system events " +"into.";
            this.serviceInstaller1.DisplayName = "ServiceWithGuiTest";
            this.serviceInstaller1.ServiceName = "ServiceWithGuiTest";
            this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
            // 
            // ProjectInstaller
            // 
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
            this.serviceProcessInstaller1,
            this.serviceInstaller1});

        }

Service1.cs:

using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;

namespace WindowsServiceWithGuiTest
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry("WindowsServiceWithGuiTest", "Starting Service");
            new Thread(RunMessagePump).Start();
        }

        void RunMessagePump()
        {
            EventLog.WriteEntry("WindowsServiceWithGuiTest.MessagePump", "Starting Message Pump");
            Application.Run(new HiddenForm());
        }

        protected override void OnStop()
        {
            Application.Exit();
        }

        public partial class HiddenForm : Form
        {
            public HiddenForm()
            {
                InitializeComponent();
                EventLog.WriteEntry("WindowsServiceWithGuiTest.HiddenForm_FormClosing", "Form c'tor finished");
            }

            private void HiddenForm_Load(object sender, EventArgs e)
            {
                EventLog.WriteEntry("WindowsServiceWithGuiTest.DisplaySettingsChanged", "Form loaded");
                SystemEvents.TimeChanged += new EventHandler(SystemEvents_TimeChanged);
                SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UPCChanged);
                SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
            }

            private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
            {
                EventLog.WriteEntry("WindowsServiceWithGuiTest.DisplaySettingsChanged", "Display Settings Have changed");
            }

            private void HiddenForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                EventLog.WriteEntry("WindowsServiceWithGuiTest.HiddenForm_FormClosing", "Form closing");
                SystemEvents.TimeChanged -= new EventHandler(SystemEvents_TimeChanged);
                SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UPCChanged);
                SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
            }

            private void SystemEvents_TimeChanged(object sender, EventArgs e)
            {
                EventLog.WriteEntry("WindowsServiceWithGuiTest.TimeChanged", "Time changed; it is now " +
                    DateTime.Now.ToLongTimeString());
            }

            private void SystemEvents_UPCChanged(object sender, UserPreferenceChangedEventArgs e)
            {
                EventLog.WriteEntry("WindowsServiceWithGuiTest.UserPreferenceChanged", e.Category.ToString());
            }
        }

        partial class HiddenForm
        {
            private System.ComponentModel.IContainer components = null;

            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            private void InitializeComponent()
            {
                this.SuspendLayout();
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(0, 0);
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.Name = "HiddenForm";
                this.Text = "HiddenForm";
                this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                this.Load += new System.EventHandler(this.HiddenForm_Load);
                this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.HiddenForm_FormClosing);
                this.ResumeLayout(false);
            }
        }
    }
}

When I compile, install, and start the service, then try to do something like change the time, change my desktop background, or change my display resolution, NOTHING HAPPENS!  The last seen event log message is that the "Form loaded".

Any help would be greatly appreciated!

Tam

Viewing all 8156 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>