Application Defined Error Or User Defined Error - VB6 - com

First, I need to clarify that this is NOT a VBA related question. This error is occurring on a release program of Visual Basic 6.0 that has nothing to do with MS Office.
The program in question consists of an executable called "Color_Picker.exe" and an ActiveX control called "ColorManagementControls.ocx". I am trying to make use of Registration-Free Activation of COM.
Whenever I try to run my program with the manifests setup
"Application-defined error or user-defined error."
pops up. From the title of the error window, which is always the name of the offending class, I can tell the error is happening within the OCX.
The issue is that I know class runs free of error. In order to make sure this wasn't an issue of incompatibility with Windows 10, since the program is being compiled in Windows XP, I properly registered my OCX, and when I do that the program runs smoothly. So I'm guessing that my OCX manifest is not properly set up or requires extra add-ons because I followed the MSDN tutorial to the letter.
EDIT: I forgot mentioning that this had previously worked when I tested it with an unfinished version of both the program and class. I then added some properties to the OCX and made some UI improvements to the EXE. That is when it stopped working.
This is the EXE manifest being used:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
type = "win32"
name = "Color_Picker"
version = "1.0.0.0" />
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="ColorManagementControls.ocx"
version="1.0.0.0" />
</dependentAssembly>
</dependency>
</assembly>
This is the OCX manifest being used:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="ColorManagementControls.ocx"
version="1.0.0.0" />
<file name = "ColorManagementControls.ocx">
<comClass
clsid="{F25E6EEC-9586-4606-B0F3-D3601F59CD33}"
threadingModel = "Apartment" />
<typelib tlbid="{F24DF9F0-C974-4307-A096-3A006918FB86}"
version="1.0" helpdir=""/>
</file>
<comInterfaceExternalProxyStub
name="_udcColorScroll"
iid="{18EBDF4B-F66A-422F-99AF-C968FE10F494}"
proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
baseInterface="{00000000-0000-0000-C000-000000000046}"
tlbid = "{F24DF9F0-C974-4307-A096-3A006918FB86}" />
</assembly>
And this is what the OLE/COM viewer shows about my OCX:
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: ColorManagementControls.ocx
[
uuid(F24DF9F0-C974-4307-A096-3A006918FB86),
version(2.0),
helpstring("vbpColorManageControls")
]
library vbpColorManageControls
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface _udcColorScroll;
dispinterface __udcColorScroll;
[
odl,
uuid(18EBDF4B-F66A-422F-99AF-C968FE10F494),
version(1.0),
hidden,
dual,
nonextensible,
oleautomation
]
interface _udcColorScroll : IDispatch {
[id(0x40030000), propget]
HRESULT HideCursor([out, retval] VARIANT_BOOL* HideCursor);
[id(0x40030000), propput]
HRESULT HideCursor([in] VARIANT_BOOL HideCursor);
[id(0x40030001), propget]
HRESULT ClipOnClick([out, retval] VARIANT_BOOL* ClipOnClick);
[id(0x40030001), propput]
HRESULT ClipOnClick([in] VARIANT_BOOL ClipOnClick);
[id(0x68030005), propget]
HRESULT ColorOut([out, retval] OLE_COLOR* );
[id(0x68030004), propget]
HRESULT Value([out, retval] single* );
[id(0x68030004), propput]
HRESULT Value([in] single );
[id(0x68030003), propget]
HRESULT StartColor([out, retval] OLE_COLOR* );
[id(0x68030003), propput]
HRESULT StartColor([in] OLE_COLOR );
[id(0x68030002), propget]
HRESULT EndColor([out, retval] OLE_COLOR* );
[id(0x68030002), propput]
HRESULT EndColor([in] OLE_COLOR );
[id(0x68030001), propget]
HRESULT Orientation([out, retval] eColPickOrientation* );
[id(0x68030001), propput]
HRESULT Orientation([in] eColPickOrientation );
[id(0x68030000), propget]
HRESULT BorderStyle([out, retval] eColPickBorderStyle* );
[id(0x68030000), propput]
HRESULT BorderStyle([in] eColPickBorderStyle );
};
[
uuid(F25E6EEC-9586-4606-B0F3-D3601F59CD33),
version(1.0),
noncreatable,
control
]
coclass udcColorScroll {
[default] interface _udcColorScroll;
[default, source] dispinterface __udcColorScroll;
};
[
uuid(CE70501E-3905-4718-A1A9-FF3C844A8286),
version(1.0),
hidden,
nonextensible
]
dispinterface __udcColorScroll {
properties:
methods:
[id(0x00000001)]
void Change([in, out] tColorScll* hoverInf);
[id(0x00000002)]
void Scroll([in, out] tColorScll* hoverInf);
};
typedef [uuid(66A38F2E-D6C2-49D3-BD5B-EF68DF34CECE), version(1.0)]
enum {
CPB_NONE = 0,
CPB_SINGLE = 1,
CPB_SINGLESHADED = 2,
CPB_DOUBLE = 3,
CPB_DOUBLESHADED = 4
} eColPickBorderStyle;
typedef [uuid(206F68AB-F66C-4BD9-AD43-82355A403A4E), version(1.0)]
enum {
CPO_HORIZONTAL = 0,
CPO_VERTICAL = 1
} eColPickOrientation;
typedef [uuid(746EB8A7-B27D-44AF-B179-AE862424BC6E), version(1.0)]
struct tagtColorScll {
[helpstring("ColorScroll")
]
OLE_COLOR ColorScroll;
[helpstring("LocScroll")
]
single LocScroll;
} tColorScll;
};

Based on your comment that
this had previously worked when I tested it with an unfinished
version of both the program and class. I then added some properties to
the OCX and made some UI improvements to the EXE. That is when it
stopped working.
it seems the problem must stem from some inconsistency between the compiled OCX and one or both of the manifest files.
From the code you have posted, the thing which stands out is that your OCX manifest has:
<typelib tlbid="{F24DF9F0-C974-4307-A096-3A006918FB86}"
version="1.0" helpdir=""/>
^^^
but the IDL has version(2.0) for the same GUID. I would see if changing the manifest to get them in sync will fix this.

Related

Use Configuration File To Specify Connection String To Define a Data Source in Unit Test for Data Driven Test CSV

The following code is defined in the test class. But i want to use DataSource("DataSourceSettingName") and app.config define.
<DeploymentItem("DataSets\\TestUserMainInput.csv")>
<DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\DataSets\\TestUserMainInput.csv", "TestUserMainInput#csv", DataAccessMethod.Sequential)>
Environment:
Visual Studio 2017
Microsoft.VisualStudio.TestTools.UnitTesting
.NET Framework 4.6.1
I already tried the following code. It failed.
<configSections>
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<connectionStrings>
<add name="MyExcelConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DataSets\TestUserMainInput.csv;Extended Properties='text;HDR=Yes;FMT=Delimited'" providerName="System.Data.OleDb" />
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="MainDataSource" connectionString="MyExcelConn" dataTableName="TestUserMainInput#csv" dataAccessMethod="Sequential"/>
</dataSources>
</microsoft.visualstudio.testtools>
Output --> Tests
Error Message
An exception occurred while calling the 'executor: // mstestadapter / v2' player: 'Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestSettings, Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter, Version = 14.0.0.0, Culture = neutral, PublicKeyToken The species could not be resolved for = b03f5f7f11d50a3a '.
Could anyone help me solve this?
There is no need to change the app.config
Just Create a new test project and add a class like this one.
The test iterates for all the csv rows. You need to place the csv in your solution and change it to copy local always.
[TestClass]
public class UnitTest1
{
public TestContext TestContext { get; set; }
private static TestContext _testContext;
[ClassInitialize]
public static void SetupTests(TestContext testContext)
{
_testContext = testContext;
}
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\DataSource\\teste.csv", "teste#csv", DataAccessMethod.Sequential), DeploymentItem("DataSource\\teste.csv"), TestMethod]
public void Testing()
{
Assert.AreEqual(TestContext.DataRow["user"], "myusername");
}
}
I found the answer in following thread:
https://dondeetan.com/2017/07/03/referencing-mstest-and-mstestv2-unit-testing-framework-through-namespace-aliasing/
MSTest (Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll) and MSTestV2 (Microsoft.VisualStudio.TestPlatform.TestFramework.dll) those assemblies have the exact same namespace.
The Issue: Reference both MSTest and MSTestV2 in the same test project using the C# but that there's no VB way of doing this.

MSBuildWorkspace cannot compile project with <ProjectReference> to another project

Note I've also asked this question (with reproduction code) on Roslyn's GitHub
Create a new solution with 2 projects (CoreLibrary and DownstreamLibrary).
Add a project reference from DownstreamLibrary to CoreLibrary.
Run the following code and note that DownstreamLibrary no longer compiles.
Note that I've tried net461, netcoreapp2.1 and netstandard2.0 as target frameworks for the projects - same problem each time.
static async Task Main(string[] args)
{
MSBuildLocator.RegisterDefaults();
using (var workspace = MSBuildWorkspace.Create())
{
workspace.WorkspaceFailed += (sender, workspaceFailedArgs) => WriteLine(workspaceFailedArgs.Diagnostic.Message);
var solution = await workspace.OpenSolutionAsync(#"c:\source\ForRoslynTest\ForRoslynTest.sln");
WriteLine($"Loaded solution {solution.FilePath}");
var projectTree = workspace.CurrentSolution.GetProjectDependencyGraph();
foreach (var projectId in projectTree.GetTopologicallySortedProjects())
{
await CompileProject(workspace.CurrentSolution.GetProject(projectId));
}
}
}
private static async Task CompileProject(Project project)
{
WriteLine($"Compiling {project.Name}. It has {project.MetadataReferences.Count} metadata references.");
var compilation = await project.GetCompilationAsync();
var errors = compilation.GetDiagnostics().Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error);
if (errors.Any())
{
WriteLine($"COMPILATION ERROR: {compilation.AssemblyName}: {errors.Count()} compilation errors: \n\t{string.Join("\n\t", errors.Where(e => false).Select(e => e.ToString()))}");
}
else
{
WriteLine($"Project {project.Name} compiled with no errors");
}
}
You will receive the following output:
Msbuild failed when processing the file 'c:\source\ForRoslynTest\DownstreamLibrary\DownstreamLibrary.csproj' with message: C:\Program Files\dotnet\sdk\2.1.602\Microsoft.Common.CurrentVersion.targets: (1548, 5): The "Microsoft.Build.Tasks.ResolveNonMSBuildProjectOutput" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Found project reference without a matching metadata reference: c:\source\ForRoslynTest\CoreLibrary\CoreLibrary.csproj
Loaded solution c:\source\ForRoslynTest\ForRoslynTest.sln
Compiling CoreLibrary. It has 113 metadata references.
Project CoreLibrary compiled with no errors
Compiling DownstreamLibrary. It has 0 metadata references.
COMPILATION ERROR: DownstreamLibrary: 3 compilation errors:
c:\source\ForRoslynTest\DownstreamLibrary\Class1.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
c:\source\ForRoslynTest\DownstreamLibrary\Class1.cs(5,18): error CS0518: Predefined type 'System.Object' is not defined or imported
c:\source\ForRoslynTest\DownstreamLibrary\Class1.cs(5,18): error CS1729: 'object' does not contain a constructor that takes 0 arguments
So my question is how do I fix the above errors and get DownstreamLibrary to compile?
EDIT
I'm 99% sure the underlying cause is this error
The "Microsoft.Build.Tasks.ResolveNonMSBuildProjectOutput" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0
I've confirmed with procmon that it's loading the following DLL (C:\Program Files\dotnet\sdk\2.1.602\Microsoft.Build.Tasks.Core.dll) which I've confirmed with ILSpy DOESN'T have the ResolveNonMSBuildProjectOutput task in it. Older versions of this DLL did have this task.
I found a manual workaround to this WorkspaceFailed error:
[Failure] Msbuild failed when processing the with message: The "Microsoft.Build.Tasks.ResolveNonMSBuildProjectOutput" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
There were a few resolution steps:
following https://github.com/microsoft/msbuild/issues/4770 I updated VS 2019 from 16.2 to 16.5.3... This didn't fix my bug, but it's worth documenting I did this.
I upgraded my Microsoft.Build.* and Microsoft.CodeAnalysis dependencies to latest, THIS DIDN'T FIX THINGS YET, same bug.
I navigated to C:\Program Files\dotnet\sdk which previously had a few directories:
1.0.0/ 1.0.0-rc4-004771/ 2.0.3/ 2.1.505/
1.0.0-preview1-002702/ 1.0.3/ 2.1.202/ 3.1.100/
1.0.0-preview2-003121/ 1.0.4/ 2.1.4/ 3.1.201/
1.0.0-preview4-004233/ 1.1.0/ 2.1.502/ NuGetFallbackFolder/
I renamed this to sdk_o and created a new folder C:\Program Files\dotnet\sdk, copying in only 3.1.201/
Success! This error was gone, but running my roslyn app then resulted in some error like (paths stripped)
[Failure] Msbuild failed when processing the file with message The "ProcessFrameworkReferences" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Frameworks, Version=5.5.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. File name: 'NuGet.Frameworks, Version=5.5.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Solved this one by adding NuGet.ProjectModel 5.5.1 to my project, the csproj now has the following package references:
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="16.5.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="16.5.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.5.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.5.0" />
<PackageReference Include="NuGet.ProjectModel" Version="5.5.1" />
</ItemGroup>
No more WorkspaceFailed events for this code:
Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += (s, e) => { Console.WriteLine(e.Diagnostic); };
var project = await workspace.OpenProjectAsync(#"C:/path/to.csproj");
The csproj I'm loading with Roslyn looks as follows:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<OutputType>Library</OutputType>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\dependencies\some.csproj" />
</ItemGroup>
</Project>

Entlib Custom exception handler missing mappings

I implemented custom exception handler which works, except mappings from xml configuration policy. Those mapping works with standard Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler
My implementation
[ConfigurationElementType(typeof(CustomHandlerData))]
public class IdentityFaultContractExceptionHandler : IExceptionHandler
{
public IdentityFaultContractExceptionHandler(NameValueCollection attributes)
{
}
public IdentityFaultContractExceptionHandler(Type faultContractType, NameValueCollection attributes)
{
}
public IdentityFaultContractExceptionHandler(Type faultContractType, string exceptionMessage, NameValueCollection attributes)
{
}
public IdentityFaultContractExceptionHandler(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes)
{
}
public Exception HandleException(Exception exception, Guid handlingInstanceId)
{
return new Exception();
}
and part of the configuration
<add name="All Exceptions" type="System.Exception, mscorlib" postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add type="MyClass.IdentityFaultContractExceptionHandler, MyClass" exceptionMessage="An error occurred in the service." faultContractType="MyClass.UnexpectedServerFault, MyClass" name="Fault Contract Exception Handler" >
<mappings>
<add source="{Message}" name="Message" />
</mappings>
</add>
</exceptionHandlers>
</add>
When I remove mappping node service works, when I add, then I got error : unrecognize element mappings.
If you are using a CustomHandlerData attribute then your configuration needs to use XML Attributes which then get passed in as a NameValueCollection to the custom handler constructor. If you want to have custom XML then you will have to use Full Design-time Integration. If you want to go down that road then you should look at the FaultContractExceptionHandlerData source code since your code would probably be quite similar.

Custom module issue

I tried creating one new module. For that i created indexController, config.xml, block, layout and other required files, even though i am unable to view the message that i wrote in my block file. Whenever the url is fired (http://mydomain.com/foobar/) the output "it is from foo bar" should be displayed, but at the moment it is not working.
My indexController.php code :
class Foo_Bar_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
Code related to block :
class Foo_Bar_Block_News extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function fetchRow()
{
echo "it is from foo bar";
}
}
code related to config.xml :
<?xml version="1.0"?>
<config>
<modules>
<Foo_Bar>
<version>1.0.0</version>
</Foo_Bar>
</modules>
<frontend>
<routers>
<foobar>
<use>standard</use>
<args>
<module>Foo_Bar</module>
<frontName>foobar</frontName>
</args>
</foobar>
</routers>
<layout>
<updates>
<bar>
<file>foobar.xml</file>
</bar>
</updates>
</layout>
<!--<events>
<catalog_product_load_after>
<observers>
<foo_bar>
<type>model</type>
<class>foo_bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
</observers>
</catalog_product_load_after>
</events>-->
</frontend>
<global>
<blocks>
<foobar>
<class>Foo_Bar_Block</class>
</foobar>
</blocks>
</global>
</config>
code related to layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<foobar_index_index>
<reference name="content">
<block type="foobar/news" name="news_test" template="bar/check.phtml"/>
</reference>
</foobar_index_index>
</layout>
Code related to template file
<?php
echo $this->fetchRow()
?>
Any help realted to this will be appreciated.
The solution to this issue in my case is to Disable the compilation from admin. Everything else is fine. The desired output is obtained after disabling the compilation from admin.
To disable compilation login to admin side of your magento project and then go to system>>Tools>>Compilation and then click on disable button to disable the compilation.

How to get files or folders full access control using c#

I'm going to copy a file to this path(C:\Windows\Win32) in windows 7 using C# programming(the "Win32" Folder created by me) but I can't.Because the operation system don't allow me.so I need to full access . I write this code for solving the problem , but I see this error in the program running : " Attempted to perform an unauthorized operation."
. please help me !!! .thanks
using System.IO;
using System.Security.AccessControl;
using System.Management;
using System.Management.Instrumentation;
1. private void Sample2_Click(object sender, EventArgs e)
2. {
3. System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(#"C:\Windows\Win32");
4. FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow);
5. DirectorySecurity ds = null;
6. if (!di.Exists)
7. {
8. System.IO.Directory.CreateDirectory(#"C:\Windows\Win32");
9. }
10. ds = di.GetAccessControl();
11. ds.AddAccessRule(fsar);
12. di.SetAccessControl(ds);
13. File.Copy(#"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg", #"C:\Windows\Win32\Desert.jpg");
14. MessageBox.Show("successfully copy!!!!");
15. }
You will need to trigger UAC when starting your application.
Either embed this XML in your manifest-file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
or you can make use of this sample code from MSDN or look here or even on SO. There is plenty of stuff.