Have you found a solution for this problem?
I have just ported a visual studio 2010 project to 2012 and now I have the same error.
The code was not changed but i can not compile because the dll won't register.
Microsoft .NET Framework Assembly Registration Utility version 4.0.30319.18408
for Microsoft .NET Framework version 4.0.30319.18408
Copyright (C) Microsoft Corporation. All rights reserved.
RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can ca
use your assembly to interfere with other applications that may be installed on
the same computer. The /codebase switch is intended to be used only with signed
assemblies. Please give your assembly a strong name and re-register it.
RegAsm : error RA0000 : An error occurred inside the user defined Register/Unreg
ister functions: System.TypeInitializationException: The type initializer for 'K
ragtenUtilityToolBar.MeasureAngleBetweenTool' threw an exception. ---> System.Ru
ntime.InteropServices.COMException: Retrieving the COM class factory for compone
nt with CLSID {7EE9C496-D123-11D0-8383-080009B996CC} failed due to the following
error: 80040111 ClassFactory cannot supply requested class (Exception from HRES
ULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).
The stacktrace points me to the row where I initialize a RgbColorClass.
This code did compile and register for COM Interop in visual studio 2010
Any ideas?
Thanks
have you set project x86? have you target framowork 3.5 or 4.0 (see ArcObjects Help for .NET developers for 4.0) ?
Yes, I had.
But I found the solution to the problem (in my situation).
The RgbColorClass was in a private static field of the the COM Registered class.
I initialized it immediately to a new object with braces.
"private static IRgbColor lineColor = new RgbColorClass() { Red = 255, Green = 217, Blue = 128, UseWindowsDithering = true };"
This is the row of code that did compile, but didn't register.
I Changed it to:
"private IRgbColor lineColor = null;"
And I initialized it in the constructor of the BaseTool:
"lineColor = new RgbColorClass() { Red = 255, Green = 217, Blue = 128, UseWindowsDithering = true };"
Now it did register correctly.
I have absolutely no idea why it didn't register when I initialized the static variable on declaration.
This Tool did compile and register on Arcgis 10.1 with a visual studio 2010 project.
Now on Arcgis 10.2.2 and visual studio 2012 I had to move the initialization to the constructor.
The reason why it was a static var is because the tool always used the same color to show a line.
(it doesn't change at runtime.)
Does anyone have a clue why I had to change this in the code?
It took me quite a while to figure this out, and because I don't know why, I might have the same problem on a different object in the future.
I hope this might help someone else.
Thanks
The reason why it was a static var is because the tool always used the same color to show a line
do you need create new instances of tool?
Have you same error if you inizialize your field in a ctor static ?
class TestColor
{
public static IRgbColor lineColor = null;
static TestColor()
{
lineColor = new RgbColorClass() { Red = 255, Green = 217, Blue = 128, UseWindowsDithering = true };
}
public TestColor(){}
}
I did solve it in the previous post by doing what you say.
However I will also post the code that compiles, but can't be registered.
I Changed it to:
"private static IRgbColor lineColor = null;"
And I initialized it in the constructor of the BaseTool:
"lineColor = new RgbColorClass() { Red = 255, Green = 217, Blue = 128, UseWindowsDithering = true };"
class TestColor { public static IRgbColor lineColor = null; static TestColor() { lineColor = new RgbColorClass() { Red = 255, Green = 217, Blue = 128, UseWindowsDithering = true }; } public TestColor(){} }
I'm still curious why this code doesn't register (It does compile correctly)
[Guid("cadf1659-3e05-4509-a668-12537f2ffea8")] |
[ClassInterface(ClassInterfaceType.None)]
[ProgId("KragtenUtilityToolBar.MeasureAngleTool")]
public sealed class MeasureAngleTool : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
}
#endregion
#endregion
private IApplication m_application;
private bool m_inUse;
private ILineSymbol m_lineSymbol;
private IPolyline m_polyline;
private ITextSymbol m_textSymbol;
private IPoint m_startPoint;
private IPoint m_textPoint;
private double m_angleSave;
private double m_distance;
private static IRgbColor LijnKleur = new RgbColorClass() { Red = 255, Green = 217, Blue = 128, UseWindowsDithering = true };
private static IRgbColor TextKleur = new RgbColorClass() { Red = 68, Green = 118, Blue = 255, UseWindowsDithering = true };
public MeasureAngleTool()
{
//
// TODO: Define values for the public properties
//
base.m_category = "Kragten Utility Toolbar"; //localizable text
base.m_caption = "Measure Angle"; //localizable text
base.m_message = "..."; //localizable text
base.m_toolTip = "..."; //localizable text
base.m_name = "Kragten_KragtenUtilityToolBarAddIn_MeasureAngleTool"; //unique id, non-localizable (e.g. "MyCategory_ArcMapTool")
try
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
// Other BaseTool implementation... |
A type with static variables with initializer expressions, but no static constructors, can exhibit subtle differences in the timing of the type initializer execution
set it in ctor static so you sure the initialization. however it hasn't sense if you don't need instance new MeasureAngleTool
Thanks!
I didn't know this.
This is something I need to keep in mind when designing/porting other tools.