problem breaking up one SharePoint project into pieces - c#

I'm trying to break my sharepoint project into a few smaller projects.
I could easily move utility files in different project.
However i encountered a problem when i moved custom-fields.
If i move custom-field from ProjectA to ProjectB and set ProjectA to reference ProjectB's DLL, building and deploying work fine. However, when program reference custom-field from SPListItem, it will throw System.ArgumentOutOfRangeException.
e.g.
SPListItem item = splist.GetItemById(id);<br>
CustomFieldValue custom = item["Custom"] // Error occurs here
Also, if i call AddFieldAsXml to define above custom-field, i get same error.
can anyone help me solve this problem?
thank you in advance...
Detail of Error occured in AddFieldAsXml (same error occurs when referencing)
Length cannot be less than zero.
Parameter name: length
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7494967
System.String.Substring(Int32 startIndex, Int32 length) +11
Microsoft.SharePoint.Publishing.PublishingHttpModule.CreateSPField(String fieldTypeName, SPFieldCollection collection, String fieldName) +80
Microsoft.SharePoint.SPFieldCollection.CreateSPField(Int32 index) +2746
Microsoft.SharePoint.SPFieldCollection.EnsureSPField(Int32 index) +89
Microsoft.SharePoint.SPFieldCollection.get_Item(Int32 iIndex) +113
Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName, Boolean bThrowException) +180
Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName) +38
Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op) +905
Microsoft.SharePoint.SPFieldCollection.AddFieldAsXml(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op) +45
This error displayed if string.substring(int startIndex, int length)'s length value is minus...
but i don't know why i get this error.

I solved the problem...
I didn't copy the fldtypes_xxxx.xml information.
so when the code try to read some information from the xml, exception is thrown...

Related

FileNotFoundException - no file missing

When entering a view for the first time, this exception is raised:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
First of all - why would it just happen the first time I enter that specific view? Even IF the issue was in the constructor (which it could not be), it would be called (and the exception thrown) every time I enter the view.
Second of all - how would I find the source of such an exception? It doesn't break into the debugger, and there are no resource files (like background images, app bar icons) missing.
Lastly - what (except directly referencing files in the code) would throw such an exception?
I would show you the code in question, but the file is a bit too big to post all of it.
UPDATE:
After debugging, I have noticed that the error happens after the constructor and OnNavigatedTo() and before Loaded(). There is a thread being launched in the OnNavigatedTo method, but I have tried to try-catch every single element of that part (and every internal part of it), and no error was found.
UPDATE 2:
After debugging some more, I found the error message:
File or assembly name 'System.Windows.debug.resources, Version=2.0.5.0, Culture=en-US, PublicKeyToken=xxxxxxxxxxxxx', or one of its dependencies, was not found.
Also the stack trace:
at System.ThrowHelper.throwVersion37CompatException(ExceptionType newEType,
String newString, ExceptionType oldEType, String oldString)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Windows.Resx..ctor()
at System.Windows.Resx.GetLoader()
at System.Windows.Resx.GetStringHelper(String name)
at System.Windows.Resx.GetString(String name)
at System.Windows.Controls.Primitives.ToggleButton.ToString()
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,
IntPtr unmanagedObjArgs, Int32 argsTypeIndex,
Int32 actualArgsTypeIndex, String eventName)
you can set break for the first chance exception visual studio, debug in to see the detail about the FileNotFound exception, which file is missing.
sometime, clr try to find some extension dll, which is normally too magic to us. for example, if you use XmlSerialize in your project, if you don't use sgen.exe to generate the dynamic xml serialize dll for your serializble type, CLR will generate one during runtime, but before this, clr will try to load the assemble, which will cause FileNotFoundException, but catched

Unit testing TypeInitializationException error

I am working on a unit testing for a function in a form call Tester.cs, below is the error:
Error 7/31/2012 10:43:11 PM One of the background threads threw exception:
System.TypeInitializationException: The type initializer for 'Tester.Tester' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: String
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at Tester.Tester..cctor() in E:\Incubator\Tester\Tester\Tester.cs:line 35
--- End of inner exception stack trace ---
at Tester.Tester.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize() MY-PC
On line 35 is a code, which basically retrieve value from configuration file and convert it to integer:
private static int _part = int.Parse(ConfigurationManager.AppSettings["Part"]);
What is the error? Thank you.
The likelyhood is that ConfigurationManager.AppSettings["Part"] is returning null. Hense the parse exception.
Does your unit test project have the app setting defined in its configuration?
You should copy your app.config (or web.config) file into test project. Otherwise test project can't find it. Remember config is related to host process, not to the dll itself.
Put the break point in line 35, something there is null which should not be...Null value can not be parsed into INT....
Be ensure that the config file is placed correctly at the directory from which you're running the application

Correctly using stacktrace to debug

The following line of code is causing me an Exception
plug.Instance.AddDocuments(new Int32[] { val_pid }, val_ptype, val_doccat, val_subcat, val_doctype, val_notes, val_summary, SummaryAppendOptions.None, val_docStatus, new String[] { PDFFile })
And this is the exception detail.
System.Exception was caught
Message=Object reference not set to an instance of an object. - Error when trying to save document
Source=SimsBridge
StackTrace:
at SimsBridge.Bridge.AddDocuments(Int32[] personIds, Int32 PersonType, String docCatagory, Int32 subCatagory, String docType, String notes, String summary, SummaryAppendOptions summaryOptions, String documentStatusCode, String[] filePaths)
at ManagedScanDesktop.Form1.SimsScanComplete(String[] files) in C:\Working\ManagedScanDesktop 1.8\v1.8\ManagedScanDesktop\ManagedScanDesktop\Form1.cs:line 2619
InnerException:
I'm not looking for a solution to the actual exception.
My question is, does the stacktrace point to which part of the method doesn't have a reference set? Or is stacktrace just to trace to where the method is called?
The stack trace shows you the call stack when an exception is thrown. From what you've provided you can only deduce that an exception was thrown from AddDocuments. Any of the reference type parameters passed in could be null. The best way to pinpoint the problems is to set a breakpoint and than inspect the values.
Your stack trace means that either SimsBridge or SimsBridge.Bridge is null.
The message is telling you that somewhere in AddDocuments a null reference exception was thrown. It could be one of the parameters or a member.

CRM 4.0 Unhandled exception upon trying to export labels for translation

I'm having a strange issue with our Dynamics CRM 4.0 (we use it to develop customizations).
When trying to export labels (Settings -> Customization -> Export Labels for Translation) the system shows this error (Tracing + DevErrors are enabled, all show the same, aswell as the Event Viewer on the server itself):
Error Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Error Details:
Exception of type 'System.Web.HttpUnhandledException' was thrown.
Full Stack:
[ArgumentException: An item with the same key has already been added.]
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.Crm.Metadata.LabelCollection.Add(Label label)
at Microsoft.Crm.ObjectModel.OrganizationUIService.GetSectionTabAndFieldLabels(IBusinessEntity entity, ILabelLoader labelLoader, ExecutionContext context, Dictionary`2 labels)
at Microsoft.Crm.ObjectModel.OrganizationUIService.RetrieveAllFormLabelsWithAllLanguages(Int32 objectTypeCode, ExecutionContext context)
at Microsoft.Crm.Metadata.OrganizationUIHelper.RetrieveAllFormLabelsWithAllLanguages(Int32 objectTypeCode, ExecutionContext context)
at Microsoft.Crm.Tools.ImportExportPublish.FormXmlHandler.GetLocalizedLabelStringsCollection(Int32 baseLanguageCode, List`1 provisionedLanguages, Dictionary`2 locLabelCollection)
at Microsoft.Crm.Tools.ImportExportPublish.RootTranslationExportHandler.ExportLocalizedLabelStrings(Int32 baseLanguageCode, List`1 provisionedLanguages)
at Microsoft.Crm.Tools.ImportExportPublish.RootTranslationExportHandler.RunExportTranslations(Int32 baseLanguageCode, List`1 provisionedLanguages)
Apparently, no one in the world has ever had this issue (I've been googling around for 2 days)...
What I've tried:
I checked MetadataSchema.LocalizedLabels for any oddity, I tried joining it to Attribute and Entity to check for duped entries (Exception complains about a duplicate key, so ...), almost made LinqPad explode from the massive amount of queries I tried and ditched...
If it's worth anything, the latest Rollup should be on the server.
A single customized label for a "notes" tab in a custom entity main form was causing the issue. I still have no clue about Why it happened (it's been created via the stock form designer) but now my issue is resolved.
If anyone needs to follow my steps, you want to look this set of data:
USE <Organization_DB>
GO
SELECT * FROM Metadataschema.LocalizedLabel WHERE InProduction=1 AND CustomizationLevel=1
GO

VS 2010 error "Value to add was out of range. Parameter name: value "

I am facing a weird problem. My web application throws error "Value to add was out of range Parameter name :value ". Now this is not every time I run the program.Sometimes shows error and sometimes runs without problems (no changes done).stack traces given below the error is not clear (at least for me). Anybody faced this kind of issue ?
Error Details
Value to add was out of range.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value]
System.DateTime.Add(Double value, Int32 scale) +9388319
System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +8837703
System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
System.Web.Compilation.BuildManager.CompileCodeDirectories() +319
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +248
[HttpException (0x80004005): Value to add was out of range.
Parameter name: value]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +62
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +421
System.Web.Compilation.BuildManager.CallAppInitializeMethod() +31
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +605
[HttpException (0x80004005): Value to add was out of range.
Parameter name: value]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9013676
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Just guesses: as the exception seems to be thrown from the code that you do not control, it is not your code that causes the error. However, that could be your system settings. For example, for some weird reason System.DateTime.Add(Double value, Int32 scale) is called with such parameters, that, as MSDN states,
The resulting DateTime is less than MinValue or greater than MaxValue.
Is it ever possible that the time on your computer is now set to some incredibly high value? Close to 23:59:59.9999999, December 31, 9999, for instance. Or maybe low value, close to 00:00:00.0000000, January 1, 0001. So the compiler for some reasons picks up the current date and needs to add some time span to it, which causes your error.
Just a wild guess, but maybe...
UPDATE
The code of the System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly method can be found here. In the code there is a line
DateTime waitLimit = DateTime.UtcNow.AddMilliseconds(3000);
That's the only place that could throw such exception (if the version I am looking at is the same as your environment). So it gives more votes for weird time set on your computer.
This can happen if the value you are trying to assign is null. Try coalescing the value
suppose:
int i = value ?? 0; //if value is null, zero is assigned to i
MyClass _class = ValueClass ?? new MyClass(); //same as above, except it instantiates.
DateTime someDate = getChuckNorrisBirthDate() ?? DateTime.Now.Date(); // beware of chuck norris
I have seen this error with DateTime variables.. but it was ages ago. Since you do not provide enough information about the type of variable etc (and the image is too small to make out anything) I am just guessing it on top of my head.
Issue solved. Just changed my regional settings,date/time settings in control panel to some random setting and then reverted them back to original followed by a PC restart and error is gone.Issue might be with the GetCodeDirectoryAssembly code as mentioned by #Michael Sagalovich.Will investigate for more details if the error pops up again :)
Thanks All

Categories